## org.apache.commons.configuration.tree
Class DefaultConfigurationNode

    java.lang.Object
      org.apache.commons.configuration.tree.DefaultConfigurationNode

All Implemented Interfaces:
  Cloneable, ConfigurationNode

Direct Known Subclasses:
  HierarchicalConfiguration.Node, ViewNode

    public class DefaultConfigurationNode

extends Object
implements ConfigurationNode, Cloneable

A default implementation of the `ConfigurationNode` interface.

Since:
  1.3
Version:
  $Id: DefaultConfigurationNode.java 1206314 2011-11-25 20:50:51Z oheger $
Author:
  Commons Configuration team

Nested Class Summary
`protected static class` `DefaultConfigurationNode.SubNodes` An internally used helper class for managing a collection of sub nodes.

Constructor Summary
`DefaultConfigurationNode()` Creates a new uninitialized instance of `DefaultConfigurationNode`.
`DefaultConfigurationNode(String name)` Creates a new instance of `DefaultConfigurationNode` and initializes it with the node name.
`DefaultConfigurationNode(String name, Object value)` Creates a new instance of `DefaultConfigurationNode` and initializes it with the name and a value.

Method Summary
`void` `addAttribute(ConfigurationNode attr)` Adds the specified attribute to this node.
`void` `addChild(ConfigurationNode child)` Adds a new child to this node.
`protected void` `checkState()` Checks if a modification of this node is allowed.
`Object` `clone()` Creates a copy of this object.
`protected DefaultConfigurationNode.SubNodes` `createSubNodes(boolean attributes)` Creates a `SubNodes` instance that is used for storing either this node's children or attributes.
`ConfigurationNode` `getAttribute(int index)` Returns the attribute with the given index.
`int` `getAttributeCount()` Returns the number of attributes contained in this node.
`int` `getAttributeCount(String name)` Returns the number of attributes of this node with the given name.
`List<ConfigurationNode>` `getAttributes()` Returns a list with the attributes of this node.
`List<ConfigurationNode>` `getAttributes(String name)` Returns a list with all attributes of this node with the given name.
`ConfigurationNode` `getChild(int index)` Returns the child node with the given index.
`List<ConfigurationNode>` `getChildren()` Returns a list with all children of this node.
`List<ConfigurationNode>` `getChildren(String name)` Returns a list of all children with the given name.
`int` `getChildrenCount()` Returns the number of all children of this node.
`int` `getChildrenCount(String name)` Returns the number of children with the given name.
`String` `getName()` Returns the name of this node.
`ConfigurationNode` `getParentNode()` Returns a reference to this node's parent.
`Object` `getReference()` Returns the reference.
`Object` `getValue()` Returns the value of this node.
`boolean` `isAttribute()` Checks if this node is an attribute node.
`boolean` `isDefined()` Returns a flag if this node is defined.
`boolean` `removeAttribute(ConfigurationNode node)` Removes the specified attribute.
`boolean` `removeAttribute(String name)` Removes all attributes with the specified name.
`void` `removeAttributes()` Removes all attributes of this node.
`boolean` `removeChild(ConfigurationNode child)` Removes the specified child node from this node.
`boolean` `removeChild(String childName)` Removes all children with the given name.
`void` `removeChildren()` Removes all child nodes of this node.
`protected void` `removeReference()` Deals with the reference when a node is removed.
`void` `setAttribute(boolean f)` Sets the attribute flag.
`void` `setName(String name)` Sets the name of this node.
`void` `setParentNode(ConfigurationNode parent)` Sets the parent of this node.
`void` `setReference(Object reference)` Sets the reference.
`void` `setValue(Object val)` Sets the value of this node.
`void` `visit(ConfigurationNodeVisitor visitor)` Visits this node and all its sub nodes.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DefaultConfigurationNode

    public DefaultConfigurationNode()

  Creates a new uninitialized instance of `DefaultConfigurationNode`.

### DefaultConfigurationNode

    public DefaultConfigurationNode(String name)

  Creates a new instance of `DefaultConfigurationNode` and initializes it with the node name.

  Parameters:
    `name` - the name of this node

