last update: 08/02/2004 23:41:25

Including properties


Sometimes configurations only differ in a few settings. For example when several developers work on the same project or everyone has it own settings for a specific path. Instead of defining an individual configuration you can now extract these properties and put it into a separate properties file. The configuration will be the same for all but the properties file is different. Another example would be when you deploy your application in a test or production environment.

How does it work

You can define the name of the properties file and this file will be read by the parser and these properties will be set as immutable variables. The variables cannot be overwritten and will not be saved when you save a configuration. Even if you would use the VariableManager to set such a variable it will not be saved. Otherwise this would break the entire functionality.

Example

This is a short example demonstrating how to use such a properties file.
First we define two properties in a file called base.properties

path=/tmp/mypath
serverroot=/usr/local/mydocs

Make sure that this file is in your classpath. Now we can define the XML:

<?xml version="1.0"?>
<properties>
  <include properties="base.properties"/>
  <category name="general">
    <property name="base.path" value="${path}"/>
    <property name="server.path" value="${serverroot}"/>
  </category>
</properties>

The interesting line is the include tag. When the parser reads the XML file it will also try to read the defined properties file. If the file is found by the ResourceLocator then the properties will read as variables. These variables are marked internally as immutable. So they will not be saved when the configurations is saved.

This include mechanism is supported by all configurations. Here is an example for a nested configuration:

<?xml version="1.0"?>
<properties>
  <include properties="base.properties"/>
  <category name="general">
    <base.path>${path}</base.path/>
    <server.path>${serverroot}</server.path>
  </category>
</properties>

That is all you need to do. Now the configuration will be the same and the few differences are stored in a properties file. This approach of course will only make sense when there are only a few differences.