Try OpenEdge Now
skip to main content
Customization Guide
Developing custom Managed Adapters : Handling complex configuration data
 

Handling complex configuration data

The configuration data for the MathDemo is quite simple – just two config parameters, "OPERATION" and "ROUNDING". Some adapters, however, may require much more complex configuration that will make the approach of defining the configuration parameters one by one in the config file impractical.
A better approach in this case is to use your own custom configuration object that has its own XML representation. Your custom object must know how to generate the XML representation and how to initialize itself if given such an XML representation string. If you use a JavaBean style object to hold your configuration, there are a number of java libraries that can serialize/deserialize your object to/from XML (for example "java.beans.XMLEncoder" and "java.beans.XMLDecoder").
If you have such an object, you can store the XML string as a value of a single configuration parameter. For example, you can include the following in your adapter configurator class:
ac.addParameter("ConfigBlock",
    PARAM_CONFIG,
    AdapterConfig.ACCESS_HIDDEN,
    PARAM_CONFIG,
    "java.lang.String",
    xmlConfigurationString);
Here, "xmlConfigurationString" contains the XML-serialized value of your custom configuration object.
When the configuration is retrieved, either by the adapter run time or by the adapter configuration opening an existing configuration in the getConfig() method, you can restore your original object from the XML string. The XML string can be obtained from the AdapterConfig object as follows:
xmlConfigurationString = ac.getParameterValue(PARAM_CONFIG);