org.apache.commons.configuration
Class HierarchicalDOM4JConfiguration

java.lang.Object
  extended byorg.apache.commons.configuration.AbstractConfiguration
      extended byorg.apache.commons.configuration.HierarchicalConfiguration
          extended byorg.apache.commons.configuration.HierarchicalDOM4JConfiguration
All Implemented Interfaces:
BasePathLoader, Configuration

public class HierarchicalDOM4JConfiguration
extends HierarchicalConfiguration
implements BasePathLoader

A specialized hierarchical configuration class that is able to parse XML documents using DOM4J.

The parsed document will be stored keeping its structure. The contained properties can be accessed using all methods supported by the base class HierarchicalProperties.

Version:
$Id: HierarchicalDOM4JConfiguration.java,v 1.1.1.1 2003/12/23 15:09:05 epugh Exp $
Author:
Oliver Heger

Nested Class Summary
 
Nested classes inherited from class org.apache.commons.configuration.HierarchicalConfiguration
HierarchicalConfiguration.CloneVisitor, HierarchicalConfiguration.DefinedKeysVisitor, HierarchicalConfiguration.DefinedVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor
 
Nested classes inherited from class org.apache.commons.configuration.AbstractConfiguration
AbstractConfiguration.Container, AbstractConfiguration.PropertiesTokenizer
 
Field Summary
private  java.lang.String basePath
          Stores the base path of this configuration.
private  java.lang.String file
          Stores the file name of the document to be parsed.
 
Fields inherited from class org.apache.commons.configuration.HierarchicalConfiguration
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
defaults, END_TOKEN, START_TOKEN
 
Constructor Summary
HierarchicalDOM4JConfiguration()
          Creates a new instance of HierarchicalDOM4JConfiguration.
HierarchicalDOM4JConfiguration(Configuration defaults)
          Creates a new instance of HierarchicalDOM4JConfiguration and sets the default properties.
 
Method Summary
private  void constructHierarchy(HierarchicalConfiguration.Node node, org.dom4j.Element element)
          Helper method for building the internal storage hierarchy.
 java.lang.String getBasePath()
          Returns the base path.
 java.lang.String getFileName()
          Returns the name of the file to be parsed by this object.
 void initProperties(org.dom4j.Document document)
          Initializes this configuration from an XML document.
 void load()
          Loads and parses an XML document.
 void load(java.net.URL url)
          Loads and parses the specified XML document.
private  void processAttributes(HierarchicalConfiguration.Node node, org.dom4j.Element element)
          Helper method for constructing node objects for the attributes of the given XML element.
 void setBasePath(java.lang.String path)
          Allows to set a base path.
 void setFileName(java.lang.String file)
          Sets the name of the file to be parsed by this object.
 
Methods inherited from class org.apache.commons.configuration.HierarchicalConfiguration
addNodes, addPropertyDirect, clearProperty, containsKey, createAddPath, fetchAddNode, fetchNodeList, findLastPathNode, findPropertyNodes, getKeys, getMaxIndex, getPropertyDirect, getRoot, isEmpty, nodeDefined, removeNode, setRoot, subset
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addProperty, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, processString, setProperty, testBoolean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

private java.lang.String file
Stores the file name of the document to be parsed.


basePath

private java.lang.String basePath
Stores the base path of this configuration.

Constructor Detail

HierarchicalDOM4JConfiguration

public HierarchicalDOM4JConfiguration()
Creates a new instance of HierarchicalDOM4JConfiguration.


HierarchicalDOM4JConfiguration

public HierarchicalDOM4JConfiguration(Configuration defaults)
Creates a new instance of HierarchicalDOM4JConfiguration and sets the default properties.

Parameters:
defaults - the default properties
Method Detail

getFileName

public java.lang.String getFileName()
Returns the name of the file to be parsed by this object.

Returns:
the file to be parsed

setFileName

public void setFileName(java.lang.String file)
Sets the name of the file to be parsed by this object.

Parameters:
file - the file to be parsed

getBasePath

public java.lang.String getBasePath()
Returns the base path.

Specified by:
getBasePath in interface BasePathLoader
Returns:
the base path

setBasePath

public void setBasePath(java.lang.String path)
Allows to set a base path. Relative file names are resolved based on this path.

Specified by:
setBasePath in interface BasePathLoader
Parameters:
path - the base path; this can be a URL or a file path

load

public void load()
          throws java.lang.Exception
Loads and parses an XML document. The file to be loaded must have been specified before.

Throws:
java.lang.Exception - if an error occurs

load

public void load(java.net.URL url)
          throws java.lang.Exception
Loads and parses the specified XML document.

Parameters:
url - the URL to the XML document
Throws:
java.lang.Exception - if an error occurs

initProperties

public void initProperties(org.dom4j.Document document)
Initializes this configuration from an XML document.

Parameters:
document - the document to be parsed

constructHierarchy

private void constructHierarchy(HierarchicalConfiguration.Node node,
                                org.dom4j.Element element)
Helper method for building the internal storage hierarchy. The XML elements are transformed into node objects.

Parameters:
node - the actual node
element - the actual XML element

processAttributes

private void processAttributes(HierarchicalConfiguration.Node node,
                               org.dom4j.Element element)
Helper method for constructing node objects for the attributes of the given XML element.

Parameters:
node - the actual node
element - the actual XML element