A specialized configuration class that extends its base class by the ability of keeping more structure in the stored properties.
There are some sources of configuration data that cannot be stored very well in a {@code BaseConfiguration} object because then their structure is lost.This is for instance true for XML documents. This class can deal with such structured configuration sources by storing the properties in a tree-like organization. The exact storage structure of the underlying data does not matter for the configuration instance; it uses a {@link NodeModel} object foraccessing it.
The hierarchical organization allows for a more sophisticated access to single properties. As an example consider the following XML document:
<database> <tables> <table> <name>users</name> <fields> <field> <name>lid</name> <type>long</name> </field> <field> <name>usrName</name> <type>java.lang.String</type> </field> ... </fields> </table> <table> <name>documents</name> <fields> <field> <name>docid</name> <type>long</type> </field> ... </fields> </table> ... </tables> </database>
If this document is parsed and stored in a hierarchical configuration object (which can be done by one of the sub classes), there are enhanced possibilities of accessing properties. Per default, the keys for querying information can contain indices that select a specific element if there are multiple hits.
For instance the key {@code tables.table(0).name} can be used to find out thename of the first table. In opposite {@code tables.table.name} would return acollection with the names of all available tables. Similarly the key {@code tables.table(1).fields.field.name} returns a collection with the namesof all fields of the second table. If another index is added after the {@code field} element, a single field can be accessed:{@code tables.table(1).fields.field(0).name}.
There is a {@code getMaxIndex()} method that returns the maximum allowedindex that can be added to a given property key. This method can be used to iterate over all values defined for a certain property.
Since the 1.3 release of Commons Configuration hierarchical configurations support an expression engine. This expression engine is responsible for evaluating the passed in configuration keys and map them to the stored properties. The examples above are valid for the default expression engine, which is used when a new {@code AbstractHierarchicalConfiguration} instance is created. With the{@code setExpressionEngine()} method a different expression engine can beset. For instance with {@link org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine}there is an expression engine available that supports configuration keys in XPATH syntax.
In addition to the events common for all configuration classes, hierarchical configurations support some more events that correspond to some specific methods and features. For those events specific event type constants in {@code ConfigurationEvent} exist:
Whether an {@code AbstractHierarchicalConfiguration} object is thread-safe ornot depends on the underlying {@code NodeModel} and the {@link Synchronizer}it is associated with. Some {@code NodeModel} implementations are inherentlythread-safe; they do not require a special {@code Synchronizer}. (Per default, a dummy {@code Synchronizer} is used which is not thread-safe!) Themethods for querying or updating configuration data invoke this {@code Synchronizer} accordingly. When accessing the configuration's rootnode directly, the client application is responsible for proper synchronization. This is achieved by calling the methods {@link #lock(LockMode)}, and {@link #unlock(LockMode)} with a proper{@link LockMode} argument. In any case, it is recommended to not access theroot node directly, but to use corresponding methods for querying or updating configuration data instead. Direct manipulations of a configuration's node structure circumvent many internal mechanisms and thus can cause undesired effects. For concrete subclasses dealing with specific node structures, this situation may be different.
@version $Id: AbstractHierarchicalConfiguration.java 1624601 2014-09-12 18:04:36Z oheger $ @since 2.0 @param < T> the type of the nodes managed by this hierarchical configuration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|