org.apache.commons.configuration
Class HierarchicalConfiguration.Node

java.lang.Object
  |
  +--org.apache.commons.configuration.HierarchicalConfiguration.Node
All Implemented Interfaces:
Cloneable, Serializable
Direct Known Subclasses:
XMLPropertyListConfiguration.PListNode
Enclosing class:
HierarchicalConfiguration

public static class HierarchicalConfiguration.Node
extends Object
implements Serializable, Cloneable

A data class for storing (hierarchical) property information. A property can have a value and an arbitrary number of child properties.

See Also:
Serialized Form

Constructor Summary
HierarchicalConfiguration.Node()
          Creates a new instance of Node.
HierarchicalConfiguration.Node(String name)
          Creates a new instance of Node and sets the name.
HierarchicalConfiguration.Node(String name, Object value)
          Creates a new instance of Node and sets the name and the value.
 
Method Summary
 void addChild(HierarchicalConfiguration.Node child)
          Adds the specified child object to this node.
 Object clone()
          Creates a copy of this object.
 List getChildren()
          Returns a list with the child nodes of this node.
 List getChildren(String name)
          Returns a list with this node's children with the given name.
 String getName()
          Returns the name of this node.
 HierarchicalConfiguration.Node getParent()
          Returns the parent of this node.
 Object getReference()
          Returns the reference object for this node.
 Object getValue()
          Returns the value of this node.
 boolean hasChildren()
          Returns a flag whether this node has child elements.
 boolean remove(HierarchicalConfiguration.Node child)
          Removes the specified child from this node.
 boolean remove(String name)
          Removes all children with the given name.
 void removeChildren()
          Removes all children of this node.
protected  void removeReference()
          Deals with the reference when a node is removed.
 void setName(String string)
          Sets the name of this node.
 void setParent(HierarchicalConfiguration.Node node)
          Sets the parent of this node.
 void setReference(Object ref)
          Sets the reference object for this node.
 void setValue(Object object)
          Sets the value of this node.
 void visit(HierarchicalConfiguration.NodeVisitor visitor, ConfigurationKey key)
          A generic method for traversing this node and all of its children.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HierarchicalConfiguration.Node

public HierarchicalConfiguration.Node()
Creates a new instance of Node.

HierarchicalConfiguration.Node

public HierarchicalConfiguration.Node(String name)
Creates a new instance of Node and sets the name.
Parameters:
name - the node's name

HierarchicalConfiguration.Node

public HierarchicalConfiguration.Node(String name,
                                      Object value)
Creates a new instance of Node and sets the name and the value.
Parameters:
name - the node's name
value - the value
Method Detail

getName

public String getName()
Returns the name of this node.
Returns:
the node name

getValue

public Object getValue()
Returns the value of this node.
Returns:
the node value (may be null )

getParent

public HierarchicalConfiguration.Node getParent()
Returns the parent of this node.
Returns:
this node's parent (can be null )

setName

public void setName(String string)
Sets the name of this node.
Parameters:
string - the node name

setValue

public void setValue(Object object)
Sets the value of this node.
Parameters:
object - the node value

setParent

public void setParent(HierarchicalConfiguration.Node node)
Sets the parent of this node.
Parameters:
node - the parent node

getReference

public Object getReference()
Returns the reference object for this node.
Returns:
the reference object

setReference

public void setReference(Object ref)
Sets the reference object for this node. A node can be associated with a reference object whose concrete meaning is determined by a sub class of HierarchicalConfiguration. In an XML configuration e.g. this reference could be an element in a corresponding XML document. The reference is used by the BuilderVisitor class when the configuration is stored.
Parameters:
ref - the reference object

addChild

public void addChild(HierarchicalConfiguration.Node child)
Adds the specified child object to this node. Note that there can be multiple children with the same name.
Parameters:
child - the child to be added

getChildren

public List getChildren()
Returns a list with the child nodes of this node.
Returns:
a list with the children (can be empty, but never null )

getChildren

public List getChildren(String name)
Returns a list with this node's children with the given name.
Parameters:
name - the name of the children
Returns:
a list with all chidren with this name; may be empty, but never null

hasChildren

public boolean hasChildren()
Returns a flag whether this node has child elements.
Returns:
true if there a child node, false otherwise

remove

public boolean remove(HierarchicalConfiguration.Node child)
Removes the specified child from this node.
Parameters:
child - the child node to be removed
Returns:
a flag if the child could be found

remove

public boolean remove(String name)
Removes all children with the given name.
Parameters:
name - the name of the children to be removed
Returns:
a flag if children with this name existed

removeChildren

public void removeChildren()
Removes all children of this node.

visit

public void visit(HierarchicalConfiguration.NodeVisitor visitor,
                  ConfigurationKey key)
A generic method for traversing this node and all of its children. This method sends the passed in visitor to this node and all of its children.
Parameters:
visitor - the visitor
key - here a configuration key with the name of the root node of the iteration can be passed; if this key is not null , the full pathes to the visited nodes are builded and passed to the visitor's visit() methods

clone

public Object clone()
Creates a copy of this object. This is not a deep copy, the children are not cloned.
Overrides:
clone in class Object
Returns:
a copy of this object

removeReference

protected void removeReference()
Deals with the reference when a node is removed. This method is called for each removed child node. It can be overloaded in sub classes, for which the reference has a concrete meaning and remove operations need some update actions. This default implementation is empty.


Copyright © 2001-2005 The Apache Software Foundation. All Rights Reserved.