Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 28266 invoked from network); 1 Mar 2008 20:24:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Mar 2008 20:24:37 -0000 Received: (qmail 37655 invoked by uid 500); 1 Mar 2008 20:24:32 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 37559 invoked by uid 500); 1 Mar 2008 20:24:32 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 37550 invoked by uid 99); 1 Mar 2008 20:24:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Mar 2008 12:24:32 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Mar 2008 20:23:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C1E5D1A9832; Sat, 1 Mar 2008 12:24:10 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080301202410.C1E5D1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 handler) + { + return handler.nodeName(getAssociatedNode()); + } } /** @@ -330,6 +365,18 @@ public void setValue(Object value, NodeHandler 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 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())); } }