Class DefaultConfigurationNode
java.lang.Object
org.apache.commons.configuration.tree.DefaultConfigurationNode
- All Implemented Interfaces:
Cloneable
,ConfigurationNode
- Direct Known Subclasses:
HierarchicalConfiguration.Node
,ViewNode
A default implementation of the ConfigurationNode
interface.
- Since:
- 1.3
- Version:
- $Id: DefaultConfigurationNode.java 1301991 2012-03-17 20:18:02Z sebb $
- Author:
- Commons Configuration team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
An internally used helper class for managing a collection of sub nodes. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new uninitialized instance ofDefaultConfigurationNode
.Creates a new instance ofDefaultConfigurationNode
and initializes it with the node name.DefaultConfigurationNode
(String name, Object value) Creates a new instance ofDefaultConfigurationNode
and initializes it with the name and a value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the specified attribute to this node.void
addChild
(ConfigurationNode child) Adds a new child to this node.protected void
Checks if a modification of this node is allowed.clone()
Creates a copy of this object.protected DefaultConfigurationNode.SubNodes
createSubNodes
(boolean attributes) Creates aSubNodes
instance that is used for storing either this node's children or attributes.getAttribute
(int index) Returns the attribute with the given index.int
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.Returns a list with the attributes of this node.getAttributes
(String name) Returns a list with all attributes of this node with the given name.getChild
(int index) Returns the child node with the given index.Returns a list with all children of this node.getChildren
(String name) Returns a list of all children with the given name.int
Returns the number of all children of this node.int
getChildrenCount
(String name) Returns the number of children with the given name.getName()
Returns the name of this node.Returns a reference to this node's parent.Returns the reference.getValue()
Returns the value of this node.boolean
Checks if this node is an attribute node.boolean
Returns a flag if this node is defined.boolean
removeAttribute
(String name) Removes all attributes with the specified name.boolean
Removes the specified attribute.void
Removes all attributes of this node.boolean
removeChild
(String childName) Removes all children with the given name.boolean
removeChild
(ConfigurationNode child) Removes the specified child node from this node.void
Removes all child nodes of this node.protected void
Deals with the reference when a node is removed.void
setAttribute
(boolean f) Sets the attribute flag.void
Sets the name of this node.void
setParentNode
(ConfigurationNode parent) Sets the parent of this node.void
setReference
(Object reference) Sets the reference.void
Sets the value of this node.void
visit
(ConfigurationNodeVisitor visitor) Visits this node and all its sub nodes.
-
Constructor Details
-
DefaultConfigurationNode
public DefaultConfigurationNode()Creates a new uninitialized instance ofDefaultConfigurationNode
. -
DefaultConfigurationNode
Creates a new instance ofDefaultConfigurationNode
and initializes it with the node name.- Parameters:
name
- the name of this node
-
DefaultConfigurationNode
Creates a new instance ofDefaultConfigurationNode
and initializes it with the name and a value.- Parameters:
name
- the node's namevalue
- the node's value
-
-
Method Details
-
getName
Returns the name of this node.- Specified by:
getName
in interfaceConfigurationNode
- Returns:
- the name of this node
-
setName
Sets the name of this node.- Specified by:
setName
in interfaceConfigurationNode
- Parameters:
name
- the new name
-
getValue
Returns the value of this node.- Specified by:
getValue
in interfaceConfigurationNode
- Returns:
- the value of this node
-
setValue
Sets the value of this node.- Specified by:
setValue
in interfaceConfigurationNode
- Parameters:
val
- the value of this node
-
getReference
Returns the reference.- Specified by:
getReference
in interfaceConfigurationNode
- Returns:
- the reference
-
setReference
Sets the reference.- Specified by:
setReference
in interfaceConfigurationNode
- Parameters:
reference
- the reference object
-
getParentNode
Returns a reference to this node's parent.- Specified by:
getParentNode
in interfaceConfigurationNode
- Returns:
- the parent node or null if this is the root
-
setParentNode
Sets the parent of this node.- Specified by:
setParentNode
in interfaceConfigurationNode
- Parameters:
parent
- the parent of this node
-
addChild
Adds a new child to this node.- Specified by:
addChild
in interfaceConfigurationNode
- Parameters:
child
- the new child
-
getChildren
Returns a list with all children of this node.- Specified by:
getChildren
in interfaceConfigurationNode
- Returns:
- a list with all child nodes
-
getChildrenCount
Returns the number of all children of this node.- Specified by:
getChildrenCount
in interfaceConfigurationNode
- Returns:
- the number of all children
-
getChildren
Returns a list of all children with the given name.- Specified by:
getChildren
in interfaceConfigurationNode
- Parameters:
name
- the name; can be null , then all children are returned- Returns:
- a list of all children with the given name
-
getChildrenCount
Returns the number of children with the given name.- Specified by:
getChildrenCount
in interfaceConfigurationNode
- 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
Returns the child node with the given index.- Specified by:
getChild
in interfaceConfigurationNode
- Parameters:
index
- the index (0-based)- Returns:
- the child with this index
-
removeChild
Removes the specified child node from this node.- Specified by:
removeChild
in interfaceConfigurationNode
- Parameters:
child
- the node to be removed- Returns:
- a flag if a node was removed
-
removeChild
Removes all children with the given name.- Specified by:
removeChild
in interfaceConfigurationNode
- Parameters:
childName
- the name of the children to be removed- Returns:
- a flag if at least one child node was removed
-
removeChildren
Removes all child nodes of this node.- Specified by:
removeChildren
in interfaceConfigurationNode
-
isAttribute
Checks if this node is an attribute node.- Specified by:
isAttribute
in interfaceConfigurationNode
- Returns:
- a flag if this is an attribute node
-
setAttribute
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 interfaceConfigurationNode
- Parameters:
f
- the attribute flag
-
addAttribute
Adds the specified attribute to this node.- Specified by:
addAttribute
in interfaceConfigurationNode
- Parameters:
attr
- the attribute to be added
-
getAttributes
Returns a list with the attributes of this node. This list containsDefaultConfigurationNode
objects, too.- Specified by:
getAttributes
in interfaceConfigurationNode
- Returns:
- the attribute list, never null
-
getAttributeCount
Returns the number of attributes contained in this node.- Specified by:
getAttributeCount
in interfaceConfigurationNode
- Returns:
- the number of attributes
-
getAttributes
Returns a list with all attributes of this node with the given name.- Specified by:
getAttributes
in interfaceConfigurationNode
- Parameters:
name
- the attribute's name- Returns:
- all attributes with this name
-
getAttributeCount
Returns the number of attributes of this node with the given name.- Specified by:
getAttributeCount
in interfaceConfigurationNode
- Parameters:
name
- the name- Returns:
- the number of attributes with this name
-
removeAttribute
Removes the specified attribute.- Specified by:
removeAttribute
in interfaceConfigurationNode
- Parameters:
node
- the attribute node to be removed- Returns:
- a flag if the attribute could be removed
-
removeAttribute
Removes all attributes with the specified name.- Specified by:
removeAttribute
in interfaceConfigurationNode
- Parameters:
name
- the name- Returns:
- a flag if at least one attribute was removed
-
getAttribute
Returns the attribute with the given index.- Specified by:
getAttribute
in interfaceConfigurationNode
- Parameters:
index
- the index (0-based)- Returns:
- the attribute with this index
-
removeAttributes
Removes all attributes of this node.- Specified by:
removeAttributes
in interfaceConfigurationNode
-
isDefined
Returns a flag if this node is defined. This means that the node contains some data.- Specified by:
isDefined
in interfaceConfigurationNode
- Returns:
- a flag whether this node is defined
-
visit
Visits this node and all its sub nodes.- Specified by:
visit
in interfaceConfigurationNode
- Parameters:
visitor
- the visitor- See Also:
-
clone
Creates a copy of this object. This is not a deep copy, the children are not cloned.- Specified by:
clone
in interfaceConfigurationNode
- Overrides:
clone
in classObject
- Returns:
- a copy of this object
-
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
Creates aSubNodes
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
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.
-