### DefaultConfigurationNode

    public DefaultConfigurationNode(String name,
                                    Object value)

  Creates a new instance of `DefaultConfigurationNode` and initializes it with the name and a value.

  Parameters:
    `name` - the node's name
    `value` - the node's value

Method Detail

### getName

    public String getName()

  Returns the name of this node.

  Specified by:
    `getName` in interface `ConfigurationNode`
  Returns:
    the name of this node

### setName

    public void setName(String name)

  Sets the name of this node.

  Specified by:
    `setName` in interface `ConfigurationNode`
  Parameters:
    `name` - the new name

### getValue

    public Object getValue()

  Returns the value of this node.

  Specified by:
    `getValue` in interface `ConfigurationNode`
  Returns:
    the value of this node

### setValue

    public void setValue(Object val)

  Sets the value of this node.

  Specified by:
    `setValue` in interface `ConfigurationNode`
  Parameters:
    `val` - the value of this node

### getReference

    public Object getReference()

  Returns the reference.

  Specified by:
    `getReference` in interface `ConfigurationNode`
  Returns:
    the reference

### setReference

    public void setReference(Object reference)

  Sets the reference.

  Specified by:
    `setReference` in interface `ConfigurationNode`
  Parameters:
    `reference` - the reference object

### getParentNode

    public ConfigurationNode getParentNode()

  Returns a reference to this node's parent.

  Specified by:
    `getParentNode` in interface `ConfigurationNode`
  Returns:
    the parent node or null if this is the root

### setParentNode

    public void setParentNode(ConfigurationNode parent)

  Sets the parent of this node.

  Specified by:
    `setParentNode` in interface `ConfigurationNode`
  Parameters:
    `parent` - the parent of this node

### addChild

    public void addChild(ConfigurationNode child)

  Adds a new child to this node.

  Specified by:
    `addChild` in interface `ConfigurationNode`
  Parameters:
    `child` - the new child

### getChildren

    public List<ConfigurationNode> getChildren()

  Returns a list with all children of this node.

  Specified by:
    `getChildren` in interface `ConfigurationNode`
  Returns:
    a list with all child nodes

### getChildrenCount

    public int getChildrenCount()

  Returns the number of all children of this node.

  Specified by:
    `getChildrenCount` in interface `ConfigurationNode`
  Returns:
    the number of all children

### getChildren

    public List<ConfigurationNode> getChildren(String name)

  Returns a list of all children with the given name.

  Specified by:
    `getChildren` in interface `ConfigurationNode`
  Parameters:
    `name` - the name; can be null , then all children are returned
  Returns:
    a list of all children with the given name

### getChildrenCount

    public int getChildrenCount(String name)

  Returns the number of children with the given name.

  Specified by:
    `getChildrenCount` in interface `ConfigurationNode`
  Parameters:
    `name` - the name; can be null , then the number of all children is returned
  Returns:
    the number of child nodes with this name

### getChild

    public ConfigurationNode getChild(int index)

  Returns the child node with the given index.

  Specified by:
    `getChild` in interface `ConfigurationNode`
  Parameters:
    `index` - the index (0-based)
  Returns:
    the child with this index

### removeChild

    public boolean removeChild(ConfigurationNode child)

  Removes the specified child node from this node.

  Specified by:
    `removeChild` in interface `ConfigurationNode`
  Parameters:
    `child` - the node to be removed
  Returns:
    a flag if a node was removed

### removeChild

    public boolean removeChild(String childName)

  Removes all children with the given name.

  Specified by:
    `removeChild` in interface `ConfigurationNode`
  Parameters:
    `childName` - the name of the children to be removed
  Returns:
    a flag if at least one child node was removed

### removeChildren

    public void removeChildren()

  Removes all child nodes of this node.

  Specified by:
    `removeChildren` in interface `ConfigurationNode`

### isAttribute

    public boolean isAttribute()

  Checks if this node is an attribute node.

  Specified by:
    `isAttribute` in interface `ConfigurationNode`
  Returns:
    a flag if this is an attribute node

