A class that handles interpolation (variable substitution) for configuration
objects.
Each instance of AbstractConfiguration is associated with an
object of this class. Each interpolation tasks are delegated to this object.
ConfigurationInterpolator works together with the
StrSubstitutor class from Commons Lang. By extending
StrLookup it is able to provide values for variables that
appear in expressions.
The basic idea of this class is that it can maintain a set of primitive
StrLookup objects, each of which are identified by a special
prefix. The variables to be processed have the form
${prefix:name} . ConfigurationInterpolator will
extract the prefix and determine, which primitive lookup object is registered
for it. Then the name of the variable is passed to this object to obtain the
actual value. It is also possible to define a default lookup object, which
will be used for variables that do not have a prefix.
When a new instance of this class is created it is initialized with a default
set of primitive lookup objects. This set can be customized using the static
methods registerGlobalLookup() and
deregisterGlobalLookup() . Per default it contains the
following standard lookup objects:
Prefix |
Lookup object |
sys |
With this prefix a lookup object is associated that is able to resolve
system properties. |
const |
The const prefix indicates that a variable is to be
interpreted as a constant member field of a class (i.e. a field with the
static final modifiers). The name of the variable must be of the form
<full qualified class name>.<field name> , e.g.
org.apache.commons.configuration.interpol.ConfigurationInterpolator.PREFIX_CONSTANTS
. |
After an instance has been created the current set of lookup objects can be
modified using the registerLookup() and
deregisterLookup() methods. The default lookup object (that is
invoked for variables without a prefix) can be set with the
setDefaultLookup() method. (If a
ConfigurationInterpolator instance is created by a
configuration object, this lookup points to the configuration itself, so that
variables are resolved using the configuration's properties. This ensures
backward compatibility to earlier version of Commons Configuration.)
Implementation node: Instances of this class are not thread-safe related to
modifications of their current set of registered lookup objects. It is
intended that each instance is associated with a single
Configuration
object and used for its interpolation tasks.
version: $Id: ConfigurationInterpolator.java 491243 2006-12-30 16:04:03Z oheger $ since: 1.4 author: author: href="http://jakarta.apache.org/commons/configuration/team-list.html">Commons author: Configuration team |