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 21:14:05 UTC

svn commit: r641540 - in /commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2: combined/CombinedNodeHandler.java expr/ConfigurationNodeHandler.java expr/NodeHandler.java

Author: oheger
Date: Wed Mar 26 13:14:03 2008
New Revision: 641540

URL: http://svn.apache.org/viewvc?rev=641540&view=rev
Log:
Minor extensions of the NodeHandler interface. The concrete handler implementations are now derived from AbstractNodeHandler.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedNodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedNodeHandler.java?rev=641540&r1=641539&r2=641540&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/combined/CombinedNodeHandler.java Wed Mar 26 13:14:03 2008
@@ -18,6 +18,7 @@
 
 import java.util.List;
 
+import org.apache.commons.configuration2.expr.AbstractNodeHandler;
 import org.apache.commons.configuration2.expr.NodeHandler;
 
 /**
@@ -47,7 +48,8 @@
  * @version $Id$
  * @since 2.0
  */
-public class CombinedNodeHandler implements NodeHandler<Object>
+public class CombinedNodeHandler extends AbstractNodeHandler<Object>
+implements NodeHandler<Object>
 {
     /**
      * Adds another value to an attribute of the specified combined node.
@@ -171,16 +173,15 @@
     }
 
     /**
-     * Tests whether the passed in node is defined. This implementation checks
-     * whether the node has a value or any attributes.
+     * Returns a flag whether the passed in combined node has any attributes.
      *
-     * @param node the node to test
-     * @return a flag whether this node is defined
+     * @param node the combined node
+     * @return a flag whether this node has any attributes
      */
-    public boolean isDefined(Object node)
+    @Override
+    public boolean hasAttributes(Object node)
     {
-        CombinedNode vn = node(node);
-        return vn.getValue() != null || vn.hasAttributes();
+        return node(node).hasAttributes();
     }
 
     /**

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java?rev=641540&r1=641539&r2=641540&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java Wed Mar 26 13:14:03 2008
@@ -31,7 +31,8 @@
  * @author Oliver Heger
  * @version $Id$
  */
-public class ConfigurationNodeHandler implements NodeHandler<ConfigurationNode>
+public class ConfigurationNodeHandler extends AbstractNodeHandler<ConfigurationNode>
+implements NodeHandler<ConfigurationNode>
 {
     /**
      * Creates a new child node with the given name and adds it to the specified
@@ -101,6 +102,19 @@
     }
 
     /**
+     * Checks whether the passed in node has any attributes. This implementation
+     * is slightly more efficient than the default one.
+     *
+     * @param node the node
+     * @return a flag whether this node has any attributes
+     */
+    @Override
+    public boolean hasAttributes(ConfigurationNode node)
+    {
+        return !node.getAttributes().isEmpty();
+    }
+
+    /**
      * Returns the child with the given index from the specified node.
      *
      * @param node the node
@@ -249,18 +263,6 @@
     public void removeChild(ConfigurationNode node, ConfigurationNode child)
     {
         node.removeChild(child);
-    }
-
-    /**
-     * Tests whether the passed in node is defined. This implementation checks
-     * whether the node has a value or any attributes.
-     *
-     * @param node the node to test
-     * @return a flag whether this node is defined
-     */
-    public boolean isDefined(ConfigurationNode node)
-    {
-        return node.getValue() != null || !node.getAttributes().isEmpty();
     }
 
     /**

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=641540&r1=641539&r2=641540&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 Mar 26 13:14:03 2008
@@ -139,6 +139,14 @@
     List<String> getAttributes(T node);
 
     /**
+     * Returns a flag whether the passed in node has any attributes.
+     *
+     * @param node the node
+     * @return a flag whether this node has any attributes
+     */
+    boolean hasAttributes(T node);
+
+    /**
      * Returns the value of the specified attribute from the given node. If a
      * concrete <code>NodeHandler</code> supports attributes with multiple
      * values, result might be a collection.
@@ -188,4 +196,16 @@
      * @return a flag whether the passed in node is defined
      */
     boolean isDefined(T node);
+
+    /**
+     * Initializes this <code>NodeHandler</code> with a reference to a
+     * <code>{@link NodeHandlerRegistry}</code>. This method is called when
+     * multiple types of configuration nodes are involved. It is especially
+     * useful for complex implementations that have to deal with arbitrary
+     * configuration nodes. <code>NodeHandler</code> implementations that only
+     * handle a specific node type can simply ignore this method.
+     *
+     * @param registry a reference to a <code>NodeHandlerRegistry</code>
+     */
+    void initNodeHandlerRegistry(NodeHandlerRegistry registry);
 }