Create a custom registry to manage the custom configuration properties file in websphere commerce.
Create a custom class called ApplicationRegistry. This class will be responsible for loading and refreshing your custom configuration property file. This class will implement com.ibm.commerce.registry.Registry interface.
public class ApplicationRegistry implements Registry {
/**
* Name of the applicattion configuration file
*/
public final static String PROPERTIES_FILE = "xxx_configuration.properties";
/**
* Name of the Registry used for custom application configuration
*/
public final static String REGISTRY_NAME = "ApplicationRegistry";
Implement Initialize () method of Registry interface and register this custom registry with wcs app as shown below.
/**
* @see com.ibm.commerce.registry.Registry#initialize()
*/
public void initialize() throws Exception {
final String METHOD = "initialize";
Properties prop = new Properties();
try {
prop.load(getInputStream(filename));
} catch (Exception e) {
throw new ECSystemException(ECMessage._ERR_GENERIC,CLASSNAME,e.getMessage());
}//end try
WcsApp.registerObject(REGISTRY_NAME, this);
}
In the initialize method, read the file and populate it to a Properties Object. Also, register this registry with the websphere commerce application using WcsApp.registerObject(“Registry_Name”, this)
Implement the refresh method of the Registry interface. This method should take care of the refresh registry command issued from Websphere Administration Console.
public void refresh() throws Exception {
final String METHOD = "refresh";
ECTrace.entry(ECTraceIdentifiers.COMPONENT_EXTERN, CLASSNAME, METHOD);
readConfiguration();
// intializeProfileProperties();
// initializeRegionCodes();
observable.refresh(this);
ECTrace.exit(ECTraceIdentifiers.COMPONENT_EXTERN, CLASSNAME, METHOD);
}
private class RegObservable extends Observable{
public void refresh(Object object){
setChanged(); //properties changed
notifyObservers(object); //notify observers
}
};
private RegObservable observable = new RegObservable ();
The refresh method uses the observer pattern. In the above code, there is a class RegObservable which extends Observable and implements refresh method.
Once your own ApplicationRegistry is created, you need to register the registry in wc-server.xml.
<Registries>
......
......
.....
<registry
name="ApplicationRegistry" regClassName="com.tgg.commerce.registry.ApplicationRegistry"/>
</Registries>
Now create a custom configuration property file in WC_ToolkitPath/properties or in WC_profile.ear/properties file (in case of wc_server)