|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.HierarchicalConfiguration
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
org.apache.commons.configuration.PatternSubtreeConfigurationWrapper
Wraps a HierarchicalConfiguration and allows subtrees to be access via a configured path with replaceable tokens derived from the ConfigurationInterpolator. When used with injection frameworks such as Spring it allows components to be injected with subtrees of the configuration.
| Nested Class Summary |
| Nested classes inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration |
AbstractHierarchicalFileConfiguration.FileConfigurationDelegate |
| Nested classes inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor |
| Field Summary |
| Fields inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
EVENT_ADD_NODES, EVENT_CLEAR_TREE, EVENT_SUBNODE_CHANGED |
| Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN |
| Constructor Summary | |
PatternSubtreeConfigurationWrapper(AbstractHierarchicalFileConfiguration config,
String path)
Constructor |
|
| Method Summary | |
void |
addConfigurationListener(ConfigurationListener l)
Adds a configuration listener to this object. |
void |
addErrorListener(ConfigurationErrorListener l)
Adds a new configuration error listener to this object. |
void |
addNodes(String key,
Collection nodes)
Directly adds sub nodes to this configuration. |
void |
addProperty(String key,
Object value)
Add a property to the configuration. |
void |
clear()
Remove all properties from the configuration. |
void |
clearConfigurationListeners()
Removes all registered configuration listeners. |
void |
clearErrorListeners()
Removes all registered error listeners. |
void |
clearProperty(String key)
Remove a property from the configuration. |
void |
clearTree(String key)
Removes all values of the property with the given name and of keys that start with this name. |
SubnodeConfiguration |
configurationAt(String key)
Returns a hierarchical subnode configuration for the node specified by the given key. |
SubnodeConfiguration |
configurationAt(String key,
boolean supportUpdates)
Returns a hierarchical subnode configuration object that wraps the configuration node specified by the given key. |
List |
configurationsAt(String key)
Returns a list of sub configurations for all configuration nodes selected by the given key. |
boolean |
containsKey(String key)
Check if the configuration contains the specified key. |
BigDecimal |
getBigDecimal(String key)
Get a BigDecimal associated with the given configuration key. |
BigDecimal |
getBigDecimal(String key,
BigDecimal defaultValue)
Get a BigDecimal associated with the given configuration key.
|
BigInteger |
getBigInteger(String key)
Get a BigInteger associated with the given configuration key. |
BigInteger |
getBigInteger(String key,
BigInteger defaultValue)
Get a BigInteger associated with the given configuration key.
|
boolean |
getBoolean(String key)
Get a boolean associated with the given configuration key. |
boolean |
getBoolean(String key,
boolean defaultValue)
Get a boolean associated with the given configuration key. |
Boolean |
getBoolean(String key,
Boolean defaultValue)
Get a Boolean associated with the given configuration key. |
byte |
getByte(String key)
Get a byte associated with the given configuration key. |
byte |
getByte(String key,
byte defaultValue)
Get a byte associated with the given configuration key. |
Byte |
getByte(String key,
Byte defaultValue)
Get a Byte associated with the given configuration key. |
Collection |
getConfigurationListeners()
Returns a collection with all configuration event listeners that are currently registered at this object. |
double |
getDouble(String key)
Get a double associated with the given configuration key. |
double |
getDouble(String key,
double defaultValue)
Get a double associated with the given configuration key. |
Double |
getDouble(String key,
Double defaultValue)
Get a Double associated with the given configuration key. |
Collection |
getErrorListeners()
Returns a collection with all configuration error listeners that are currently registered at this object. |
ExpressionEngine |
getExpressionEngine()
Returns the expression engine used by this configuration. |
float |
getFloat(String key)
Get a float associated with the given configuration key. |
float |
getFloat(String key,
float defaultValue)
Get a float associated with the given configuration key. |
Float |
getFloat(String key,
Float defaultValue)
Get a Float associated with the given configuration key.
|
int |
getInt(String key)
Get a int associated with the given configuration key. |
int |
getInt(String key,
int defaultValue)
Get a int associated with the given configuration key. |
Integer |
getInteger(String key,
Integer defaultValue)
Get an Integer associated with the given configuration key.
|
Iterator |
getKeys()
Get the list of the keys contained in the configuration. |
Iterator |
getKeys(String prefix)
Get the list of the keys contained in the configuration that match the specified prefix. |
List |
getList(String key)
Get a List of strings associated with the given configuration key. |
List |
getList(String key,
List defaultValue)
Get a List of strings associated with the given configuration key. |
long |
getLong(String key)
Get a long associated with the given configuration key. |
long |
getLong(String key,
long defaultValue)
Get a long associated with the given configuration key. |
Long |
getLong(String key,
Long defaultValue)
Get a Long associated with the given configuration key.
|
int |
getMaxIndex(String key)
Returns the maximum defined index for the given key. |
Properties |
getProperties(String key)
Get a list of properties associated with the given configuration key. |
Object |
getProperty(String key)
Gets a property from the configuration. |
HierarchicalConfiguration.Node |
getRoot()
Returns the root node of this hierarchical configuration. |
ConfigurationNode |
getRootNode()
Returns the root node of this hierarchical configuration. |
short |
getShort(String key)
Get a short associated with the given configuration key. |
short |
getShort(String key,
short defaultValue)
Get a short associated with the given configuration key. |
Short |
getShort(String key,
Short defaultValue)
Get a Short associated with the given configuration key.
|
String |
getString(String key)
Get a string associated with the given configuration key. |
String |
getString(String key,
String defaultValue)
Get a string associated with the given configuration key. |
String[] |
getStringArray(String key)
Get an array of strings associated with the given configuration key. |
Configuration |
interpolatedConfiguration()
Returns a configuration with the same content as this configuration, but with all variables replaced by their actual values. |
boolean |
isEmpty()
Check if the configuration is empty. |
void |
load(Reader reader)
Load the configuration from the specified reader. |
boolean |
removeConfigurationListener(ConfigurationListener l)
Removes the specified event listener so that it does not receive any further events caused by this object. |
boolean |
removeErrorListener(ConfigurationErrorListener l)
Removes the specified error listener so that it does not receive any further events caused by this object. |
protected Object |
resolveContainerStore(String key)
Returns an object from the store described by the key. |
void |
save(Writer writer)
Save the configuration to the specified writer. |
void |
setExpressionEngine(ExpressionEngine expressionEngine)
Sets the expression engine to be used by this configuration. |
void |
setProperty(String key,
Object value)
Set a property, this will replace any previously set values. |
void |
setRoot(HierarchicalConfiguration.Node node)
Sets the root node of this hierarchical configuration. |
void |
setRootNode(ConfigurationNode rootNode)
Sets the root node of this hierarchical configuration. |
Configuration |
subset(String prefix)
Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix. |
| Methods inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration |
addPropertyDirect, configurationChanged, createDelegate, fetchNodeList, getBasePath, getDelegate, getEncoding, getFile, getFileName, getReloadingStrategy, getURL, isAutoSave, load, load, load, load, load, load, reload, save, save, save, save, save, save, setAutoSave, setBasePath, setDelegate, setEncoding, setFile, setFileName, setReloadingStrategy, setURL, subnodeConfigurationChanged |
| Methods inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
clearNode, clearNode, clearReferences, clone, createAddPath, createNode, createSubnodeConfiguration, createSubnodeConfiguration, fetchAddNode, findLastPathNode, findPropertyNodes, getDefaultExpressionEngine, nodeDefined, nodeDefined, removeNode, removeNode, setDefaultExpressionEngine |
| Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
addErrorLogListener, append, clearPropertyDirect, copy, createInterpolator, getDefaultListDelimiter, getDelimiter, getInterpolator, getListDelimiter, getLogger, getProperties, getSubstitutor, interpolate, interpolate, interpolateHelper, isDelimiterParsingDisabled, isThrowExceptionOnMissing, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissing |
| Methods inherited from class org.apache.commons.configuration.event.EventSource |
createErrorEvent, createEvent, fireError, fireEvent, isDetailEvents, setDetailEvents |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public PatternSubtreeConfigurationWrapper(AbstractHierarchicalFileConfiguration config,
String path)
config - The Configuration to be wrapped.path - The base path pattern.| Method Detail |
public void addProperty(String key,
Object value)
Configurationresource.loader = fileis already present in the configuration and you call
addProperty("resource.loader", "classpath")
Then you will end up with a List like the following:
["file", "classpath"]
addProperty in interface ConfigurationaddProperty in class AbstractConfigurationpublic void clear()
Configuration
clear in interface Configurationclear in class AbstractConfigurationpublic void clearProperty(String key)
Configuration
clearProperty in interface ConfigurationclearProperty in class AbstractHierarchicalFileConfigurationpublic boolean containsKey(String key)
Configuration
containsKey in interface ConfigurationcontainsKey in class AbstractHierarchicalFileConfiguration
public BigDecimal getBigDecimal(String key,
BigDecimal defaultValue)
ConfigurationBigDecimal associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getBigDecimal in interface ConfigurationgetBigDecimal in class AbstractConfigurationpublic BigDecimal getBigDecimal(String key)
ConfigurationBigDecimal associated with the given configuration key.
getBigDecimal in interface ConfigurationgetBigDecimal in class AbstractConfigurationAbstractConfiguration.setThrowExceptionOnMissing(boolean)
public BigInteger getBigInteger(String key,
BigInteger defaultValue)
ConfigurationBigInteger associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getBigInteger in interface ConfigurationgetBigInteger in class AbstractConfigurationpublic BigInteger getBigInteger(String key)
ConfigurationBigInteger associated with the given configuration key.
getBigInteger in interface ConfigurationgetBigInteger in class AbstractConfigurationAbstractConfiguration.setThrowExceptionOnMissing(boolean)
public boolean getBoolean(String key,
boolean defaultValue)
Configuration
getBoolean in interface ConfigurationgetBoolean in class AbstractConfigurationPropertyConverter.toBoolean(Object)
public Boolean getBoolean(String key,
Boolean defaultValue)
ConfigurationBoolean associated with the given configuration key.
getBoolean in interface ConfigurationgetBoolean in class AbstractConfigurationkey - the key of the propertydefaultValue - the default value
BooleanPropertyConverter.toBoolean(Object)public boolean getBoolean(String key)
Configuration
getBoolean in interface ConfigurationgetBoolean in class AbstractConfigurationPropertyConverter.toBoolean(Object)
public byte getByte(String key,
byte defaultValue)
Configuration
getByte in interface ConfigurationgetByte in class AbstractConfiguration
public Byte getByte(String key,
Byte defaultValue)
ConfigurationByte associated with the given configuration key.
getByte in interface ConfigurationgetByte in class AbstractConfigurationpublic byte getByte(String key)
Configuration
getByte in interface ConfigurationgetByte in class AbstractConfiguration
public double getDouble(String key,
double defaultValue)
Configuration
getDouble in interface ConfigurationgetDouble in class AbstractConfiguration
public Double getDouble(String key,
Double defaultValue)
ConfigurationDouble associated with the given configuration key.
getDouble in interface ConfigurationgetDouble in class AbstractConfigurationpublic double getDouble(String key)
Configuration
getDouble in interface ConfigurationgetDouble in class AbstractConfiguration
public float getFloat(String key,
float defaultValue)
Configuration
getFloat in interface ConfigurationgetFloat in class AbstractConfiguration
public Float getFloat(String key,
Float defaultValue)
ConfigurationFloat associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getFloat in interface ConfigurationgetFloat in class AbstractConfigurationpublic float getFloat(String key)
Configuration
getFloat in interface ConfigurationgetFloat in class AbstractConfiguration
public int getInt(String key,
int defaultValue)
Configuration
getInt in interface ConfigurationgetInt in class AbstractConfigurationpublic int getInt(String key)
Configuration
getInt in interface ConfigurationgetInt in class AbstractConfiguration
public Integer getInteger(String key,
Integer defaultValue)
ConfigurationInteger associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getInteger in interface ConfigurationgetInteger in class AbstractConfigurationpublic Iterator getKeys()
Configurationremove() method is specific to
a concrete implementation. It may remove the corresponding
property from the configuration, but this is not guaranteed. In any case
it is no replacement for calling
Configuration.clearProperty(String) for this property. So it is
highly recommended to avoid using the iterator's remove()
method.
getKeys in interface ConfigurationgetKeys in class AbstractHierarchicalFileConfigurationpublic Iterator getKeys(String prefix)
Configuration
getKeys in interface ConfigurationgetKeys in class AbstractHierarchicalFileConfiguration
public List getList(String key,
List defaultValue)
Configuration
getList in interface ConfigurationgetList in class AbstractConfigurationpublic List getList(String key)
Configuration
getList in interface ConfigurationgetList in class AbstractConfigurationAbstractConfiguration.getStringArray(String)
public long getLong(String key,
long defaultValue)
Configuration
getLong in interface ConfigurationgetLong in class AbstractConfiguration
public Long getLong(String key,
Long defaultValue)
ConfigurationLong associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getLong in interface ConfigurationgetLong in class AbstractConfigurationpublic long getLong(String key)
Configuration
getLong in interface ConfigurationgetLong in class AbstractConfigurationpublic Properties getProperties(String key)
Configurationkey=value. These
strings are splitted at the equals sign, and the key parts will become
keys of the returned Properties object, the value parts
become values.
getProperties in interface ConfigurationgetProperties in class AbstractConfigurationpublic Object getProperty(String key)
ConfigurationConfiguration interface the other get methods (that
return specific data types) will internally make use of this method. On
this level variable substitution is not yet performed. The returned
object is an internal representation of the property value for the passed
in key. It is owned by the Configuration object. So a caller
should not modify this object. It cannot be guaranteed that this object
will stay constant over time (i.e. further update operations on the
configuration may change its internal state).
getProperty in interface ConfigurationgetProperty in class AbstractHierarchicalFileConfiguration
public short getShort(String key,
short defaultValue)
Configuration
getShort in interface ConfigurationgetShort in class AbstractConfiguration
public Short getShort(String key,
Short defaultValue)
ConfigurationShort associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getShort in interface ConfigurationgetShort in class AbstractConfigurationpublic short getShort(String key)
Configuration
getShort in interface ConfigurationgetShort in class AbstractConfiguration
public String getString(String key,
String defaultValue)
Configuration
getString in interface ConfigurationgetString in class AbstractConfigurationpublic String getString(String key)
Configuration
getString in interface ConfigurationgetString in class AbstractConfigurationAbstractConfiguration.setThrowExceptionOnMissing(boolean)public String[] getStringArray(String key)
Configuration
getStringArray in interface ConfigurationgetStringArray in class AbstractConfigurationkey - The configuration key.
AbstractConfiguration.setListDelimiter(char),
AbstractConfiguration.setDelimiterParsingDisabled(boolean)public boolean isEmpty()
Configuration
isEmpty in interface ConfigurationisEmpty in class AbstractHierarchicalFileConfiguration
public void setProperty(String key,
Object value)
Configuration
setProperty in interface ConfigurationsetProperty in class AbstractHierarchicalFileConfigurationpublic Configuration subset(String prefix)
Configuration
prefix.number = 1
prefix.string = Apache
prefixed.foo = bar
prefix = Jakarta
the Configuration returned by subset("prefix") will contain
the properties:
number = 1
string = Apache
= Jakarta
(The key for the value "Jakarta" is an empty string)
Since the subset is a decorator and not a modified copy of the initial Configuration, any change made to the subset is available to the Configuration, and reciprocally.
subset in interface Configurationsubset in class HierarchicalConfigurationprefix - the prefix of the keys for the subset
public HierarchicalConfiguration.Node getRoot()
HierarchicalConfigurationHierarchicalConfiguration.getRootNode() method instead, which operates on
the preferred data type ConfigurationNode.
getRoot in class HierarchicalConfigurationpublic void setRoot(HierarchicalConfiguration.Node node)
HierarchicalConfigurationHierarchicalConfiguration.setRootNode(ConfigurationNode) method instead,
which operates on the preferred data type ConfigurationNode.
setRoot in class HierarchicalConfigurationnode - the root nodepublic ConfigurationNode getRootNode()
HierarchicalConfiguration
getRootNode in class HierarchicalConfigurationpublic void setRootNode(ConfigurationNode rootNode)
HierarchicalConfiguration
setRootNode in class HierarchicalConfigurationrootNode - the root nodepublic ExpressionEngine getExpressionEngine()
HierarchicalConfiguration
getExpressionEngine in class HierarchicalConfigurationpublic void setExpressionEngine(ExpressionEngine expressionEngine)
HierarchicalConfiguration
setExpressionEngine in class HierarchicalConfigurationexpressionEngine - the new expression engine; can be null,
then the default expression engine will be used
public void addNodes(String key,
Collection nodes)
AbstractHierarchicalFileConfiguration
addNodes in class AbstractHierarchicalFileConfigurationkey - the key where the nodes are to be addednodes - a collection with the nodes to be added
public SubnodeConfiguration configurationAt(String key,
boolean supportUpdates)
HierarchicalConfiguration
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
method is that
HierarchicalConfiguration.subset(String)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.
With the supportUpdate flag the behavior of the returned
SubnodeConfiguration regarding updates of its parent
configuration can be determined. A subnode configuration operates on the
same nodes as its parent, so changes at one configuration are normally
directly visible for the other configuration. There are however changes
of the parent configuration, which are not recognized by the subnode
configuration per default. An example for this is a reload operation (for
file-based configurations): Here the complete node set of the parent
configuration is replaced, but the subnode configuration still references
the old nodes. If such changes should be detected by the subnode
configuration, the supportUpdates flag must be set to
true. This causes the subnode configuration to reevaluate the key
used for its creation each time it is accessed. This guarantees that the
subnode configuration always stays in sync with its key, even if the
parent configuration's data significantly changes. If such a change
makes the key invalid - because it now no longer points to exactly one
node -, the subnode configuration is not reconstructed, but keeps its
old data. It is then quasi detached from its parent.
configurationAt in class HierarchicalConfigurationkey - the key that selects the sub treesupportUpdates - a flag whether the returned subnode configuration
should be able to handle updates of its parent
SubnodeConfigurationpublic SubnodeConfiguration configurationAt(String key)
HierarchicalConfigurationconfigurationAt(key,
false).
configurationAt in class HierarchicalConfigurationkey - the key that selects the sub tree
SubnodeConfigurationpublic List configurationsAt(String key)
HierarchicalConfigurationExpressionEngine) 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");
...
configurationsAt in class HierarchicalConfigurationkey - the key for selecting the desired nodes
public void clearTree(String key)
HierarchicalConfigurationclearTree("foo") would remove both properties.
clearTree in class AbstractHierarchicalFileConfigurationpublic int getMaxIndex(String key)
HierarchicalConfiguration
getMaxIndex in class HierarchicalConfigurationkey - the key to be checked
public Configuration interpolatedConfiguration()
HierarchicalConfiguration
interpolatedConfiguration in class HierarchicalConfigurationpublic void addConfigurationListener(ConfigurationListener l)
EventSource
addConfigurationListener in class EventSourcel - the listener to addpublic boolean removeConfigurationListener(ConfigurationListener l)
EventSource
removeConfigurationListener in class EventSourcel - the listener to be removed
public Collection getConfigurationListeners()
EventSource
getConfigurationListeners in class EventSourceConfigurationListeners (this collection is a snapshot
of the currently registered listeners; manipulating it has no effect
on this event source object)public void clearConfigurationListeners()
EventSource
clearConfigurationListeners in class EventSourcepublic void addErrorListener(ConfigurationErrorListener l)
EventSource
addErrorListener in class EventSourcel - the listener to register (must not be null)public boolean removeErrorListener(ConfigurationErrorListener l)
EventSource
removeErrorListener in class EventSourcel - the listener to remove
public void clearErrorListeners()
EventSource
clearErrorListeners in class EventSource
public void save(Writer writer)
throws ConfigurationException
FileConfiguration
writer - the writer
ConfigurationException - if an error occurs during the save operation
public void load(Reader reader)
throws ConfigurationException
FileConfiguration
reader - the reader
ConfigurationException - if an error occurs during the load operationpublic Collection getErrorListeners()
EventSource
getErrorListeners in class EventSourceConfigurationErrorListeners (this collection is a
snapshot of the currently registered listeners; it cannot be manipulated)protected Object resolveContainerStore(String key)
AbstractConfiguration
resolveContainerStore in class AbstractConfigurationkey - The property key.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||