| |
|
| org.apache.commons.configuration.AbstractConfiguration org.apache.commons.configuration.HierarchicalConfiguration
All known Subclasses: org.apache.commons.configuration.CombinedConfiguration, org.apache.commons.configuration.SubnodeConfiguration, org.apache.commons.configuration.AbstractHierarchicalFileConfiguration,
HierarchicalConfiguration | public class HierarchicalConfiguration extends AbstractConfiguration implements Serializable,Cloneable(Code) | | 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
BaseConfiguration object because then their structure is lost.
This is especially true for XML documents. This class can deal with such
structured configuration sources by storing the properties in a tree-like
organization. The internal used storage form 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
HierarchicalConfiguration object (which can be done by one of
the sub classes), there are enhanced possibilities of accessing properties.
The keys for querying information can contain indices that select a certain
element if there are multiple hits. For instance the key
tables.table(0).name can be used to find out the name of the
first table. In opposite tables.table.name would return a
collection with the names of all available tables. Similarily the key
tables.table(1).fields.field.name returns a collection with
the names of all fields of the second table. If another index is added after
the field element, a single field can be accessed:
tables.table(1).fields.field(0).name . There is a
getMaxIndex() method that returns the maximum allowed index
that can be added to a given property key. This method can be used to iterate
over all values defined for a certain property.
author: Oliver Heger version: $Id: HierarchicalConfiguration.java,v 1.14 2004/12/02 22:05:52 version: ebourg Exp $ |
Inner Class :public static class NodeVisitor | |
Inner Class :abstract protected static class BuilderVisitor extends NodeVisitor | |
Field Summary | |
final public static int | EVENT_ADD_NODES Constant for the add nodes event. | final public static int | EVENT_CLEAR_TREE Constant for the clear tree event. |
EVENT_ADD_NODES | final public static int EVENT_ADD_NODES(Code) | | Constant for the add nodes event.
|
EVENT_CLEAR_TREE | final public static int EVENT_CLEAR_TREE(Code) | | Constant for the clear tree event.
|
HierarchicalConfiguration | public HierarchicalConfiguration()(Code) | | Creates a new instance of HierarchicalConfiguration .
|
HierarchicalConfiguration | public HierarchicalConfiguration(HierarchicalConfiguration c)(Code) | | Creates a new instance of HierarchicalConfiguration and
copies all data contained in the specified configuration into the new
one.
Parameters: c - the configuration that is to be copied (if null, thisconstructor will behave like the standard constructor) since: 1.4 |
addNodes | public void addNodes(String key, Collection nodes)(Code) | | Adds a collection of nodes at the specified position of the configuration
tree. This method works similar to addProperty() , but
instead of a single property a whole collection of nodes can be added -
and thus complete configuration sub trees. E.g. with this method it is
possible to add parts of another HierarchicalConfiguration
object to this object. If the passed in key refers to an existing and
unique node, the new nodes are added to this node. Otherwise a new node
will be created at the specified position in the hierarchy.
Parameters: key - the key where the nodes are to be added; can be null ,then they are added to the root node Parameters: nodes - a collection with the Node objects to beadded |
addPropertyDirect | protected void addPropertyDirect(String key, Object obj)(Code) | | Adds the property with the specified key. This task will be delegated to
the associated ExpressionEngine , so the passed in key
must match the requirements of this implementation.
Parameters: key - the key of the new property Parameters: obj - the value of the new property |
clearNode | protected void clearNode(ConfigurationNode node)(Code) | | Clears the value of the specified node. If the node becomes undefined by
this operation, it is removed from the hierarchy.
Parameters: node - the node to be cleard |
clearProperty | public void clearProperty(String key)(Code) | | Removes the property with the given key. Properties with names that start
with the given key (i.e. properties below the specified key in the
hierarchy) won't be affected.
Parameters: key - the key of the property to be removed |
clearReferences | protected static void clearReferences(ConfigurationNode node)(Code) | | Clears all reference fields in a node structure. A configuration node can
store a so-called "reference". The meaning of this data is
determined by a concrete sub class. Typically such references are
specific for a configuration instance. If this instance is cloned or
copied, they must be cleared. This can be done using this method.
Parameters: node - the root node of the node hierarchy, in which the referencesare to be cleared since: 1.4 |
clearTree | public void clearTree(String key)(Code) | | Removes all values of the property with the given name and of keys that
start with this name. So if there is a property with the key
"foo" and a property with the key "foo.bar", a call
of clearTree("foo") would remove both properties.
Parameters: key - the key of the property to be removed |
clone | public Object clone()(Code) | | Creates a copy of this object. This new configuration object will contain
copies of all nodes in the same structure. Registered event listeners
won't be cloned; so they are not registered at the returned copy.
the copy since: 1.2 |
configurationAt | public SubnodeConfiguration configurationAt(String key)(Code) | |
Returns a hierarchical subnode configuration object that wraps the
configuration node specified by the given key. This method provides an
easy means of accessing sub trees of a hierarchical configuration. In the
returned configuration the sub tree can directly be accessed, it becomes
the root node of this configuration. Because of this the passed in key
must select exactly one configuration node; otherwise an
IllegalArgumentException will be thrown.
The difference between this method and the
HierarchicalConfiguration.subset(String) method is that
subset() supports arbitrary subsets of configuration nodes
while configurationAt() only returns a single sub tree.
Please refer to the documentation of the
SubnodeConfiguration class to obtain further information
about subnode configurations and when they should be used.
Parameters: key - the key that selects the sub tree a hierarchical configuration that contains this sub tree See Also: SubnodeConfiguration since: 1.3 |
configurationsAt | public List configurationsAt(String key)(Code) | | Returns a list of sub configurations for all configuration nodes selected
by the given key. This method will evaluate the passed in key (using the
current ExpressionEngine ) and then create a subnode
configuration for each returned node (like
HierarchicalConfiguration.configurationAt(String) }). This is especially
useful when dealing with list-like structures. As an example consider the
configuration that contains data about database tables and their fields.
If you need access to all fields of a certain table, you can simply do
List fields = config.configurationsAt("tables.table(0).fields.field");
for(Iterator it = fields.iterator(); it.hasNext();)
{
HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
// now the children and attributes of the field node can be
// directly accessed
String fieldName = sub.getString("name");
String fieldType = sub.getString("type");
...
Parameters: key - the key for selecting the desired nodes a list with hierarchical configuration objects; eachconfiguration represents one of the nodes selected by the passed in key since: 1.3 |
containsKey | public boolean containsKey(String key)(Code) | | Checks if the specified key is contained in this configuration. Note that
for this configuration the term "contained" means that the key
has an associated value. If there is a node for this key that has no
value but children (either defined or undefined), this method will still
return false .
Parameters: key - the key to be chekced a flag if this key is contained in this configuration |
createAddPath | protected Node createAddPath(ConfigurationKey.KeyIterator keyIt, Node root)(Code) | | Creates the missing nodes for adding a new property. This method ensures
that there are corresponding nodes for all components of the specified
configuration key.
Parameters: keyIt - the key iterator Parameters: root - the base node of the path to be created the last node of the path |
createNode | protected Node createNode(String name)(Code) | | Creates a new Node object with the specified name. This
method can be overloaded in derived classes if a specific node type is
needed. This base implementation always returns a new object of the
Node class.
Parameters: name - the name of the new node the new node |
createSubnodeConfiguration | protected SubnodeConfiguration createSubnodeConfiguration(ConfigurationNode node)(Code) | | Creates a subnode configuration for the specified node. This method is
called by configurationAt() and
configurationsAt() .
Parameters: node - the node, for which a subnode configuration is to be created the configuration for the given node since: 1.3 |
fetchAddNode | protected Node fetchAddNode(ConfigurationKey.KeyIterator keyIt, Node startNode)(Code) | | Returns a reference to the parent node of an add operation. Nodes for new
properties can be added as children of this node. If the path for the
specified key does not exist so far, it is created now.
Parameters: keyIt - the iterator for the key of the new property Parameters: startNode - the node to start the search with the parent node for the add operation |
fetchNodeList | protected List fetchNodeList(String key)(Code) | | Helper method for fetching a list of all nodes that are addressed by the
specified key.
Parameters: key - the key a list with all affected nodes (never null ) |
findLastPathNode | protected Node findLastPathNode(ConfigurationKey.KeyIterator keyIt, Node node)(Code) | | Finds the last existing node for an add operation. This method traverses
the configuration tree along the specified key. The last existing node on
this path is returned.
Parameters: keyIt - the key iterator Parameters: node - the actual node the last existing node on the given path |
findPropertyNodes | protected void findPropertyNodes(ConfigurationKey.KeyIterator keyPart, Node node, Collection nodes)(Code) | | Recursive helper method for fetching a property. This method processes
all facets of a configuration key, traverses the tree of properties and
fetches the the nodes of all matching properties.
Parameters: keyPart - the configuration key iterator Parameters: node - the actual node Parameters: nodes - here the found nodes are stored |
getDefaultExpressionEngine | public static ExpressionEngine getDefaultExpressionEngine()(Code) | | Returns the default expression engine.
the default expression engine since: 1.3 |
getExpressionEngine | public ExpressionEngine getExpressionEngine()(Code) | | Returns the expression engine used by this configuration. This method
will never return null; if no specific expression engine was set,
the default expression engine will be returned.
the current expression engine since: 1.3 |
getKeys | public Iterator getKeys()(Code) | | Returns an iterator with all keys defined in this configuration.
Note that the keys returned by this method will not contain any
indices. This means that some structure will be lost.
an iterator with the defined keys in this configuration |
getKeys | public Iterator getKeys(String prefix)(Code) | | Returns an iterator with all keys defined in this configuration that
start with the given prefix. The returned keys will not contain any
indices.
Parameters: prefix - the prefix of the keys to start with an iterator with the found keys |
getMaxIndex | public int getMaxIndex(String key)(Code) | | Returns the maximum defined index for the given key. This is useful if
there are multiple values for this key. They can then be addressed
separately by specifying indices from 0 to the return value of this
method.
Parameters: key - the key to be checked the maximum defined index for this key |
getProperty | public Object getProperty(String key)(Code) | | Fetches the specified property. This task is delegated to the associated
expression engine.
Parameters: key - the key to be looked up the found value |
getRoot | public Node getRoot()(Code) | | Returns the root node of this hierarchical configuration. This method
exists for backwards compatibility only. New code should use the
HierarchicalConfiguration.getRootNode() method instead, which operates on
the preferred data type ConfigurationNode .
the root node |
getRootNode | public ConfigurationNode getRootNode()(Code) | | Returns the root node of this hierarchical configuration.
the root node since: 1.3 |
isEmpty | public boolean isEmpty()(Code) | | Checks if this configuration is empty. Empty means that there are no keys
with any values, though there can be some (empty) nodes.
a flag if this configuration is empty |
nodeDefined | protected boolean nodeDefined(ConfigurationNode node)(Code) | | Checks if the specified node is defined.
Parameters: node - the node to be checked a flag if this node is defined |
removeNode | protected void removeNode(ConfigurationNode node)(Code) | | Removes the specified node from this configuration. This method ensures
that parent nodes that become undefined by this operation are also
removed.
Parameters: node - the node to be removed |
setDefaultExpressionEngine | public static void setDefaultExpressionEngine(ExpressionEngine engine)(Code) | | Sets the default expression engine. This expression engine will be used
if no specific engine was set for an instance. It is shared between all
hierarchical configuration instances. So modifying its properties will
impact all instances, for which no specific engine is set.
Parameters: engine - the new default expression engine since: 1.3 |
setExpressionEngine | public void setExpressionEngine(ExpressionEngine expressionEngine)(Code) | | Sets the expression engine to be used by this configuration. All property
keys this configuration has to deal with will be interpreted by this
engine.
Parameters: expressionEngine - the new expression engine; can be null,then the default expression engine will be used since: 1.3 |
setProperty | public void setProperty(String key, Object value)(Code) | | Sets the value of the specified property.
Parameters: key - the key of the property to set Parameters: value - the new value of this property |
setRoot | public void setRoot(Node node)(Code) | | Sets the root node of this hierarchical configuration. This method
exists for backwards compatibility only. New code should use the
HierarchicalConfiguration.setRootNode(ConfigurationNode) method instead,
which operates on the preferred data type ConfigurationNode .
Parameters: node - the root node |
setRootNode | public void setRootNode(ConfigurationNode rootNode)(Code) | | Sets the root node of this hierarchical configuration.
Parameters: rootNode - the root node since: 1.3 |
subset | public Configuration subset(String prefix)(Code) | | Creates a new Configuration object containing all keys
that start with the specified prefix. This implementation will return a
HierarchicalConfiguration object so that the structure of
the keys will be saved.
Parameters: prefix - the prefix of the keys for the subset a new configuration object representing the selected subset |
Methods inherited from org.apache.commons.configuration.AbstractConfiguration | public void addErrorLogListener()(Code)(Java Doc) public void addProperty(String key, Object value)(Code)(Java Doc) abstract protected void addPropertyDirect(String key, Object value)(Code)(Java Doc) public void clear()(Code)(Java Doc) public void clearProperty(String key)(Code)(Java Doc) protected void clearPropertyDirect(String key)(Code)(Java Doc) abstract public boolean containsKey(String key)(Code)(Java Doc) protected ConfigurationInterpolator createInterpolator()(Code)(Java Doc) public BigDecimal getBigDecimal(String key)(Code)(Java Doc) public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)(Code)(Java Doc) public BigInteger getBigInteger(String key)(Code)(Java Doc) public BigInteger getBigInteger(String key, BigInteger defaultValue)(Code)(Java Doc) public boolean getBoolean(String key)(Code)(Java Doc) public boolean getBoolean(String key, boolean defaultValue)(Code)(Java Doc) public Boolean getBoolean(String key, Boolean defaultValue)(Code)(Java Doc) public byte getByte(String key)(Code)(Java Doc) public byte getByte(String key, byte defaultValue)(Code)(Java Doc) public Byte getByte(String key, Byte defaultValue)(Code)(Java Doc) public static char getDefaultListDelimiter()(Code)(Java Doc) public static char getDelimiter()(Code)(Java Doc) public double getDouble(String key)(Code)(Java Doc) public double getDouble(String key, double defaultValue)(Code)(Java Doc) public Double getDouble(String key, Double defaultValue)(Code)(Java Doc) public float getFloat(String key)(Code)(Java Doc) public float getFloat(String key, float defaultValue)(Code)(Java Doc) public Float getFloat(String key, Float defaultValue)(Code)(Java Doc) public int getInt(String key)(Code)(Java Doc) public int getInt(String key, int defaultValue)(Code)(Java Doc) public Integer getInteger(String key, Integer defaultValue)(Code)(Java Doc) public ConfigurationInterpolator getInterpolator()(Code)(Java Doc) abstract public Iterator getKeys()(Code)(Java Doc) public Iterator getKeys(String prefix)(Code)(Java Doc) public List getList(String key)(Code)(Java Doc) public List getList(String key, List defaultValue)(Code)(Java Doc) public char getListDelimiter()(Code)(Java Doc) public Log getLogger()(Code)(Java Doc) public long getLong(String key)(Code)(Java Doc) public long getLong(String key, long defaultValue)(Code)(Java Doc) public Long getLong(String key, Long defaultValue)(Code)(Java Doc) public Properties getProperties(String key)(Code)(Java Doc) public Properties getProperties(String key, Properties defaults)(Code)(Java Doc) public short getShort(String key)(Code)(Java Doc) public short getShort(String key, short defaultValue)(Code)(Java Doc) public Short getShort(String key, Short defaultValue)(Code)(Java Doc) public String getString(String key)(Code)(Java Doc) public String getString(String key, String defaultValue)(Code)(Java Doc) public String[] getStringArray(String key)(Code)(Java Doc) public synchronized StrSubstitutor getSubstitutor()(Code)(Java Doc) protected String interpolate(String base)(Code)(Java Doc) protected Object interpolate(Object value)(Code)(Java Doc) protected String interpolateHelper(String base, List priorVariables)(Code)(Java Doc) public boolean isDelimiterParsingDisabled()(Code)(Java Doc) abstract public boolean isEmpty()(Code)(Java Doc) public boolean isThrowExceptionOnMissing()(Code)(Java Doc) protected Object resolveContainerStore(String key)(Code)(Java Doc) public static void setDefaultListDelimiter(char delimiter)(Code)(Java Doc) public static void setDelimiter(char delimiter)(Code)(Java Doc) public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)(Code)(Java Doc) public void setListDelimiter(char listDelimiter)(Code)(Java Doc) public void setLogger(Log log)(Code)(Java Doc) public void setProperty(String key, Object value)(Code)(Java Doc) public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)(Code)(Java Doc) public Configuration subset(String prefix)(Code)(Java Doc)
|
|
|
|