Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Anchor
top
top

In This Section

Table of Contents
maxLevel2

 

XperienCentral provides a Configuration Management service. This service is used to store environment specific settings (hostname, for example). The settings of the Configuration Management service can be edited through the Setup Tool (/web/setup). This section topic explains how to add a property to the Configuration Management service and how to retrieve the contents of the properties in the Java code. When creating and reading configuration entries, be sure that you conform to the plugin development guidelines (G046 and G152 in particular). When you follow the steps explained in this sectiontopic, your plugin will conform to these guidelines.

 

In This Topic

Table of Contents
maxLevel2

 

...

Adding Properties to the Configuration Management

Beginning with XperienCentral.version 10.4, it is possible to add properties to the Configuration Management through a plugin. This section topic explains the steps you need to take to create two new extra properties. One extra property is an array (a list of server names). The second extra property is the portnumber.

Create config_metatype.xml

Create a new file in the root of the resources folder; the new file is called config_metatype.xml. This file defines the properties that can be used and groups them into a set. The contents of config_metatype.xml should look like this in order to create support for the two new properties:

...


The cardinality can be set for each property. Cardinality ‘-1’ means that the property can contain more than one value. Cardinality ‘1’ means that the property can only hold one value. Be sure that the id of the configuration set (my_config_set) is prefixed by the plugin ID, as described in guideline G152.

Create config.xml

While the file config_metatype.xml can be compared to an interface, the file config.xml can be compared to an implementation of this interface. The config.xml file should also be placed in the root of the resources folder. The config.xml file contains default values for the properties as defined in config_metatype.xml. The config.xml for the above example looks like this:

...

The values for a property that can hold multiple values should be entered in a comma-separated fashion.

Register the Configuration Set

By just creating the two XML files the Configuration Management service still doesn’t know about the new properties. There are two methods in the Configuration Management service that can be called that will process the two XML files and register the new properties:

...

The two methods as described above should only be called when the plugin is loaded. The best place for these lines is in the start() method of a configuration service. Remember that this configuration set is created by the plugin and should thus be removed automatically when the plugin is purged. So the purge method should delete the configuration set.

 

Back to Top

 

...

Using Custom Configuration Properties

This section part describes in detail how to use properties that were added to the Configuration Management service. The following steps have to be taken to make the properties available:

  • Create a configuration service that has access to the Configuration Management service;
  • The component that needs access to the configuration properties depends on the configuration service.

Define a Service Component in the Activator

In the Activator, a service component is defined. The service component will:

...

Code Block
themeEclipse
ServiceComponentDefinitionImpl serviceDef = new ServiceComponentDefinitionImpl( false );
serviceDef.setId("nl.gx.helloworld.configurationservice");
serviceDef.setName("HelloWorld configuration service.");
serviceDef.setDescription( "Service which contains the configuration for this WCBplugin." );
serviceDef.setTypeId( ServiceComponentType.class.getName() );
serviceDef.setProperties( new Hashtable<String, String>() );
serviceDef.setImplementationClassName(HelloWorldConfigurationServiceImpl.class.getName() );
serviceDef.setInterfaceClassNames( new String[] {HelloWorldConfigurationService.class.getName()} );
serviceDef.setWrapperClassNames( new String[] {} );
ComponentDependencyImpl serviceDependency = new ComponentDependencyImpl();
serviceDependency.setServiceName(ConfigurationManagement.class.getName());
serviceDependency.setRequired(true);
serviceDef.setDependencies(new ComponentDependency[] { serviceDependency });

Define an Interface for the HWC Service

The interface for the HWC (HelloWorld Configuration) service component is very small. The getters in the interface are based on the XML examples of the previous sectionsearlier in this topic. A basic interface looks like this:

...

Code Block
themeEclipse
public interface HelloWorldConfigurationService {
       public String[] getServerNames();
       public String getPortnumber();
}

Create an Implementation of the Interface

The implementation of the interface has a dependency on the Configuration Management service so it only needs a private member of the ConfigurationManagement type to have access to the service. The implementation of the HelloWorldConfigurationService interface looks like this:

...

Code Block
themeEclipse
public final class HelloWorldConfigurationServiceImpl extends
	SimpleServiceComponent implements HelloWorldConfigurationService {

	private final static Logger LOG = Logger.getLogger(HelloWorldConfigurationServiceImpl.class.getName());

	private ConfigurationManagement myConfigService;

	/**
	* Callback method for the dependency manager, called when the bundle isstarted. This start method registers the properties
	* to the ConfigurationManagement service.
	*/

  public void onStart() {
	// Note: when the configuration set already exists, its existing properties will not be affected.
	myConfigService.addConfigurationSetDefinition(
  		getClass().getResource("/config_metatype.xml"));
	myConfigService.parseAndAddConfigurationSets(
		getClass().getResource("/config.xml"), false);
  }

	/**
	* Callback method for the dependency manager, called when the bundle is purged. This purge method removes the configuration set
	* created in the start method.
	*/

public boolean onPurge() {
	myConfigService.removeConfigurationSet("my_config_set");
    return true;
  }

public String getPortnumber() {
	try {
		return myConfigService.getParameter(
			"my_config_set.my_config_entry_portnumber");
	}	catch (ConfigurationManagementException e) {
		LOG.log(Level.WARNING, "Could not find parameter'my_config_set.my_config_entry_portnumber' from the ConfigurationManagement service", e);
		return null;
	}

  }

public String[] getServerNames() {
	try {
		return myConfigService.getParameters(“my_config_set.my_config_entry_server_names");
	}	catch (ConfigurationManagementException e) {
		LOG.log(Level.WARNING, "Could not find parameter'my_config_set.my_config_entry_server_names' from the ConfigurationManagement service", e);
		return null;
		}
     }
   }
 }
}

Add a Dependency to the Configuration Service

The components that want access to the properties need to create a dependency on the HWC service that was created earlier in the previous sectionsthis topic. If, for example, an element needs access to the properties, the dependency would look like this:

...

Add this dependency to the definition of a component in the Activator.

Use the Dependency in the Implementation

The dependency to the HWC service can now be used in the element implementation:

...

Code Block
themeEclipse
INFO: Values of the custom properties are:
  Server names:
www.domain1.com;www.domain2.com; Portnumber  : 8080

Changing the Values of the Properties

Once the properties are present in the Configuration Management service, the value of the properties can be changed through the /web/setup tool. Log onto the Setup Tool (/web/setup) and navigate to the General configuration tab. Your configuration set should be present between the default configuration sets (the sets are alphabetically ordered).

 

Back to Top