Extending the configuration of a service module to add name-value parameters
The simplest way to quickly add configuration data to a BOD service module is to extend the default WebSphere Commerce configuration file. No parser code needs to be written, you just need to provide the parameters in an XML file, and then retrieve them in your Java code.
About this task
Note: Because the configuration data is structured as name-value pairs, the following
restrictions apply:
To add configuration data as name-value pairs to a service module:- Each configuration data name must be unique.
- The data cannot be structured as parent-child relationships.
Procedure
-
Create a file called
wc-component.xml
in the WC_eardir\xml\config\servicemodulename-ext\ directory, where servicemodulename is the name of the WebSphere Commerce or custom service module. -
Paste the following XML into the file:
<_config:DevelopmentComponentConfiguration xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config ../xsd/wc-component.xsd"> <_config:extendedconfiguration> <_config:configgrouping name="MyConfigurationGroup"> <_config:property name="myName" value="myValue"/> </_config:configgrouping> </_config:extendedconfiguration> </_config:DevelopmentComponentConfiguration >
where MyConfigurationGroup is a name for a logical grouping of configuration data, and myName and myValue is the name-value pair you want to add. -
In your service module Java code, you can access the configuration data using Java code similar
to the following example:
String compId = "com.myco.myservicemodule"; ComponentConfiguration config = ComponentConfigurationRegistry.instance().getComponentConfiguration(compId); List configNodes = (List) config.getComponentConfiguration(ExtendedConfigurationConfigNode.class.getName(), null); for (int i=0; i<configNodes.size(); i++) { ExtendedConfigurationConfigNode extendedConfig = (ExtendedConfigurationConfigNode) configNodes.get(i); HashMap configMap = (HashMap) extendedConfig.getConfigSection("MyConfigurationGroup"); String customNewConfigMyValue = (String) configMap.get("myName"); }
Note how the MyConfigurationGroup and MyName strings are used to retrieve the configuration values.