If an adapter is going to be used often, it is not convenient each time to manually edit the "config.xml" file in order to change the adapter configuration. Developing a custom adapter configurator GUI solves this problem and also allows more complex configurations to be used.
A custom adapter configurator for the Math adapter should allow the user to select the operation and to turn on and off the rounding of the result. A simple GUI that does this is shown in the following figure:
Figure 12. MathAdapter Configurator GUI
The task of an adapter configurator is to generate the config.xml file according to the user’s inputs. A managed adapter configurator is a class that extends the "com.savvion.sbm.adapters.framework.AdapterConfiguratorBase" class and overwrites the following methods:
public void init(JPanel panel). This method creates the GUI. An empty JPanel is passed by the framework and the custom adapter configurator is expected to populate it with GUI elements. Those must not include the OK and Cancel button, which are placed automatically on every adapter configurator dialog. In the case of the MathAdapter configurator, the init() method should place in the JPanel the operation and rounding labels and check boxes, as shown in the above figure.
public void setConfig(AdapterConfig ac). This method is called by the adapter framework if there is an existing configuration (for example, if the adapter configuration for an already existing Business Process Server process is edited). The "ac" parameter is a "com.savvion.sbm.adapter.framework.AdapterConfig" object – a wrapper around the config.xml format. It allows you, as an adapter developer, to avoid parsing XML format and shields you for any future changes in the XML DTD.
public AdapterConfig getConfig(). This method is called by the adapter framework when the user (OpenEdge Business Process Server process developer) presses the OK button on the adapter configurator. The adapter configurator is expected to return a "com.savvion.sbm.adapters.framework.AdapterConfig" object, describing the config.xml file. Your code does not have to worry when, how, and where this information is stored. See the comments regarding the AdapterConfig object in the description of the setConfig() method above.
Following is a listing of the MathAdapter configurator implementing these three methods:
In the init() method, lines 25-38 initialize the GUI elements. Those are then placed in the JPanel at lines 40-53. Again, note that this does not include the OK and Cancel buttons – OK and Cancel are placed under the JPanel by the adapter framework.
The setConfig() method, on lines 57-58 initializes the check boxes with their default values. If the AdapterConfig parameter is not null, the check boxes are reset with the values from this existing configuration (lines 59-66).
The longest method in this class, getConfig(), generates a new AdapterConfig object, based on the user’s (the OpenEdge Business Process Server process designer) entries in the configurator. A fresh AdapterConfig is created and the values for the "OPERATION" and "ROUNDING" parameters are obtained on lines 70-73.
Next, each of the blocks in the adapter configuration, and the parameters in each block, are added in turn. Refer to the section on config.xml. Note that this method defines not only the "OPERATION" and "ROUNDING" configuration parameters, but also specifies all adapter inputs and outputs – in this case, the "X", "Y" and "RETURN" parameters. The difference is that the "X", "Y", and "RETURN" parameters do not have default value, and are made visible for mapping to dataslots by the user.