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 {@link DefaultConfigurationBuilder#DefaultConfigurationBuilder(boolean) newDefaultConfigurationBuilder(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 {@link 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. {@link #getName getName}() | my-system |
conf. {@link #getAttributeNames getAttributeNames}().length | 2 | 1 |
conf. {@link #getChildren getChildren}().length | 2 |
conf. {@link #getAttributeAsFloat getAttributeAsFloat}("version") | 1.3 |
conf. {@link #getChild getChild}("widget"). {@link #getAttribute getAttribute}("name") | fooWidget |
conf. {@link #getChild getChild}("widget") . {@link #getAttributeAsBoolean getAttributeAsBoolean}("threadsafe") | true |
conf. {@link #getChild getChild}("widget"). {@link #getLocation getLocation}() | file:///home/jeff/tmp/java/avalon/src/java/new.xconf:4:60 |
conf. {@link #getChild getChild}("desc"). {@link #getName getName}() | desc (see {@link #getChild(String)}) | desc |
conf. {@link #getChild getChild}("doc:desc"). {@link #getName getName}() | doc:desc | doc:desc (see {@link #getChild(String)}) |
conf. {@link #getChild getChild}("desc"). {@link #getValue getValue}() | {@link ConfigurationException} | This is a highly fictitious config file |
conf. {@link #getChild getChild}("doc:desc"). {@link #getValue getValue}() | This is a highly fictitious config file | {@link ConfigurationException} |
conf. {@link #getChild getChild}("desc"). {@link #getNamespace getNamespace}() | | http://myco.com/documentation" |
Type-safe utility methods are provided for retrieving attribute and element values as String
, int
, long
, float
and boolean
.
Miscellanea
Currently, the configuration tree can only be traversed one node at a time, eg., through {@link #getChild getChild("foo")} or {@link #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. }
@author
Avalon Development Team
@version CVS $Revision: 1.29 $ $Date: 2004/02/11 14:34:24 $