commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r632655 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/expr/NodeList.java test/java/org/apache/commons/configuration2/expr/TestNodeList.java
Date Sat, 01 Mar 2008 20:24:10 GMT
Author: oheger
Date: Sat Mar  1 12:24:06 2008
New Revision: 632655

URL: http://svn.apache.org/viewvc?rev=632655&view=rev
Log:
Added a getName() method to NodeList

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeList.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeList.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeList.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeList.java?rev=632655&r1=632654&r2=632655&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeList.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeList.java
Sat Mar  1 12:24:06 2008
@@ -111,6 +111,21 @@
     }
 
     /**
+     * Returns the name of the element at the specified index. If the element is
+     * a node, the node name is returned. For an attribute the attribute name is
+     * returned.
+     *
+     * @param index the index
+     * @param handler the node handler
+     * @return the name of the element at this index
+     * @throws IndexOutOfBoundsException if the index is invalid
+     */
+    public String getName(int index, NodeHandler<T> handler)
+    {
+        return element(index).getName(handler);
+    }
+
+    /**
      * Returns the value of the element at the specified index. This method
      * works for both nodes and attributes.
      *
@@ -198,6 +213,14 @@
         public abstract boolean isNode();
 
         /**
+         * Returns the name of this list element.
+         *
+         * @param handler the node handler
+         * @return the name of this list element
+         */
+        public abstract String getName(NodeHandler<T> handler);
+
+        /**
          * Obtains the value from this list element.
          *
          * @param handler the node handler
@@ -274,6 +297,18 @@
         {
             handler.setValue(getAssociatedNode(), value);
         }
+
+        /**
+         * Returns the name of the represented node.
+         *
+         * @param handler the node handler
+         * @return the name of this node
+         */
+        @Override
+        public String getName(NodeHandler<T> handler)
+        {
+            return handler.nodeName(getAssociatedNode());
+        }
     }
 
     /**
@@ -330,6 +365,18 @@
         public void setValue(Object value, NodeHandler<T> handler)
         {
             handler.setAttributeValue(getAssociatedNode(), name, value);
+        }
+
+        /**
+         * Returns the name of the represented attribute.
+         *
+         * @param handler the node handler
+         * @return the name of this attribute
+         */
+        @Override
+        public String getName(NodeHandler<T> handler)
+        {
+            return name;
         }
     }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeList.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeList.java?rev=632655&r1=632654&r2=632655&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeList.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeList.java
Sat Mar  1 12:24:06 2008
@@ -34,6 +34,9 @@
     /** Constant for a test value. */
     private static final String VALUE = "test";
 
+    /** Constant for a test name.*/
+    private static final String NAME = "testName";
+
     /** Constant for the number of test nodes. */
     private static final int COUNT = 10;
 
@@ -169,5 +172,27 @@
         {
             // ok
         }
+    }
+
+    /**
+     * Tests querying the name of a node.
+     */
+    public void testGetNameNode()
+    {
+        ConfigurationNode node = new DefaultConfigurationNode(NAME);
+        list.addNode(node);
+        assertEquals("Wrong node name", NAME, list.getName(0,
+                new ConfigurationNodeHandler()));
+    }
+
+    /**
+     * Tests querying the name of an attribute.
+     */
+    public void testGetNameAttribute()
+    {
+        ConfigurationNode parent = new DefaultConfigurationNode();
+        list.addAttribute(parent, NAME);
+        assertEquals("Wrong attribute name", NAME, list.getName(0,
+                new ConfigurationNodeHandler()));
     }
 }



Mime
View raw message