Author: oheger
Date: Wed Feb 20 13:37:06 2008
New Revision: 629621
URL: http://svn.apache.org/viewvc?rev=629621&view=rev
Log:
Removed the inner class NodeVisitor from HierarchicalConfiguration. It existed
only for backwards compatibility reasons. It could be replaced by
ConfigurationNodeVisitorAdapter.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java?rev=629621&r1=629620&r2=629621&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java
Wed Feb 20 13:37:06 2008
@@ -37,7 +37,6 @@
import org.apache.commons.configuration2.tree.DefaultExpressionEngine;
import org.apache.commons.configuration2.tree.ExpressionEngine;
import org.apache.commons.configuration2.tree.NodeAddData;
-import org.apache.commons.lang.StringUtils;
/**
* <p>A specialized configuration class that extends its base class by the
@@ -1244,100 +1243,6 @@
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 pathes to the visited nodes are builded and passed to the
- * visitor's <code>visit()</code> 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();)
- {
- ((Node) it.next()).visit(visitor, key);
- }
- for (Iterator<ConfigurationNode> it = getAttributes().iterator();
it.hasNext() && !visitor.terminate();)
- {
- ((Node) it.next()).visit(visitor, key);
- }
-
- if (key != null)
- {
- key.setLength(length);
- }
- visitor.visitAfterChildren(this, key);
- }
- }
-
- /**
- * <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</code> objects and provides a default implementation. The
- * method <code>visit()</code> of <code>Node</code> 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;
- }
}
/**
@@ -1545,17 +1450,16 @@
* method is called, which must be defined in concrete sub classes. This
* method can perform all steps to integrate the new node into the original
* 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.
*
* @param node the node to visit
- * @param key the current key
*/
- public void visitBeforeChildren(Node node, ConfigurationKey key)
+ @Override
+ public void visitBeforeChildren(ConfigurationNode node)
{
Collection<ConfigurationNode> subNodes = new
LinkedList<ConfigurationNode>(node.getChildren());
subNodes.addAll(node.getAttributes());
@@ -1629,6 +1533,8 @@
* 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/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java?rev=629621&r1=629620&r2=629621&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java
Wed Feb 20 13:37:06 2008
@@ -20,6 +20,8 @@
import java.util.Iterator;
import org.apache.commons.configuration2.HierarchicalConfiguration.Node;
+import org.apache.commons.configuration2.tree.ConfigurationNode;
+import org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
@@ -100,7 +102,7 @@
*/
protected void processKeys()
{
- getConfiguration().getRoot().visit(new SAXVisitor(), null);
+ getConfiguration().getRoot().visit(new SAXVisitor());
}
/**
@@ -108,7 +110,7 @@
* 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,9 +119,9 @@
* Visits the specified node after its children have been processed.
*
* @param node the actual node
- * @param key the key of this node
*/
- public void visitAfterChildren(Node node, ConfigurationKey key)
+ @Override
+ public void visitAfterChildren(ConfigurationNode node)
{
if (!isAttributeNode(node))
{
@@ -133,7 +135,8 @@
* @param node the actual node
* @param key the key of this node
*/
- public void visitBeforeChildren(Node node, ConfigurationKey key)
+ @Override
+ public void visitBeforeChildren(ConfigurationNode node)
{
if (!isAttributeNode(node))
{
@@ -152,6 +155,7 @@
*
* @return a flag if iteration should be stopped
*/
+ @Override
public boolean terminate()
{
return getException() != null;
@@ -163,7 +167,7 @@
* @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();
@@ -188,7 +192,7 @@
* @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();
}
@@ -201,7 +205,7 @@
* @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/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java?rev=629621&r1=629620&r2=629621&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
Wed Feb 20 13:37:06 2008
@@ -1145,7 +1145,7 @@
*/
public void processDocument(Node rootNode)
{
- rootNode.visit(this, null);
+ rootNode.visit(this);
}
/**
@@ -1158,7 +1158,8 @@
* @param sibling2 the second sibling
* @return the new node
*/
- protected Object insert(Node newNode, Node parent, Node sibling1, Node
sibling2)
+ @Override
+ protected Object insert(ConfigurationNode newNode, ConfigurationNode
parent, ConfigurationNode sibling1, ConfigurationNode sibling2)
{
if (newNode.isAttribute())
{
@@ -1203,7 +1204,7 @@
* @param name the name of the affected attribute
* @param listDelimiter the delimiter for attributes with multiple
values
*/
- private static void updateAttribute(Node node, Element elem, String
name, char listDelimiter)
+ private static void updateAttribute(ConfigurationNode node, Element
elem, String name, char listDelimiter)
{
if (node != null && elem != null)
{
@@ -1243,7 +1244,7 @@
* @param name the name of the attribute
* @param listDelimiter the delimiter for attributes with multiple
values
*/
- static void updateAttribute(Node node, String name, char listDelimiter)
+ static void updateAttribute(ConfigurationNode node, String name, char
listDelimiter)
{
if (node != null)
{
@@ -1257,7 +1258,7 @@
* @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/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java?rev=629621&r1=629620&r2=629621&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java
Wed Feb 20 13:37:06 2008
@@ -31,6 +31,7 @@
import org.apache.commons.configuration2.event.ConfigurationEvent;
import org.apache.commons.configuration2.event.ConfigurationListener;
import org.apache.commons.configuration2.tree.ConfigurationNode;
+import org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter;
import org.apache.commons.configuration2.tree.DefaultConfigurationNode;
import org.apache.commons.configuration2.tree.DefaultExpressionEngine;
import org.apache.commons.configuration2.tree.ExpressionEngine;
@@ -729,7 +730,7 @@
public void testNodeVisitor()
{
CountVisitor v = new CountVisitor();
- config.getRoot().visit(v, null);
+ config.getRoot().visit(v);
assertEquals(28, v.beforeCount);
assertEquals(v.beforeCount, v.afterCount);
}
@@ -1040,21 +1041,23 @@
* A test visitor implementation for checking whether all visitor methods
* are correctly called.
*/
- static class CountVisitor extends HierarchicalConfiguration.NodeVisitor
+ static class CountVisitor extends ConfigurationNodeVisitorAdapter
{
public int beforeCount;
public int afterCount;
- public void visitAfterChildren(Node node, ConfigurationKey key)
+ @Override
+ public void visitAfterChildren(ConfigurationNode node)
{
- super.visitAfterChildren(node, key);
+ super.visitAfterChildren(node);
afterCount++;
}
- public void visitBeforeChildren(Node node, ConfigurationKey key)
+ @Override
+ public void visitBeforeChildren(ConfigurationNode node)
{
- super.visitBeforeChildren(node, key);
+ super.visitBeforeChildren(node);
beforeCount++;
}
}