Difference between revisions of "Properties"

m
 
Line 1: Line 1:
 
Components often want to store and retrieve configuration settings between invocations. An API is provided for this purpose.
 
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 [{{SERVER}}/workbench/api/org/geworkbench/engine/properties/PropertyManager.html <tt>org.geworkbench.engine.properties.PropertyManager</tt>] class. A singleton instance is available to process requests.
+
Configuration is handled by the setting and getting of properties using the [{{SERVER}}/workbench/api/org/geworkbench/engine/properties/PropertiesManager.html <tt>org.geworkbench.engine.properties.PropertiesManager</tt>] class. A singleton instance is available to process requests.
  
 
The two important methods of this class are:
 
The two important methods of this class are:

Latest revision as of 12:41, 28 November 2006

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.PropertiesManager 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.