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/03/26 12:04:19 UTC

svn commit: r641252 - /commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/NodeCombiner.java

Author: oheger
Date: Wed Mar 26 04:04:17 2008
New Revision: 641252

URL: http://svn.apache.org/viewvc?rev=641252&view=rev
Log:
New NodeCombiner implementation based on node handlers

Added:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/NodeCombiner.java
      - copied, changed from r636104, commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeCombiner.java

Copied: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/NodeCombiner.java (from r636104, commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeCombiner.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/NodeCombiner.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/NodeCombiner.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeCombiner.java&r1=636104&r2=641252&rev=641252&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeCombiner.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/NodeCombiner.java Wed Mar 26 04:04:17 2008
@@ -14,13 +14,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.apache.commons.configuration2.tree;
+package org.apache.commons.configuration2.combined;
 
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.commons.configuration2.expr.NodeHandler;
+
 /**
  * <p>
  * A base class for node combiner implementations.
@@ -47,7 +48,7 @@
  *
  * @author <a href="http://commons.apache.org/configuration/team-list.html">Commons Configuration team</a>
  * @version $Id$
- * @since 1.3
+ * @since 2.0
  */
 public abstract class NodeCombiner
 {
@@ -84,16 +85,17 @@
     }
 
     /**
-     * Checks if a node is a list node. This implementation tests if the given
-     * node name is contained in the set of known list nodes. Derived classes
-     * which use different criteria may overload this method.
+     * Checks if a node is a list node. This implementation tests if the name of
+     * the given node is contained in the set of known list nodes. Derived
+     * classes which use different criteria may override this method.
      *
      * @param node the node to be tested
+     * @param handler the corresponding node handler
      * @return a flag whether this is a list node
      */
-    public boolean isListNode(ConfigurationNode node)
+    public <T> boolean isListNode(T node, NodeHandler<T> handler)
     {
-        return listNodes.contains(node.getName());
+        return listNodes.contains(handler.nodeName(node));
     }
 
     /**
@@ -105,18 +107,38 @@
      * @param node2 the second root node
      * @return the resulting combined node structure
      */
-    public abstract ConfigurationNode combine(ConfigurationNode node1, ConfigurationNode node2);
+    public abstract <T, U> CombinedNode combine(T node1, NodeHandler<T> handler1,
+            U node2, NodeHandler<U> handler2);
 
     /**
      * Creates a new view node. This method will be called whenever a new view
-     * node is to be created. It can be overriden to create special view nodes.
+     * node is to be created. It can be overridden to create special view nodes.
      * This base implementation returns a new instance of
-     * <code>{@link ViewNode}</code>.
+     * <code>{@link CombinedNode}</code>.
      *
      * @return the new view node
      */
-    protected ViewNode createViewNode()
+    protected CombinedNode createViewNode()
+    {
+        return new CombinedNode();
+    }
+
+    /**
+     * Appends all attributes of the given source node to the specified view
+     * node.
+     *
+     * @param <T> the type of nodes to deal with
+     * @param vn the view node
+     * @param node the source node
+     * @param handler the handler for the source node
+     */
+    protected <T> void appendAttributes(CombinedNode vn, T node,
+            NodeHandler<T> handler)
     {
-        return new ViewNode();
+        for (String attrName : handler.getAttributes(node))
+        {
+            vn.addAttributeValue(attrName, handler.getAttributeValue(node,
+                    attrName));
+        }
     }
 }