You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/09/18 22:07:30 UTC
svn commit: r1387339 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/
main/java/org/apache/commons/configuration/plist/ main/javacc/
test/java/org/apache/commons/configuration/
test/java/org/apache/commons/confi...
Author: oheger
Date: Tue Sep 18 20:07:29 2012
New Revision: 1387339
URL: http://svn.apache.org/viewvc?rev=1387339&view=rev
Log:
[CONFIGURATION-506] Removed obsolete HierarchicalConfiguration.Node and NodeVisitor classes.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationFactory.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
commons/proper/configuration/trunk/src/main/javacc/PropertyListParser.jj
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationFactory.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationFactory.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationFactory.java Tue Sep 18 20:07:29 2012
@@ -27,6 +27,7 @@ import java.util.Map;
import org.apache.commons.configuration.plist.PropertyListConfiguration;
import org.apache.commons.configuration.plist.XMLPropertyListConfiguration;
+import org.apache.commons.configuration.tree.ConfigurationNode;
import org.apache.commons.digester.AbstractObjectCreationFactory;
import org.apache.commons.digester.CallMethodRule;
import org.apache.commons.digester.Digester;
@@ -816,19 +817,19 @@ public class ConfigurationFactory
* @param cdata the configuration data object
* @return a root node for this configuration
*/
- private HierarchicalConfiguration.Node createRootNode(AdditionalConfigurationData cdata)
+ private ConfigurationNode createRootNode(AdditionalConfigurationData cdata)
{
if (cdata.getConfiguration() instanceof HierarchicalConfiguration)
{
// we can directly use this configuration's root node
- return ((HierarchicalConfiguration) cdata.getConfiguration()).getRoot();
+ return ((HierarchicalConfiguration) cdata.getConfiguration()).getRootNode();
}
else
{
// transform configuration to a hierarchical root node
HierarchicalConfiguration hc = new HierarchicalConfiguration();
ConfigurationUtils.copy(cdata.getConfiguration(), hc);
- return hc.getRoot();
+ return hc.getRootNode();
}
}
}
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java Tue Sep 18 20:07:29 2012
@@ -580,25 +580,6 @@ public class DynamicCombinedConfiguratio
}
@Override
- public Node getRoot()
- {
- return this.getCurrentConfig().getRoot();
- }
-
- @Override
- public void setRoot(Node node)
- {
- if (configs != null)
- {
- this.getCurrentConfig().setRoot(node);
- }
- else
- {
- super.setRoot(node);
- }
- }
-
- @Override
public ExpressionEngine getExpressionEngine()
{
return super.getExpressionEngine();
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java Tue Sep 18 20:07:29 2012
@@ -36,8 +36,6 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.tree.DefaultExpressionEngine;
import org.apache.commons.configuration.tree.ExpressionEngine;
import org.apache.commons.configuration.tree.NodeAddData;
-import org.apache.commons.configuration.tree.ViewNode;
-import org.apache.commons.lang.StringUtils;
/**
* <p>A specialized configuration class that extends its base class by the
@@ -154,11 +152,6 @@ public class HierarchicalConfiguration e
/** Stores the default expression engine to be used for new objects.*/
private static ExpressionEngine defaultExpressionEngine;
- /** Stores the root node of this configuration. This field is required for
- * backwards compatibility only.
- */
- private Node root;
-
/** Stores the root configuration node.*/
private ConfigurationNode rootNode;
@@ -170,7 +163,7 @@ public class HierarchicalConfiguration e
*/
public HierarchicalConfiguration()
{
- setRootNode(new Node());
+ setRootNode(new DefaultConfigurationNode());
}
/**
@@ -205,43 +198,6 @@ public class HierarchicalConfiguration e
}
/**
- * Returns the root node of this hierarchical configuration. This method
- * exists for backwards compatibility only. New code should use the
- * {@link #getRootNode()} method instead, which operates on
- * the preferred data type {@code ConfigurationNode}.
- *
- * @return the root node
- */
- public Node getRoot()
- {
- if (root == null && rootNode != null)
- {
- // Dynamically create a snapshot of the root node
- return new Node(rootNode);
- }
-
- return root;
- }
-
- /**
- * Sets the root node of this hierarchical configuration. This method
- * exists for backwards compatibility only. New code should use the
- * {@link #setRootNode(ConfigurationNode)} method instead,
- * which operates on the preferred data type {@code ConfigurationNode}.
- *
- * @param node the root node
- */
- public void setRoot(Node node)
- {
- if (node == null)
- {
- throw new IllegalArgumentException("Root node must not be null!");
- }
- root = node;
- rootNode = null;
- }
-
- /**
* Returns the root node of this hierarchical configuration.
*
* @return the root node
@@ -249,7 +205,7 @@ public class HierarchicalConfiguration e
*/
public ConfigurationNode getRootNode()
{
- return (rootNode != null) ? rootNode : root;
+ return rootNode;
}
/**
@@ -265,9 +221,6 @@ public class HierarchicalConfiguration e
throw new IllegalArgumentException("Root node must not be null!");
}
this.rootNode = rootNode;
-
- // For backward compatibility also set the old root field.
- root = (rootNode instanceof Node) ? (Node) rootNode : null;
}
/**
@@ -959,39 +912,6 @@ public class HierarchicalConfiguration e
}
/**
- * Recursive helper method for fetching a property. This method processes
- * all facets of a configuration key, traverses the tree of properties and
- * fetches the the nodes of all matching properties.
- *
- * @param keyPart the configuration key iterator
- * @param node the actual node
- * @param nodes here the found nodes are stored
- * @deprecated Property keys are now evaluated by the expression engine
- * associated with the configuration; this method will no longer be called.
- * If you want to modify the way properties are looked up, consider
- * implementing you own {@code ExpressionEngine} implementation.
- */
- @Deprecated
- protected void findPropertyNodes(ConfigurationKey.KeyIterator keyPart,
- Node node, Collection<ConfigurationNode> nodes)
- {
- }
-
- /**
- * Checks if the specified node is defined.
- *
- * @param node the node to be checked
- * @return a flag if this node is defined
- * @deprecated Use the method {@link #nodeDefined(ConfigurationNode)}
- * instead.
- */
- @Deprecated
- protected boolean nodeDefined(Node node)
- {
- return nodeDefined((ConfigurationNode) node);
- }
-
- /**
* Checks if the specified node is defined.
*
* @param node the node to be checked
@@ -1010,21 +930,6 @@ public class HierarchicalConfiguration e
* removed.
*
* @param node the node to be removed
- * @deprecated Use the method {@link #removeNode(ConfigurationNode)}
- * instead.
- */
- @Deprecated
- protected void removeNode(Node node)
- {
- removeNode((ConfigurationNode) node);
- }
-
- /**
- * Removes the specified node from this configuration. This method ensures
- * that parent nodes that become undefined by this operation are also
- * removed.
- *
- * @param node the node to be removed
*/
protected void removeNode(ConfigurationNode node)
{
@@ -1044,20 +949,6 @@ public class HierarchicalConfiguration e
* this operation, it is removed from the hierarchy.
*
* @param node the node to be cleared
- * @deprecated Use the method {@link #clearNode(ConfigurationNode)}
- * instead
- */
- @Deprecated
- protected void clearNode(Node node)
- {
- clearNode((ConfigurationNode) node);
- }
-
- /**
- * Clears the value of the specified node. If the node becomes undefined by
- * this operation, it is removed from the hierarchy.
- *
- * @param node the node to be cleared
*/
protected void clearNode(ConfigurationNode node)
{
@@ -1069,77 +960,17 @@ public class HierarchicalConfiguration e
}
/**
- * Returns a reference to the parent node of an add operation. Nodes for new
- * properties can be added as children of this node. If the path for the
- * specified key does not exist so far, it is created now.
- *
- * @param keyIt the iterator for the key of the new property
- * @param startNode the node to start the search with
- * @return the parent node for the add operation
- * @deprecated Adding new properties is now to a major part delegated to the
- * {@code ExpressionEngine} associated with this configuration instance.
- * This method will no longer be called. Developers who want to modify the
- * process of adding new properties should consider implementing their own
- * expression engine.
- */
- @Deprecated
- protected Node fetchAddNode(ConfigurationKey.KeyIterator keyIt, Node startNode)
- {
- return null;
- }
-
- /**
- * Finds the last existing node for an add operation. This method traverses
- * the configuration tree along the specified key. The last existing node on
- * this path is returned.
- *
- * @param keyIt the key iterator
- * @param node the actual node
- * @return the last existing node on the given path
- * @deprecated Adding new properties is now to a major part delegated to the
- * {@code ExpressionEngine} associated with this configuration instance.
- * This method will no longer be called. Developers who want to modify the
- * process of adding new properties should consider implementing their own
- * expression engine.
- */
- @Deprecated
- protected Node findLastPathNode(ConfigurationKey.KeyIterator keyIt, Node node)
- {
- return null;
- }
-
- /**
- * Creates the missing nodes for adding a new property. This method ensures
- * that there are corresponding nodes for all components of the specified
- * configuration key.
- *
- * @param keyIt the key iterator
- * @param root the base node of the path to be created
- * @return the last node of the path
- * @deprecated Adding new properties is now to a major part delegated to the
- * {@code ExpressionEngine} associated with this configuration instance.
- * This method will no longer be called. Developers who want to modify the
- * process of adding new properties should consider implementing their own
- * expression engine.
- */
- @Deprecated
- protected Node createAddPath(ConfigurationKey.KeyIterator keyIt, Node root)
- {
- return null;
- }
-
- /**
* Creates a new {@code Node} object with the specified name. This
* method can be overloaded in derived classes if a specific node type is
* needed. This base implementation always returns a new object of the
- * {@code Node} class.
+ * {@code DefaultConfigurationNode} class.
*
* @param name the name of the new node
* @return the new node
*/
- protected Node createNode(String name)
+ protected ConfigurationNode createNode(String name)
{
- return new Node(name);
+ return new DefaultConfigurationNode(name);
}
/**
@@ -1199,279 +1030,6 @@ public class HierarchicalConfiguration e
}
/**
- * Transforms the specified object into a Node. This method treats view
- * nodes in a special way. This is necessary because ViewNode does not
- * extend HierarchicalConfiguration.Node; thus the API for the node visitor
- * is slightly different. Therefore a view node is transformed into a
- * special compatibility Node object.
- *
- * @param obj the original node object
- * @return the node to be used
- */
- private static Node getNodeFor(Object obj)
- {
- Node nd;
- if (obj instanceof ViewNode)
- {
- final ViewNode viewNode = (ViewNode) obj;
- nd = new Node(viewNode)
- {
- @Override
- public void setReference(Object reference)
- {
- super.setReference(reference);
- // also set the reference at the original node
- viewNode.setReference(reference);
- }
- };
- }
- else
- {
- nd = (Node) obj;
- }
- return nd;
- }
-
- /**
- * A data class for storing (hierarchical) property information. A property
- * can have a value and an arbitrary number of child properties. From
- * version 1.3 on this class is only a thin wrapper over the
- * {@link org.apache.commons.configuration.tree.DefaultConfigurationNode DefaultconfigurationNode}
- * class that exists mainly for the purpose of backwards compatibility.
- */
- public static class Node extends DefaultConfigurationNode implements Serializable
- {
- /**
- * The serial version UID.
- */
- private static final long serialVersionUID = -6357500633536941775L;
-
- /**
- * Creates a new instance of {@code Node}.
- */
- public Node()
- {
- super();
- }
-
- /**
- * Creates a new instance of {@code Node} and sets the name.
- *
- * @param name the node's name
- */
- public Node(String name)
- {
- super(name);
- }
-
- /**
- * Creates a new instance of {@code Node} and sets the name and the value.
- *
- * @param name the node's name
- * @param value the value
- */
- public Node(String name, Object value)
- {
- super(name, value);
- }
-
- /**
- * Creates a new instance of {@code Node} based on the given
- * source node. All properties of the source node, including its
- * children and attributes, will be copied.
- *
- * @param src the node to be copied
- */
- public Node(ConfigurationNode src)
- {
- this(src.getName(), src.getValue());
- setReference(src.getReference());
- for (ConfigurationNode nd : src.getChildren())
- {
- // Don't change the parent node
- ConfigurationNode parent = nd.getParentNode();
- addChild(nd);
- nd.setParentNode(parent);
- }
-
- for (ConfigurationNode nd : src.getAttributes())
- {
- // Don't change the parent node
- ConfigurationNode parent = nd.getParentNode();
- addAttribute(nd);
- nd.setParentNode(parent);
- }
- }
-
- /**
- * Returns the parent of this node.
- *
- * @return this node's parent (can be <b>null</b>)
- */
- public Node getParent()
- {
- return (Node) getParentNode();
- }
-
- /**
- * Sets the parent of this node.
- *
- * @param node the parent node
- */
- public void setParent(Node node)
- {
- setParentNode(node);
- }
-
- /**
- * Adds the given node to the children of this node.
- *
- * @param node the child to be added
- */
- public void addChild(Node node)
- {
- addChild((ConfigurationNode) node);
- }
-
- /**
- * Returns a flag whether this node has child elements.
- *
- * @return <b>true</b> if there is a child node, <b>false</b> otherwise
- */
- public boolean hasChildren()
- {
- return getChildrenCount() > 0 || getAttributeCount() > 0;
- }
-
- /**
- * Removes the specified child from this node.
- *
- * @param child the child node to be removed
- * @return a flag if the child could be found
- */
- public boolean remove(Node child)
- {
- return child.isAttribute() ? removeAttribute(child) : removeChild(child);
- }
-
- /**
- * Removes all children with the given name.
- *
- * @param name the name of the children to be removed
- * @return a flag if children with this name existed
- */
- public boolean remove(String name)
- {
- boolean childrenRemoved = removeChild(name);
- boolean attrsRemoved = removeAttribute(name);
- return childrenRemoved || attrsRemoved;
- }
-
- /**
- * 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.
- *
- * @param visitor the visitor
- * @param key here a configuration key with the name of the root node of
- * the iteration can be passed; if this key is not <b>null </b>, the
- * full paths to the visited nodes are builded and passed to the
- * visitor's {@code visit()} methods
- */
- public void visit(NodeVisitor visitor, ConfigurationKey key)
- {
- int length = 0;
- if (key != null)
- {
- length = key.length();
- if (getName() != null)
- {
- key
- .append(StringUtils
- .replace(
- isAttribute() ? ConfigurationKey
- .constructAttributeKey(getName())
- : getName(),
- String
- .valueOf(ConfigurationKey.PROPERTY_DELIMITER),
- ConfigurationKey.ESCAPED_DELIMITER));
- }
- }
-
- visitor.visitBeforeChildren(this, key);
-
- for (Iterator<ConfigurationNode> it = getChildren().iterator(); it.hasNext()
- && !visitor.terminate();)
- {
- Object obj = it.next();
- getNodeFor(obj).visit(visitor, key);
- }
- for (Iterator<ConfigurationNode> it = getAttributes().iterator(); it.hasNext()
- && !visitor.terminate();)
- {
- Object obj = it.next();
- getNodeFor(obj).visit(visitor, key);
- }
-
- visitor.visitAfterChildren(this, key);
- if (key != null)
- {
- key.setLength(length);
- }
- }
- }
-
- /**
- * <p>Definition of a visitor class for traversing a node and all of its
- * children.</p><p>This class defines the interface of a visitor for
- * {@code Node} objects and provides a default implementation. The
- * method {@code visit()} of {@code Node} implements a generic
- * iteration algorithm based on the <em>Visitor</em> pattern. By providing
- * different implementations of visitors it is possible to collect different
- * data during the iteration process.</p>
- *
- */
- public static class NodeVisitor
- {
- /**
- * Visits the specified node. This method is called during iteration for
- * each node before its children have been visited.
- *
- * @param node the actual node
- * @param key the key of this node (may be <b>null </b>)
- */
- public void visitBeforeChildren(Node node, ConfigurationKey key)
- {
- }
-
- /**
- * Visits the specified node after its children have been processed.
- * This gives a visitor the opportunity of collecting additional data
- * after the child nodes have been visited.
- *
- * @param node the node to be visited
- * @param key the key of this node (may be <b>null </b>)
- */
- public void visitAfterChildren(Node node, ConfigurationKey key)
- {
- }
-
- /**
- * Returns a flag that indicates if iteration should be stopped. This
- * method is called after each visited node. It can be useful for
- * visitors that search a specific node. If this node is found, the
- * whole process can be stopped. This base implementation always returns
- * <b>false </b>.
- *
- * @return a flag if iteration should be stopped
- */
- public boolean terminate()
- {
- return false;
- }
- }
-
- /**
* A specialized visitor that checks if a node is defined.
* "Defined" in this terms means that the node or at least one of
* its sub nodes is associated with a value.
@@ -1679,7 +1237,7 @@ public class HierarchicalConfiguration e
* structure.
*
*/
- protected abstract static class BuilderVisitor extends NodeVisitor
+ protected abstract static class BuilderVisitor extends ConfigurationNodeVisitorAdapter
{
/**
* Visits the specified node before its children have been traversed.
@@ -1688,13 +1246,13 @@ public class HierarchicalConfiguration e
* @param key the current key
*/
@Override
- public void visitBeforeChildren(Node node, ConfigurationKey key)
+ public void visitBeforeChildren(ConfigurationNode node)
{
Collection<ConfigurationNode> subNodes = new LinkedList<ConfigurationNode>(node.getChildren());
subNodes.addAll(node.getAttributes());
Iterator<ConfigurationNode> children = subNodes.iterator();
- Node sibling1 = null;
- Node nd = null;
+ ConfigurationNode sibling1 = null;
+ ConfigurationNode nd = null;
while (children.hasNext())
{
@@ -1702,19 +1260,17 @@ public class HierarchicalConfiguration e
do
{
sibling1 = nd;
- Object obj = children.next();
- nd = getNodeFor(obj);
+ nd = children.next();
} while (nd.getReference() != null && children.hasNext());
if (nd.getReference() == null)
{
// find all following new nodes
- List<Node> newNodes = new LinkedList<Node>();
+ List<ConfigurationNode> newNodes = new LinkedList<ConfigurationNode>();
newNodes.add(nd);
while (children.hasNext())
{
- Object obj = children.next();
- nd = getNodeFor(obj);
+ nd = children.next();
if (nd.getReference() == null)
{
newNodes.add(nd);
@@ -1726,8 +1282,8 @@ public class HierarchicalConfiguration e
}
// Insert all new nodes
- Node sibling2 = (nd.getReference() == null) ? null : nd;
- for (Node insertNode : newNodes)
+ ConfigurationNode sibling2 = (nd.getReference() == null) ? null : nd;
+ for (ConfigurationNode insertNode : newNodes)
{
if (insertNode.getReference() == null)
{
@@ -1764,6 +1320,8 @@ public class HierarchicalConfiguration e
* node
* @return the reference object for the node to be inserted
*/
- protected abstract Object insert(Node newNode, Node parent, Node sibling1, Node sibling2);
+ protected abstract Object insert(ConfigurationNode newNode,
+ ConfigurationNode parent, ConfigurationNode sibling1,
+ ConfigurationNode sibling2);
}
}
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java Tue Sep 18 20:07:29 2012
@@ -17,8 +17,8 @@
package org.apache.commons.configuration;
-import org.apache.commons.configuration.HierarchicalConfiguration.Node;
import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.ConfigurationNodeVisitorAdapter;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
@@ -100,7 +100,7 @@ public class HierarchicalConfigurationXM
@Override
protected void processKeys()
{
- getConfiguration().getRoot().visit(new SAXVisitor(), null);
+ getConfiguration().getRootNode().visit(new SAXVisitor());
}
/**
@@ -108,7 +108,7 @@ public class HierarchicalConfigurationXM
* hierarchical node structure.
*
*/
- class SAXVisitor extends HierarchicalConfiguration.NodeVisitor
+ class SAXVisitor extends ConfigurationNodeVisitorAdapter
{
/** Constant for the attribute type.*/
private static final String ATTR_TYPE = "CDATA";
@@ -117,10 +117,9 @@ public class HierarchicalConfigurationXM
* Visits the specified node after its children have been processed.
*
* @param node the actual node
- * @param key the key of this node
*/
@Override
- public void visitAfterChildren(Node node, ConfigurationKey key)
+ public void visitAfterChildren(ConfigurationNode node)
{
if (!isAttributeNode(node))
{
@@ -135,7 +134,7 @@ public class HierarchicalConfigurationXM
* @param key the key of this node
*/
@Override
- public void visitBeforeChildren(Node node, ConfigurationKey key)
+ public void visitBeforeChildren(ConfigurationNode node)
{
if (!isAttributeNode(node))
{
@@ -166,7 +165,7 @@ public class HierarchicalConfigurationXM
* @param node the actual node
* @return an object with all attributes of this node
*/
- protected Attributes fetchAttributes(Node node)
+ protected Attributes fetchAttributes(ConfigurationNode node)
{
AttributesImpl attrs = new AttributesImpl();
@@ -190,7 +189,7 @@ public class HierarchicalConfigurationXM
* @param node the node to be checked
* @return the name for this node
*/
- private String nodeName(Node node)
+ private String nodeName(ConfigurationNode node)
{
return (node.getName() == null) ? getRootName() : node.getName();
}
@@ -203,7 +202,7 @@ public class HierarchicalConfigurationXM
* @param node the node to be checked
* @return a flag if this is an attribute node
*/
- private boolean isAttributeNode(Node node)
+ private boolean isAttributeNode(ConfigurationNode node)
{
return node.isAttribute();
}
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java Tue Sep 18 20:07:29 2012
@@ -462,25 +462,6 @@ public class MultiFileHierarchicalConfig
}
@Override
- public Node getRoot()
- {
- return this.getConfiguration().getRoot();
- }
-
- @Override
- public void setRoot(Node node)
- {
- if (init)
- {
- this.getConfiguration().setRoot(node);
- }
- else
- {
- super.setRoot(node);
- }
- }
-
- @Override
public ConfigurationNode getRootNode()
{
return this.getConfiguration().getRootNode();
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java Tue Sep 18 20:07:29 2012
@@ -332,25 +332,6 @@ public class PatternSubtreeConfiguration
}
@Override
- public Node getRoot()
- {
- return getConfig().getRoot();
- }
-
- @Override
- public void setRoot(Node node)
- {
- if (init)
- {
- getConfig().setRoot(node);
- }
- else
- {
- super.setRoot(node);
- }
- }
-
- @Override
public ConfigurationNode getRootNode()
{
return getConfig().getRootNode();
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java Tue Sep 18 20:07:29 2012
@@ -311,7 +311,7 @@ public class SubnodeConfiguration extend
* @return the new node
*/
@Override
- protected Node createNode(String name)
+ protected ConfigurationNode createNode(String name)
{
return getParent().createNode(name);
}
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java Tue Sep 18 20:07:29 2012
@@ -49,6 +49,7 @@ import javax.xml.transform.stream.Stream
import org.apache.commons.configuration.resolver.DefaultEntityResolver;
import org.apache.commons.configuration.resolver.EntityRegistry;
import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
@@ -502,7 +503,7 @@ public class XMLConfiguration extends Ab
public void clear()
{
super.clear();
- setRoot(new Node());
+ getRootNode().setReference(null);
document = null;
}
@@ -520,11 +521,11 @@ public class XMLConfiguration extends Ab
setSystemID(document.getDoctype().getSystemId());
}
- constructHierarchy(getRoot(), document.getDocumentElement(), elemRefs, true);
+ constructHierarchy(getRootNode(), document.getDocumentElement(), elemRefs, true);
getRootNode().setName(document.getDocumentElement().getNodeName());
if (elemRefs)
{
- getRoot().setReference(document.getDocumentElement());
+ getRootNode().setReference(document.getDocumentElement());
}
}
@@ -539,7 +540,7 @@ public class XMLConfiguration extends Ab
* this controls the whitespace handling
* @return a map with all attribute values extracted for the current node
*/
- private Map<String, String> constructHierarchy(Node node,
+ private Map<String, String> constructHierarchy(ConfigurationNode node,
Element element, boolean elemRefs, boolean trim)
{
boolean trimFlag = shouldTrim(element, trim);
@@ -553,7 +554,7 @@ public class XMLConfiguration extends Ab
if (w3cNode instanceof Element)
{
Element child = (Element) w3cNode;
- Node childNode = new XMLNode(child.getTagName(),
+ ConfigurationNode childNode = new XMLNode(child.getTagName(),
elemRefs ? child : null);
Map<String, String> attrmap =
constructHierarchy(childNode, child, elemRefs, trimFlag);
@@ -572,7 +573,7 @@ public class XMLConfiguration extends Ab
{
text = text.trim();
}
- if (text.length() > 0 || (!node.hasChildren() && node != getRoot()))
+ if (text.length() > 0 || (!hasChildren(node) && node != getRootNode()))
{
node.setValue(text);
}
@@ -580,6 +581,17 @@ public class XMLConfiguration extends Ab
}
/**
+ * Tests whether the specified node has some child elements.
+ *
+ * @param node the node to check
+ * @return a flag whether there are child elements
+ */
+ private static boolean hasChildren(ConfigurationNode node)
+ {
+ return node.getChildrenCount() > 0 || node.getAttributeCount() > 0;
+ }
+
+ /**
* Helper method for constructing node objects for the attributes of the
* given XML element.
*
@@ -588,7 +600,7 @@ public class XMLConfiguration extends Ab
* @param elemRefs a flag whether references to the XML elements should be set
* @return a map with all attribute values extracted for the current node
*/
- private Map<String, String> processAttributes(Node node,
+ private Map<String, String> processAttributes(ConfigurationNode node,
Element element, boolean elemRefs)
{
NamedNodeMap attributes = element.getAttributes();
@@ -626,10 +638,10 @@ public class XMLConfiguration extends Ab
* @param attr the name of the attribute
* @param value the attribute value
*/
- private void appendAttribute(Node node, Element element, boolean elemRefs,
+ private void appendAttribute(ConfigurationNode node, Element element, boolean elemRefs,
String attr, String value)
{
- Node child = new XMLNode(attr, elemRefs ? element : null);
+ ConfigurationNode child = new XMLNode(attr, elemRefs ? element : null);
child.setValue(value);
node.addAttribute(child);
}
@@ -643,7 +655,7 @@ public class XMLConfiguration extends Ab
* @param trim flag whether texts of elements should be trimmed
* @param attrmap a map with the attributes of the current node
*/
- private void handleDelimiters(Node parent, Node child, boolean trim,
+ private void handleDelimiters(ConfigurationNode parent, ConfigurationNode child, boolean trim,
Map<String, String> attrmap)
{
if (child.getValue() != null)
@@ -664,7 +676,7 @@ public class XMLConfiguration extends Ab
{
Iterator<String> it = values.iterator();
// Create new node for the original child's first value
- Node c = createNode(child.getName());
+ ConfigurationNode c = createNode(child.getName());
c.setValue(it.next());
// Copy original attributes to the new node
for (ConfigurationNode ndAttr : child.getAttributes())
@@ -672,13 +684,13 @@ public class XMLConfiguration extends Ab
ndAttr.setReference(null);
c.addAttribute(ndAttr);
}
- parent.remove(child);
+ parent.removeChild(child);
parent.addChild(c);
// add multiple new children
while (it.hasNext())
{
- c = new XMLNode(child.getName(), null);
+ c = createNode(child.getName());
c.setValue(it.next());
for (Map.Entry<String, String> e : attrmap.entrySet())
{
@@ -796,7 +808,7 @@ public class XMLConfiguration extends Ab
XMLBuilderVisitor builder = new XMLBuilderVisitor(document,
isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter());
- builder.processDocument(getRoot());
+ builder.processDocument(getRootNode());
initRootElementText(document, getRootNode().getValue());
return document;
}
@@ -846,7 +858,7 @@ public class XMLConfiguration extends Ab
* @return the new node
*/
@Override
- protected Node createNode(String name)
+ protected ConfigurationNode createNode(String name)
{
return new XMLNode(name, null);
}
@@ -1189,7 +1201,7 @@ public class XMLConfiguration extends Ab
* A specialized {@code Node} class that is connected with an XML
* element. Changes on a node are also performed on the associated element.
*/
- class XMLNode extends Node
+ class XMLNode extends DefaultConfigurationNode
{
/**
* The serial version UID.
@@ -1305,7 +1317,7 @@ public class XMLConfiguration extends Ab
*/
private void updateAttribute()
{
- XMLBuilderVisitor.updateAttribute(getParent(), getName());
+ XMLBuilderVisitor.updateAttribute(getParentNode(), getName());
}
/**
@@ -1384,9 +1396,9 @@ public class XMLConfiguration extends Ab
*
* @param rootNode the root node
*/
- public void processDocument(Node rootNode)
+ public void processDocument(ConfigurationNode rootNode)
{
- rootNode.visit(this, null);
+ rootNode.visit(this);
}
/**
@@ -1400,7 +1412,9 @@ public class XMLConfiguration extends Ab
* @return the new node
*/
@Override
- protected Object insert(Node newNode, Node parent, Node sibling1, Node sibling2)
+ protected Object insert(ConfigurationNode newNode,
+ ConfigurationNode parent, ConfigurationNode sibling1,
+ ConfigurationNode sibling2)
{
if (newNode.isAttribute())
{
@@ -1444,7 +1458,7 @@ public class XMLConfiguration extends Ab
* @param elem the element that is associated with this node
* @param name the name of the affected attribute
*/
- private static void updateAttribute(Node node, Element elem, String name)
+ private static void updateAttribute(ConfigurationNode node, Element elem, String name)
{
if (node != null && elem != null)
{
@@ -1503,7 +1517,7 @@ public class XMLConfiguration extends Ab
* @param node the affected node
* @param name the name of the attribute
*/
- static void updateAttribute(Node node, String name)
+ static void updateAttribute(ConfigurationNode node, String name)
{
if (node != null)
{
@@ -1517,7 +1531,7 @@ public class XMLConfiguration extends Ab
* @param node the node
* @return the element of this node
*/
- private Element getElement(Node node)
+ private Element getElement(ConfigurationNode node)
{
// special treatment for root node of the hierarchy
return (node.getName() != null && node.getReference() != null) ? (Element) node
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java Tue Sep 18 20:07:29 2012
@@ -38,6 +38,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.lang.StringUtils;
/**
@@ -229,7 +230,7 @@ public class PropertyListConfiguration e
try
{
HierarchicalConfiguration config = parser.parse();
- setRoot(config.getRoot());
+ setRootNode(config.getRootNode());
}
catch (ParseException e)
{
@@ -240,7 +241,7 @@ public class PropertyListConfiguration e
public void save(Writer out) throws ConfigurationException
{
PrintWriter writer = new PrintWriter(out);
- printNode(writer, 0, getRoot());
+ printNode(writer, 0, getRootNode());
writer.flush();
}
@@ -339,7 +340,7 @@ public class PropertyListConfiguration e
}
else if (value instanceof HierarchicalConfiguration)
{
- printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRoot());
+ printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRootNode());
}
else if (value instanceof Configuration)
{
@@ -352,7 +353,7 @@ public class PropertyListConfiguration e
while (it.hasNext())
{
String key = it.next();
- Node node = new Node(key);
+ ConfigurationNode node = new DefaultConfigurationNode(key);
node.setValue(config.getProperty(key));
printNode(out, indentLevel + 1, node);
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java Tue Sep 18 20:07:29 2012
@@ -47,6 +47,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.xml.sax.Attributes;
@@ -247,7 +248,7 @@ public class XMLPropertyListConfiguratio
};
// parse the file
- XMLPropertyListHandler handler = new XMLPropertyListHandler(getRoot());
+ XMLPropertyListHandler handler = new XMLPropertyListHandler(getRootNode());
try
{
SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -280,7 +281,7 @@ public class XMLPropertyListConfiguratio
writer.println("<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">");
writer.println("<plist version=\"1.0\">");
- printNode(writer, 1, getRoot());
+ printNode(writer, 1, getRootNode());
writer.println("</plist>");
writer.flush();
@@ -380,7 +381,7 @@ public class XMLPropertyListConfiguratio
}
else if (value instanceof HierarchicalConfiguration)
{
- printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRoot());
+ printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRootNode());
}
else if (value instanceof Configuration)
{
@@ -393,7 +394,7 @@ public class XMLPropertyListConfiguratio
{
// create a node for each property
String key = it.next();
- Node node = new Node(key);
+ ConfigurationNode node = new DefaultConfigurationNode(key);
node.setValue(config.getProperty(key));
// print the node
@@ -465,9 +466,9 @@ public class XMLPropertyListConfiguratio
private StringBuilder buffer = new StringBuilder();
/** The stack of configuration nodes */
- private List<Node> stack = new ArrayList<Node>();
+ private List<ConfigurationNode> stack = new ArrayList<ConfigurationNode>();
- public XMLPropertyListHandler(Node root)
+ public XMLPropertyListHandler(ConfigurationNode root)
{
push(root);
}
@@ -475,7 +476,7 @@ public class XMLPropertyListConfiguratio
/**
* Return the node on the top of the stack.
*/
- private Node peek()
+ private ConfigurationNode peek()
{
if (!stack.isEmpty())
{
@@ -490,7 +491,7 @@ public class XMLPropertyListConfiguratio
/**
* Remove and return the node on the top of the stack.
*/
- private Node pop()
+ private ConfigurationNode pop()
{
if (!stack.isEmpty())
{
@@ -505,7 +506,7 @@ public class XMLPropertyListConfiguratio
/**
* Put a node on the top of the stack.
*/
- private void push(Node node)
+ private void push(ConfigurationNode node)
{
stack.add(node);
}
@@ -529,7 +530,7 @@ public class XMLPropertyListConfiguratio
node.addValue(config);
// push the root on the stack
- push(config.getRoot());
+ push(config.getRootNode());
}
}
}
@@ -617,7 +618,7 @@ public class XMLPropertyListConfiguratio
* <b>Do not use this class !</b> It is used internally by XMLPropertyConfiguration
* to parse the configuration file, it may be removed at any moment in the future.
*/
- public static class PListNode extends Node
+ public static class PListNode extends DefaultConfigurationNode
{
/**
* The serial version UID.
Modified: commons/proper/configuration/trunk/src/main/javacc/PropertyListParser.jj
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/javacc/PropertyListParser.jj?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/javacc/PropertyListParser.jj (original)
+++ commons/proper/configuration/trunk/src/main/javacc/PropertyListParser.jj Tue Sep 18 20:07:29 2012
@@ -29,7 +29,8 @@ import java.util.List;
import java.util.ArrayList;
import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.configuration.HierarchicalConfiguration.Node;
+import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.codec.binary.Hex;
@@ -166,8 +167,8 @@ PropertyListConfiguration parse() :
PropertyListConfiguration Dictionary() :
{
PropertyListConfiguration configuration = new PropertyListConfiguration();
- List<Node> children = new ArrayList<Node>();
- Node child = null;
+ List<ConfigurationNode> children = new ArrayList<ConfigurationNode>();
+ ConfigurationNode child = null;
}
{
<DICT_BEGIN>
@@ -178,7 +179,7 @@ PropertyListConfiguration Dictionary() :
{
// prune & graft the nested configuration to the parent configuration
HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue();
- Node root = conf.getRoot();
+ ConfigurationNode root = conf.getRootNode();
root.setName(child.getName());
children.add(root);
}
@@ -193,18 +194,18 @@ PropertyListConfiguration Dictionary() :
for (int i = 0; i < children.size(); i++)
{
child = children.get(i);
- configuration.getRoot().addChild(child);
+ configuration.getRootNode().addChild(child);
}
return configuration;
}
}
-Node Property() :
+ConfigurationNode Property() :
{
String key = null;
Object value = null;
- Node node = new Node();
+ ConfigurationNode node = new DefaultConfigurationNode();
}
{
key = String()
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java Tue Sep 18 20:07:29 2012
@@ -20,7 +20,6 @@ package org.apache.commons.configuration
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -34,7 +33,6 @@ import java.util.List;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.configuration.HierarchicalConfiguration.Node;
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener;
import org.apache.commons.configuration.tree.ConfigurationNode;
@@ -78,14 +76,14 @@ public class TestHierarchicalConfigurati
* name
*/
config = new HierarchicalConfiguration();
- HierarchicalConfiguration.Node nodeTables = createNode("tables", null);
+ ConfigurationNode nodeTables = createNode("tables", null);
for(int i = 0; i < tables.length; i++)
{
- HierarchicalConfiguration.Node nodeTable = createNode("table", null);
+ ConfigurationNode nodeTable = createNode("table", null);
nodeTables.addChild(nodeTable);
- HierarchicalConfiguration.Node nodeName = createNode("name", tables[i]);
+ ConfigurationNode nodeName = createNode("name", tables[i]);
nodeTable.addChild(nodeName);
- HierarchicalConfiguration.Node nodeFields = createNode("fields", null);
+ ConfigurationNode nodeFields = createNode("fields", null);
nodeTable.addChild(nodeFields);
for (int j = 0; j < fields[i].length; j++)
@@ -94,31 +92,16 @@ public class TestHierarchicalConfigurati
}
}
- config.getRoot().addChild(nodeTables);
+ config.getRootNode().addChild(nodeTables);
}
- @Test
- public void testSetRoot()
- {
- config.setRoot(new HierarchicalConfiguration.Node("test"));
- assertTrue(config.isEmpty());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetRootNull()
- {
- config.setRoot(null);
- }
@Test
public void testSetRootNode()
{
- config.setRootNode(new DefaultConfigurationNode("testNode"));
- assertNotSame("Same root node", config.getRootNode(), config.getRoot());
- assertEquals("Wrong name of root node", "testNode", config.getRoot().getName());
-
- config.setRootNode(new HierarchicalConfiguration.Node("test"));
- assertSame("Wrong root node", config.getRootNode(), config.getRoot());
+ ConfigurationNode root = new DefaultConfigurationNode("testNode");
+ config.setRootNode(root);
+ assertSame("Wrong root node", root, config.getRootNode());
}
@Test(expected = IllegalArgumentException.class)
@@ -133,10 +116,10 @@ public class TestHierarchicalConfigurati
assertFalse(config.isEmpty());
HierarchicalConfiguration conf2 = new HierarchicalConfiguration();
assertTrue(conf2.isEmpty());
- HierarchicalConfiguration.Node child1 = new HierarchicalConfiguration.Node("child1");
- HierarchicalConfiguration.Node child2 = new HierarchicalConfiguration.Node("child2");
+ ConfigurationNode child1 = new DefaultConfigurationNode("child1");
+ ConfigurationNode child2 = new DefaultConfigurationNode("child2");
child1.addChild(child2);
- conf2.getRoot().addChild(child1);
+ conf2.getRootNode().addChild(child1);
assertTrue(conf2.isEmpty());
}
@@ -699,7 +682,7 @@ public class TestHierarchicalConfigurati
{
Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
nodes.add(createNode("usr", "scott"));
- Node nd = createNode("pwd", "tiger");
+ ConfigurationNode nd = createNode("pwd", "tiger");
nd.setAttribute(true);
nodes.add(nd);
config.addNodes("database.connection.settings", nodes);
@@ -761,81 +744,6 @@ public class TestHierarchicalConfigurati
}
/**
- * Tests removing children from a configuration node.
- */
- @Test
- public void testNodeRemove()
- {
- HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(
- "parent", "test");
- assertFalse(node.hasChildren());
- node.removeChildren(); // should have no effect
- assertFalse(node.remove("child"));
-
- node.addChild(createNode("test", "test"));
- assertTrue(node.hasChildren());
- assertTrue(node.remove("test"));
- assertFalse(node.hasChildren());
-
- for (int i = 0; i < 10; i++)
- {
- node.addChild(createNode("child" + i, "test" + i));
- }
- assertTrue(node.hasChildren());
- assertFalse(node.remove("child"));
- assertTrue(node.remove("child2"));
- assertTrue(node.getChildren("child2").isEmpty());
-
- HierarchicalConfiguration.Node child = createNode("child0", "testChild");
- assertFalse(node.remove(child));
- node.addChild(child);
- assertTrue(node.remove(child));
- assertEquals(1, node.getChildren("child0").size());
- assertEquals("test0", ((HierarchicalConfiguration.Node) node
- .getChildren("child0").get(0)).getValue());
-
- assertTrue(node.remove("child0"));
- assertFalse(node.remove(child));
-
- node.removeChildren();
- assertTrue(node.getChildren().isEmpty());
- assertFalse(node.remove(child));
- }
-
- /**
- * Tests the visitor mechanism.
- */
- @Test
- public void testNodeVisitor()
- {
- CountVisitor v = new CountVisitor();
- config.getRoot().visit(v, null);
- assertEquals("Wrong number of visits", 28, v.beforeCount);
- assertEquals("Different number of before and after visits",
- v.beforeCount, v.afterCount);
- }
-
- /**
- * Tests the visitor mechanism if a ConfigurationKey is passed in.
- */
- @Test
- public void testNodeVisitorKeys()
- {
- CountVisitor v = new CountVisitor();
- @SuppressWarnings("deprecation")
- ConfigurationKey configKey = new ConfigurationKey();
- config.getRoot().visit(v, configKey);
- for (Iterator<String> it = config.getKeys(); it.hasNext();)
- {
- String key = it.next();
- assertTrue("Key not found in before keys: " + key, v.beforeKeys
- .contains(key));
- assertTrue("Key not found in after keys: " + key, v.afterKeys
- .contains(key));
- }
- }
-
- /**
* Tests setting a custom expression engine, which uses a slightly different
* syntax.
*/
@@ -1073,7 +981,7 @@ public class TestHierarchicalConfigurati
root.addChild(child1);
config.setRootNode(root);
config.addProperty("child2", "test2");
- ConfigurationNode oldRoot = config.getRoot();
+ ConfigurationNode oldRoot = config.getRootNode();
assertEquals("Wrong number of children", 2, oldRoot.getChildrenCount());
}
@@ -1188,9 +1096,9 @@ public class TestHierarchicalConfigurati
* @param name the name of the field
* @return the field node
*/
- private static HierarchicalConfiguration.Node createFieldNode(String name)
+ private static ConfigurationNode createFieldNode(String name)
{
- HierarchicalConfiguration.Node fld = createNode("field", null);
+ ConfigurationNode fld = createNode("field", null);
fld.addChild(createNode("name", name));
return fld;
}
@@ -1201,52 +1109,10 @@ public class TestHierarchicalConfigurati
* @param value the node's value
* @return the new node
*/
- private static HierarchicalConfiguration.Node createNode(String name, Object value)
+ private static ConfigurationNode createNode(String name, Object value)
{
- HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
+ ConfigurationNode node = new DefaultConfigurationNode(name);
node.setValue(value);
return node;
}
-
- /**
- * A test visitor implementation for checking whether all visitor methods
- * are correctly called.
- */
- @SuppressWarnings("deprecation")
- static class CountVisitor extends HierarchicalConfiguration.NodeVisitor
- {
- /** The number of invocations of visitBeforeChildren(). */
- int beforeCount;
-
- /** The number of invocations of visitAfterChildren(). */
- int afterCount;
-
- /** A set with the keys passed to visitBeforeChildren(). */
- final Set<String> beforeKeys = new HashSet<String>();
-
- /** A set with the keys passed to visitAfterChildren(). */
- final Set<String> afterKeys = new HashSet<String>();
-
- @Override
- public void visitAfterChildren(Node node, ConfigurationKey key)
- {
- super.visitAfterChildren(node, key);
- afterCount++;
- if (key != null)
- {
- afterKeys.add(key.toString());
- }
- }
-
- @Override
- public void visitBeforeChildren(Node node, ConfigurationKey key)
- {
- super.visitBeforeChildren(node, key);
- beforeCount++;
- if (key != null)
- {
- beforeKeys.add(key.toString());
- }
- }
- }
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java Tue Sep 18 20:07:29 2012
@@ -70,13 +70,13 @@ public class TestSubnodeConfiguration
public TemporaryFolder folder = new TemporaryFolder();
/** The parent configuration. */
- HierarchicalConfiguration parent;
+ private HierarchicalConfiguration parent;
/** The subnode configuration to be tested. */
- SubnodeConfiguration config;
+ private SubnodeConfiguration config;
/** Stores a counter for the created nodes. */
- int nodeCounter;
+ private int nodeCounter;
@Before
public void setUp() throws Exception
@@ -93,7 +93,7 @@ public class TestSubnodeConfiguration
{
setUpSubnodeConfig();
assertSame("Wrong root node in subnode", getSubnodeRoot(parent), config
- .getRoot());
+ .getRootNode());
assertSame("Wrong parent config", parent, config.getParent());
}
@@ -569,7 +569,7 @@ public class TestSubnodeConfiguration
// Provide a special implementation of createNode() to check
// if it is called by the subnode config
@Override
- protected Node createNode(String name)
+ protected ConfigurationNode createNode(String name)
{
nodeCounter++;
return super.createNode(name);
@@ -596,7 +596,7 @@ public class TestSubnodeConfiguration
*/
protected ConfigurationNode getSubnodeRoot(HierarchicalConfiguration conf)
{
- ConfigurationNode root = conf.getRoot();
+ ConfigurationNode root = conf.getRootNode();
return root.getChild(0).getChild(0);
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java Tue Sep 18 20:07:29 2012
@@ -47,6 +47,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.reloading.InvariantReloadingStrategy;
import org.apache.commons.configuration.resolver.CatalogResolver;
import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.junit.Before;
import org.junit.Test;
@@ -1457,7 +1458,7 @@ public class TestXMLConfiguration
{
conf.setFile(testSaveConf);
conf.setAutoSave(true);
- HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(
+ ConfigurationNode node = new DefaultConfigurationNode(
"addNodesTest", Boolean.TRUE);
Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(1);
nodes.add(node);
@@ -1474,10 +1475,10 @@ public class TestXMLConfiguration
@Test
public void testAddNodesAndSave() throws ConfigurationException
{
- ConfigurationNode node = new HierarchicalConfiguration.Node("test");
- ConfigurationNode child = new HierarchicalConfiguration.Node("child");
+ ConfigurationNode node = new DefaultConfigurationNode("test");
+ ConfigurationNode child = new DefaultConfigurationNode("child");
node.addChild(child);
- ConfigurationNode attr = new HierarchicalConfiguration.Node("attr");
+ ConfigurationNode attr = new DefaultConfigurationNode("attr");
node.addAttribute(attr);
ConfigurationNode node2 = conf.createNode("test2");
Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(2);
@@ -1599,11 +1600,10 @@ public class TestXMLConfiguration
conf.addProperty("testAddNodes.property(-1)[@name]", "prop2");
conf.addProperty("testAddNodes.property(1).value", "value2");
Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
- nodes.add(new HierarchicalConfiguration.Node("property"));
+ nodes.add(new DefaultConfigurationNode("property"));
conf.addNodes("testAddNodes", nodes);
nodes.clear();
- ConfigurationNode nd = new HierarchicalConfiguration.Node("name",
- "prop3");
+ ConfigurationNode nd = new DefaultConfigurationNode("name", "prop3");
nd.setAttribute(true);
nodes.add(nd);
conf.addNodes("testAddNodes.property(2)", nodes);
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java Tue Sep 18 20:07:29 2012
@@ -116,7 +116,7 @@ public class TestXMLBeanDeclaration
public void testInitFromNullConfigurationAndNode()
{
decl = new XMLBeanDeclaration(null, new HierarchicalConfiguration()
- .getRoot());
+ .getRootNode());
}
/**
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java Tue Sep 18 20:07:29 2012
@@ -176,7 +176,7 @@ public class TestMergeCombiner extends A
assertEquals("Wrong field", "docname", c
.getString("fields.field(1).name"));
- List<ConfigurationNode> nds = config.getExpressionEngine().query(config.getRoot(),
+ List<ConfigurationNode> nds = config.getExpressionEngine().query(config.getRootNode(),
"database.tables.table");
assertFalse("No node found", nds.isEmpty());
return nds.get(0);
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java?rev=1387339&r1=1387338&r2=1387339&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java Tue Sep 18 20:07:29 2012
@@ -170,7 +170,7 @@ public class TestOverrideCombiner extend
assertEquals("Wrong field", "docname", c
.getString("fields.field(1).name"));
- List<ConfigurationNode> nds = config.getExpressionEngine().query(config.getRoot(),
+ List<ConfigurationNode> nds = config.getExpressionEngine().query(config.getRootNode(),
"database.tables.table");
assertFalse("No node found", nds.isEmpty());
return nds.get(0);