The basic idea of this class is that it can maintain a set of primitive {@code StrLookup} objects, each of which is identified by a specialprefix. The variables to be processed have the form ${prefix:name}
. {@code ConfigurationInterpolator} willextract 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 or that cannot be resolved by their associated lookup object.
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 {@code registerGlobalLookup()} and{@code 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 {@code const} prefix indicates that a variable is to beinterpreted 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 {@code |
After an instance has been created the current set of lookup objects can be modified using the {@code registerLookup()} and{@code deregisterLookup()} methods. The default lookup object (that isinvoked for variables without a prefix) can be set with the {@code setDefaultLookup()} method. (If a{@code ConfigurationInterpolator} instance is created by aconfiguration 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 {@code Configuration} object and used for its interpolation tasks.
@version $Id: ConfigurationInterpolator.java 1295276 2012-02-29 21:11:35Z oheger $ @since 1.4 @authorStrLookup
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 is 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 or that cannot be resolved by their associated lookup object.
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.
The basic idea of this class is that it can maintain a set of primitive {@link Lookup} objects, each of which is identified by a special prefix. Thevariables to be processed have the form ${prefix:name}
. {@code 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 an arbitrary number of default lookup objects, which are used for variables that do not have a prefix or that cannot be resolved by their associated lookup object. When adding default lookup objects their order matters; they are queried in this order, and the first non-null variable value is used.
After an instance has been created it does not contain any {@code Lookup}objects. The current set of lookup objects can be modified using the {@code registerLookup()} and {@code deregisterLookup()} methods. Defaultlookup objects (that are invoked for variables without a prefix) can be added or removed with the {@code addDefaultLookup()} and{@code removeDefaultLookup()} methods respectively. (When a{@code ConfigurationInterpolator} instance is created by a configurationobject, a default lookup object is added pointing to the configuration itself, so that variables are resolved using the configuration's properties.)
The default usage scenario is that on a fully initialized instance the {@code interpolate()} method is called. It is passed an object value whichmay contain variables. All these variables are substituted if they can be resolved. The result is the passed in value with variables replaced. Alternatively, the {@code resolve()} method can be called to obtain thevalues of specific variables without performing interpolation.
Implementation node: This class is thread-safe. Lookup objects can be added or removed at any time concurrent to interpolation operations.
@version $Id: ConfigurationInterpolator.java 1624601 2014-09-12 18:04:36Z oheger $ @since 1.4 @author
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|