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 2008/04/17 08:18:36 UTC
svn commit: r648966 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/combined/
main/java/org/apache/commons/configuration2/expr/
test/java/org/apache/commons/configuration2/combined/
Author: oheger
Date: Wed Apr 16 23:18:23 2008
New Revision: 648966
URL: http://svn.apache.org/viewvc?rev=648966&view=rev
Log:
Extended NodeHandler interface to distinguish between value and structure nodes
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedConfigurationNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/AbstractNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/combined/TestCombinedConfigurationNodeHandler.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedConfigurationNodeHandler.java?rev=648966&r1=648965&r2=648966&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedConfigurationNodeHandler.java Wed Apr 16 23:18:23 2008
@@ -142,6 +142,20 @@
}
/**
+ * Adds a new child with a value to a parent node. This implementation
+ * delegates to the node handler responsible for the passed in node.
+ *
+ * @param node the node
+ * @param name the name of the new child node
+ * @param value the value
+ * @return the newly created child node
+ */
+ public Object addChild(Object node, String name, Object value)
+ {
+ return fetchHandler(node).addChild(node, name, value);
+ }
+
+ /**
* Returns the value of the specified attribute of the given node. This
* implementation delegates to the node handler responsible for the passed
* in node.
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/AbstractNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/AbstractNodeHandler.java?rev=648966&r1=648965&r2=648966&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/AbstractNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/AbstractNodeHandler.java Wed Apr 16 23:18:23 2008
@@ -71,4 +71,21 @@
{
return getValue(node) != null || hasAttributes(node);
}
+
+ /**
+ * Adds a child node with a value. This implementation delegates to the
+ * overloaded <code>addChild()</code> method and then sets the value on
+ * the resulting node.
+ *
+ * @param node the parent node
+ * @param name the name of the new child
+ * @param value the value
+ * @return the newly created child node
+ */
+ public T addChild(T node, String name, Object value)
+ {
+ T child = addChild(node, name);
+ setValue(child, value);
+ return child;
+ }
}
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java?rev=648966&r1=648965&r2=648966&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java Wed Apr 16 23:18:23 2008
@@ -80,6 +80,22 @@
T addChild(T node, String name);
/**
+ * Adds a child with the given node name and value to the specified parent
+ * node. This method is used for creating nodes with a value while the other
+ * <code>addChild()</code> method creates structure nodes (i.e. nodes that
+ * may contain child nodes and attributes, but do not have a value). Some
+ * concrete implementations of node handler have to distinguish between
+ * these node types.
+ *
+ * @param node the parent node
+ * @param name the name of the new child
+ * @param value the value of the new child
+ * @return the newly added child (this can be <b>null</b> if an
+ * implementation decides to create an attribute for the value node)
+ */
+ T addChild(T node, String name, Object value);
+
+ /**
* Returns a list with all children of the specified node.
*
* @param node the node
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/combined/TestCombinedConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/combined/TestCombinedConfigurationNodeHandler.java?rev=648966&r1=648965&r2=648966&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/combined/TestCombinedConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/combined/TestCombinedConfigurationNodeHandler.java Wed Apr 16 23:18:23 2008
@@ -264,6 +264,19 @@
}
/**
+ * Tests the addChild() implementation that sets a value.
+ */
+ public void testAddChildValue()
+ {
+ subHandler.addChild(this, SUB_NAME, VALUE);
+ EasyMock.expectLastCall().andReturn(NODE);
+ EasyMock.replay(subHandler);
+ assertEquals("Wrong child node", NODE, handler.addChild(this, SUB_NAME,
+ VALUE));
+ EasyMock.verify(subHandler);
+ }
+
+ /**
* Tests the getAttributeValue() implementation.
*/
public void testGetAttributeValue()