commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject svn commit: r158299 - in jakarta/commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java test/org/apache/commons/jxpath/ri/model/MixedModelTest.java
Date Sun, 20 Mar 2005 04:25:14 GMT
Author: dmitri
Date: Sat Mar 19 20:25:13 2005
New Revision: 158299

URL: http://svn.apache.org/viewcvs?view=rev&rev=158299
Log:
Fixed Scott Heaberlin's StackOverflow bug.

Modified:
    jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
    jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java

Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java?view=diff&r1=158298&r2=158299
==============================================================================
--- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
(original)
+++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
Sat Mar 19 20:25:13 2005
@@ -19,8 +19,11 @@
 
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathIntrospector;
+import org.apache.commons.jxpath.ri.Compiler;
 import org.apache.commons.jxpath.ri.QName;
+import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
 import org.apache.commons.jxpath.ri.compiler.NodeTest;
+import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
 import org.apache.commons.jxpath.ri.model.NodeIterator;
 import org.apache.commons.jxpath.ri.model.NodePointer;
 import org.apache.commons.jxpath.util.ValueUtils;
@@ -196,10 +199,22 @@
         return getValuePointer().namespacePointer(namespace);
     }
 
-    public boolean testNode(NodeTest nodeTest) {
-//        if (index
-        /** @todo: infinite loop here */
-        return getValuePointer().testNode(nodeTest);
+    public boolean testNode(NodeTest test) {
+        if (index == WHOLE_COLLECTION) {
+            if (test == null) {
+                return true;
+            }
+            else if (test instanceof NodeNameTest) {
+                return false;
+            }
+            else if (test instanceof NodeTypeTest) {
+                if (((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE) {
+                    return true;
+                }
+            }
+            return false;
+        }
+        return getValuePointer().testNode(test);
     }
 
     public int compareChildNodePointers(

Modified: jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java?view=diff&r1=158298&r2=158299
==============================================================================
--- jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java
(original)
+++ jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java
Sat Mar 19 20:25:13 2005
@@ -529,4 +529,35 @@
             new Integer(4),
             "/matrix[1]/.[1]");
     }
+    
+    /**
+     * Scott Heaberlin's test - collection of collections
+     */
+    public void testCollectionPointer() {
+        List list = new ArrayList();
+        Map map = new HashMap();
+        map.put("KeyOne", "SomeStringOne");
+        map.put("KeyTwo", "SomeStringTwo");
+        
+        Map map2 = new HashMap();
+        map2.put("KeyA", "StringA");
+        map2.put("KeyB", "StringB");
+        
+        map.put("KeyThree", map2);
+        list.add(map);
+        
+        List list2 = new ArrayList();
+        list2.add("foo");
+        list2.add(map);
+        list2.add(map);
+        list.add(list2);
+        
+        context = JXPathContext.newContext(list);
+        
+        assertEquals("SomeStringOne", context.getValue(".[1]/KeyOne"));
+        assertEquals("StringA", context.getValue(".[1]/KeyThree/KeyA"));
+        assertEquals(new Integer(3), context.getValue("size(.[1]/KeyThree)"));
+        assertEquals(new Double(6.0), context.getValue("count(.[1]/KeyThree/*)"));
+        assertEquals(new Double(3.0), context.getValue("count(.[1]/KeyThree/KeyA)"));
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message