### setAttribute

    public void setAttribute(boolean f)

  Sets the attribute flag. Note: this method can only be called if the node is not already part of a node hierarchy.

  Specified by:
    `setAttribute` in interface `ConfigurationNode`
  Parameters:
    `f` - the attribute flag

### addAttribute

    public void addAttribute(ConfigurationNode attr)

  Adds the specified attribute to this node.

  Specified by:
    `addAttribute` in interface `ConfigurationNode`
  Parameters:
    `attr` - the attribute to be added

### getAttributes

    public List<ConfigurationNode> getAttributes()

  Returns a list with the attributes of this node. This list contains `DefaultConfigurationNode` objects, too.

  Specified by:
    `getAttributes` in interface `ConfigurationNode`
  Returns:
    the attribute list, never null

### getAttributeCount

    public int getAttributeCount()

  Returns the number of attributes contained in this node.

  Specified by:
    `getAttributeCount` in interface `ConfigurationNode`
  Returns:
    the number of attributes

### getAttributes

    public List<ConfigurationNode> getAttributes(String name)

  Returns a list with all attributes of this node with the given name.

  Specified by:
    `getAttributes` in interface `ConfigurationNode`
  Parameters:
    `name` - the attribute's name
  Returns:
    all attributes with this name

### getAttributeCount

    public int getAttributeCount(String name)

  Returns the number of attributes of this node with the given name.

  Specified by:
    `getAttributeCount` in interface `ConfigurationNode`
  Parameters:
    `name` - the name
  Returns:
    the number of attributes with this name

### removeAttribute

    public boolean removeAttribute(ConfigurationNode node)

  Removes the specified attribute.

  Specified by:
    `removeAttribute` in interface `ConfigurationNode`
  Parameters:
    `node` - the attribute node to be removed
  Returns:
    a flag if the attribute could be removed

### removeAttribute

    public boolean removeAttribute(String name)

  Removes all attributes with the specified name.

  Specified by:
    `removeAttribute` in interface `ConfigurationNode`
  Parameters:
    `name` - the name
  Returns:
    a flag if at least one attribute was removed

### getAttribute

    public ConfigurationNode getAttribute(int index)

  Returns the attribute with the given index.

  Specified by:
    `getAttribute` in interface `ConfigurationNode`
  Parameters:
    `index` - the index (0-based)
  Returns:
    the attribute with this index

### removeAttributes

    public void removeAttributes()

  Removes all attributes of this node.

  Specified by:
    `removeAttributes` in interface `ConfigurationNode`

### isDefined

    public boolean isDefined()

  Returns a flag if this node is defined. This means that the node contains some data.

  Specified by:
    `isDefined` in interface `ConfigurationNode`
  Returns:
    a flag whether this node is defined

### visit

    public void visit(ConfigurationNodeVisitor visitor)

  Visits this node and all its sub nodes.

  Specified by:
    `visit` in interface `ConfigurationNode`
  Parameters:
    `visitor` - the visitor
  See Also:
    `ConfigurationNodeVisitor`

### clone

    public Object clone()

  Creates a copy of this object. This is not a deep copy, the children are not cloned.

  Specified by:
    `clone` in interface `ConfigurationNode`
  Overrides:
    `clone` in class `Object`
  Returns:
    a copy of this object

### checkState

    protected void checkState()

  Checks if a modification of this node is allowed. Some properties of a node must not be changed when the node has a parent. This method checks this and throws a runtime exception if necessary.

### createSubNodes

    protected DefaultConfigurationNode.SubNodes createSubNodes(boolean attributes)

  Creates a `SubNodes` instance that is used for storing either this node's children or attributes.

  Parameters:
    `attributes` - true if the returned instance is used for storing attributes, false for storing child nodes
  Returns:
    the `SubNodes` object to use

### removeReference

    protected void removeReference()

  Deals with the reference when a node is removed. This method is called for each removed child node or attribute. 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-2012 The Apache Software Foundation. All Rights Reserved.