3.4. Definition and use of Variables

Variables are a way of storing user provided information in an extensible form to make it available for the application. Some applications make extensive use of variables while others hardly look at them.

One basic use of variables however is their interpretation when loading the configuration settings. Configuration items might use such variables to keep file system paths to the same value for different users, while still ensuring a unique file for each individual user.

To ensure a maximum of flexibility for various scenarios, these variables can be specified as a configuration item themselves. The item variables specifies the path to a file with variable definitions. These definitions can be either in standard Java properties format, where the property key will be used as the variable name and the properties value as the variable content. Another possibility is using an XML file which conforms to the XML schema ReplacementMapperConfig.xsd, which allows much more ways of structuring variable definitions from multiple files.

Variables allow to keep the definition of a commonly used value in one place while still using it for several different purposes. The system provided variable app.name for example determines the name of the settings files which keep track of various different application specific settings: for example the dialog-properties item with its default value of ${settings.dir}/${app.name}Dialog.properties will use the file ..../MyAppDialog.properties for the application MyApp.

In general the contents of variables are allowed to refer to other variables, which provides a flexible way of templating many things. However, it is not supported to build such dependency chains which will lead back to form a cycle. So the following set of variables is valid:

  template = some variable '${var-1}' has the value '${var-2}'
  var-1    = foo
  var-2    = bar
It would result in the value “some variable 'foo' has the value 'bar'”. If, however, the variable var-1 would be redefined as:
  var-1    = "sample ${template}"
this would result in a cycle: template => var-1 => template which is not allowed.

By default, a part in the variable content which starts with “ ${ ” and ends with “ } ” will be replaced by the contents of a variable with the name which matches the part between that start and end as illustrated above. Sometimes when combining different sets of variables for different purposes, it is desirable to prevent variable expansion in one set to allow some other process to expand it under different conditions. For this purpose it is possible to redefine the parts which start and end a variable reference in content text. This is only possible when using the XML form of specifying variables, however, see the XML schema for how to specify this.