Configuration is a interface encapsulating a configuration node
used to retrieve configuration values.
This is a "read only" interface preventing applications from modifying their own configurations. Once it is created, the information never changes.
The data model is a subset of XML's; a single-rooted hierarchical tree where each
node can contain multiple attributes, and leaf nodes can also
contain a value. Reflecting this, Configurations are
usually built from an XML file by the DefaultConfigurationBuilder
class, or directly by a SAX parser using a SAXConfigurationHandler or
NamespacedSAXConfigurationHandler event handler.
Since version 4.1, each Configuration node has a namespace
associated with it, in the form of a string, accessible through getNamespace. If no namespace is present, getNamespace will
return blank (""). See DefaultConfigurationBuilder for details on how
XML namespaces are mapped to Configuration namespaces.
As an example, consider two Configurations (with and without
namespaces) built from this XML:
<my-system version="1.3" xmlns:doc="http://myco.com/documentation"> <doc:desc>This is a highly fictitious config file</doc:desc> <widget name="fooWidget" initOrder="1" threadsafe="true"/> </my-system>
If namespace support is enabled (eg through
DefaultConfigurationBuilder#DefaultConfigurationBuilder(boolean) new
DefaultConfigurationBuilder(true)), then the xmlns:doc element
will not translate into a Configuration attribute, and the
doc:desc element will become a Configuration node
with name "desc" and namespace "http://myco.com/documentation". The
widget element will have namespace "".
If namespace support is disabled (the default for
DefaultConfigurationBuilder), the above XML will translate directly to
Configuration nodes. The my-system node will have
an attribute named "xmlns:doc", and a child called "doc:desc".
Assuming the Configuration object is named conf,
here is how the data could be retrieved:
| Code | No namespaces | With namespaces |
|---|---|---|
conf. | my-system | |
conf.
| 2 | 1 |
conf.
| 2 | |
conf.
| 1.3 | |
conf.
| fooWidget | |
conf. |
true | |
conf.
| file:///home/jeff/tmp/java/avalon/src/java/new.xconf:4:60 | |
conf.
| desc (see getChild(String)) | desc |
conf.
| doc:desc | doc:desc (see getChild(String)) |
conf.
| ConfigurationException | This is a highly fictitious config file |
conf.
| This is a highly fictitious config file | ConfigurationException |
conf.
| http://myco.com/documentation" | |
Type-safe utility methods are provided for retrieving attribute and element
values as String, int, long,
float and boolean.
Currently, the configuration tree can only be traversed one node at a time,
eg., through getChild("foo") or getChildren(). In
a future release, it may be possible to access child nodes with an XPath-like
syntax.
Checking for the existence of an attribute can be done as follows:
String value = conf.getAttribute( "myAttribute", null );
if ( null == value )
{
// Do the processing applicable if the attribute isn't present.
}
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: String value of attribute.The name of the parameter you ask the value of. paramName)Return the value of specified attribute. |
| public String | Returns: String value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.The name of the attribute you ask the value of. name, String The default value desired. defaultValue)Returns the value of the attribute specified by its name as a
|
| public boolean | Returns: boolean value of attributeThe name of the parameter you ask the value of. paramName)Return the |
| public boolean | Returns: boolean value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.The name of the attribute you ask the value of. name, boolean The default value desired. defaultValue)Returns the value of the attribute specified by its name as a
|
| public double | Returns: double value of attributeThe name of the parameter you ask the value of. paramName)Return the |
| public double | Returns: float value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.The name of the attribute you ask the value of. name, double The default value desired. defaultValue)Returns the value of the attribute specified by its name as a
|
| public float | Returns: float value of attributeThe name of the parameter you ask the value of. paramName)Return the |
| public float | Returns: float value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.The name of the attribute you ask the value of. name, float The default value desired. defaultValue)Returns the value of the attribute specified by its name as a
|
| public int | Returns: int value of attributeThe name of the parameter you ask the value of. paramName)Return the |
| public int | Returns: int value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.The name of the attribute you ask the value of. name, int The default value desired. defaultValue)Returns the value of the attribute specified by its name as a
|
| public long | Returns: long value of attributeThe name of the parameter you ask the value of. name)Returns the value of the attribute specified by its name as a
|
| public long | Returns: long value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.The name of the attribute you ask the value of. name, long The default value desired. defaultValue)Returns the value of the attribute specified by its name as a
|
| public String[] | |
| public Configuration | |
| public Configuration | Returns: ConfigurationThe name of the child node. child, boolean If createNew)true, a new Configuration
will be created and returned if the specified child does not exist. If
false, null will be returned when the specified
child doesn't exist.Return a |
| public Configuration[] | Returns: All child nodesReturn an |
| public Configuration[] | Returns: The child nodes with namenameThe name of the children to get. name)Return an |
| public String | Returns: a string describing location of ConfigurationReturn a string describing location of Configuration. |
| public String | |
| public String | Returns: a String identifying the namespace of this Configuration.Returns a string indicating which namespace this Configuration node belongs to. |
| public String | |
| public String | |
| public boolean | |
| public boolean | Returns: boolean value of theConfiguration, or default
if none specified.The default value desired. defaultValue)Returns the value of the configuration element as a |
| public double | |
| public double | Returns: float value of theConfiguration, or default
if none specified.The default value desired. defaultValue)Returns the value of the configuration element as a |
| public float | |
| public float | Returns: float value of theConfiguration, or default
if none specified.The default value desired. defaultValue)Returns the value of the configuration element as a |
| public int | |
| public int | Returns: int value of theConfiguration, or default
if none specified.The default value desired. defaultValue)Returns the value of the configuration element as an |
| public long | |
| public long | Returns: long value of theConfiguration, or default
if none specified.The default value desired. defaultValue)Returns the value of the configuration element as a |
| getAttribute | back to summary |
|---|---|
| public String getAttribute(String paramName) throws ConfigurationException Return the value of specified attribute.
| |
| getAttribute | back to summary |
|---|---|
| public String getAttribute(String name, String defaultValue) Returns the value of the attribute specified by its name as a
| |
| getAttributeAsBoolean | back to summary |
|---|---|
| public boolean getAttributeAsBoolean(String paramName) throws ConfigurationException Return the
| |
| getAttributeAsBoolean | back to summary |
|---|---|
| public boolean getAttributeAsBoolean(String name, boolean defaultValue) Returns the value of the attribute specified by its name as a
| |
| getAttributeAsDouble | back to summary |
|---|---|
| public double getAttributeAsDouble(String paramName) throws ConfigurationException Return the
| |
| getAttributeAsDouble | back to summary |
|---|---|
| public double getAttributeAsDouble(String name, double defaultValue) Returns the value of the attribute specified by its name as a
| |
| getAttributeAsFloat | back to summary |
|---|---|
| public float getAttributeAsFloat(String paramName) throws ConfigurationException Return the
| |
| getAttributeAsFloat | back to summary |
|---|---|
| public float getAttributeAsFloat(String name, float defaultValue) Returns the value of the attribute specified by its name as a
| |
| getAttributeAsInteger | back to summary |
|---|---|
| public int getAttributeAsInteger(String paramName) throws ConfigurationException Return the
| |
| getAttributeAsInteger | back to summary |
|---|---|
| public int getAttributeAsInteger(String name, int defaultValue) Returns the value of the attribute specified by its name as a
| |
| getAttributeAsLong | back to summary |
|---|---|
| public long getAttributeAsLong(String name) throws ConfigurationException Returns the value of the attribute specified by its name as a
| |
| getAttributeAsLong | back to summary |
|---|---|
| public long getAttributeAsLong(String name, long defaultValue) Returns the value of the attribute specified by its name as a
| |
| getAttributeNames | back to summary |
|---|---|
| public String[] getAttributeNames() Return an array of all attribute names.
The order of attributes in this array can not be relied on. As
with XML, a
| |
| getChild | back to summary |
|---|---|
| public Configuration getChild(String child) Return a new
If no such child node exists, an empty
If you wish to get a
| |
| getChild | back to summary |
|---|---|
| public Configuration getChild(String child, boolean createNew) Return a
| |
| getChildren | back to summary |
|---|---|
| public Configuration[] getChildren() Return an
| |
| getChildren | back to summary |
|---|---|
| public Configuration[] getChildren(String name) Return an
| |
| getLocation | back to summary |
|---|---|
| public String getLocation() Return a string describing location of Configuration. Location can be different for different mediums (ie "file:line" for normal XML files or "table:primary-key" for DB based configurations);
| |
| getName | back to summary |
|---|---|
| public String getName() Return the name of the node.
| |
| getNamespace | back to summary |
|---|---|
| public String getNamespace() throws ConfigurationException Returns a string indicating which namespace this Configuration node belongs to. What this returns is dependent on the configuration file and the Configuration builder. If the Configuration builder does not support namespaces, this method will return a blank string. In the case of DefaultConfigurationBuilder, the namespace will be the URI associated with the XML element. Eg.,: <foo xmlns:x="http://blah.com"> <x:bar/> </foo> The namespace of
| |
| getValue | back to summary |
|---|---|
| public String getValue() throws ConfigurationException Return the
| |
| getValue | back to summary |
|---|---|
| public String getValue(String defaultValue) Returns the value of the configuration element as a | |
| getValueAsBoolean | back to summary |
|---|---|
| public boolean getValueAsBoolean() throws ConfigurationException Return the
| |
| getValueAsBoolean | back to summary |
|---|---|
| public boolean getValueAsBoolean(boolean defaultValue) Returns the value of the configuration element as a
| |
| getValueAsDouble | back to summary |
|---|---|
| public double getValueAsDouble() throws ConfigurationException Return the
| |
| getValueAsDouble | back to summary |
|---|---|
| public double getValueAsDouble(double defaultValue) Returns the value of the configuration element as a
| |
| getValueAsFloat | back to summary |
|---|---|
| public float getValueAsFloat() throws ConfigurationException Return the
| |
| getValueAsFloat | back to summary |
|---|---|
| public float getValueAsFloat(float defaultValue) Returns the value of the configuration element as a
| |
| getValueAsInteger | back to summary |
|---|---|
| public int getValueAsInteger() throws ConfigurationException Return the
| |
| getValueAsInteger | back to summary |
|---|---|
| public int getValueAsInteger(int defaultValue) Returns the value of the configuration element as an
| |
| getValueAsLong | back to summary |
|---|---|
| public long getValueAsLong() throws ConfigurationException Return the
| |
| getValueAsLong | back to summary |
|---|---|
| public long getValueAsLong(long defaultValue) Returns the value of the configuration element as a
| |