commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r637457 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/expr/xpath/ test/java/org/apache/commons/configuration2/expr/xpath/
Date Sat, 15 Mar 2008 20:09:32 GMT
Author: oheger
Date: Sat Mar 15 13:09:31 2008
New Revision: 637457

URL: http://svn.apache.org/viewvc?rev=637457&view=rev
Log:
ConfigurationAttributePointer now returns a proxy node for the represented attribute. This
allows the XPATH expression engine to correctly detect attribute nodes.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/xpath/ConfigurationAttributePointer.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/xpath/TestConfigurationAttributePointer.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/xpath/ConfigurationAttributePointer.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/xpath/ConfigurationAttributePointer.java?rev=637457&r1=637456&r2=637457&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/xpath/ConfigurationAttributePointer.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/xpath/ConfigurationAttributePointer.java
Sat Mar 15 13:09:31 2008
@@ -100,14 +100,14 @@
     }
 
     /**
-     * Returns the immediate node. We return the parent node here.
+     * Returns the immediate node. This is a proxy for an attribute node.
      *
      * @return the immediate node
      */
     @Override
     public Object getImmediateNode()
     {
-        return parentNode;
+        return new AttributeNodeProxy();
     }
 
     /**
@@ -217,5 +217,35 @@
     protected NodeHandler<T> getNodeHandler()
     {
         return getParentPointer().getNodeHandler();
+    }
+
+    /**
+     * A simple class that represents an attribute node. Attributes are not
+     * necessarily modeled as nodes in all object models. So we introduce this
+     * wrapper class for representing an attribute node. This class is detected
+     * by the XPath query engine and handled correspondingly.
+     */
+    class AttributeNodeProxy
+    {
+        /**
+         * Returns the parent node. This is the node to which the represented
+         * attribute belongs.
+         *
+         * @return the parent node
+         */
+        public T getParentNode()
+        {
+            return getParentPointer().getConfigurationNode();
+        }
+
+        /**
+         * Returns the name of this attribute.
+         *
+         * @return the attribute name
+         */
+        public String getAttributeName()
+        {
+            return attributeName;
+        }
     }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/xpath/TestConfigurationAttributePointer.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/xpath/TestConfigurationAttributePointer.java?rev=637457&r1=637456&r2=637457&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/xpath/TestConfigurationAttributePointer.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/xpath/TestConfigurationAttributePointer.java
Sat Mar 15 13:09:31 2008
@@ -80,12 +80,22 @@
     }
 
     /**
-     * Tests querying the immediate node.
+     * Tests querying the immediate node. Here a proxy for an attribute node
+     * should be returned.
      */
+    @SuppressWarnings("unchecked")
     public void testGetImmediateNode()
     {
-        assertEquals("Wrong immediate node", parent.getConfigurationNode(),
-                pointer.getImmediateNode());
+        Object node = pointer.getImmediateNode();
+        assertTrue(
+                "Wrong node class",
+                node instanceof ConfigurationAttributePointer.AttributeNodeProxy);
+        ConfigurationAttributePointer<ConfigurationNode>.AttributeNodeProxy proxy =
+            (ConfigurationAttributePointer.AttributeNodeProxy) node;
+        assertEquals("Wrong parent node", parent.getConfigurationNode(), proxy
+                .getParentNode());
+        assertEquals("Wrong attribute name", ATTR_NAME, proxy
+                .getAttributeName());
     }
 
     /**



Mime
View raw message