Properties

Revision as of 16:24, 20 November 2006 by Watkinson (talk | contribs)

Components often want to store and retrieve configuration settings between invocations. An API is provided for this purpose.

Configuration is handled by the setting and getting of properties using the org.geworkbench.engine.properties.PropertyManager class. A singleton instance is available to process requests.

The two important methods of this class are:

public void setProperty(Class componentClass, String key, String value) throws IOException;

and

public String getProperty(Class componentClass, String key, String defaultValue) throws IOException;

The first parameter to both methods can be the Class object of any class in your component. This is used to determine where the configuration will be stored. This class is mapped back to the component that it is associated with. The defaultValue parameter of getProperty will be the returned result if there is no known value for the specified key.

Here is an example use of the properties manager:

PropertiesManager.getInstance().setProperty(getClass(), "test", "value");

and later...

String value = PropertiesManager.getInstance().getProperty(getClass(), "test", "Default Value");

Setting the property will automatically cause the value to be saved to disk. The configuration file is an XML file stored in a conf subdirectory of the component's working directory.