commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic DynamicPropertiesModelTest.java
Date Tue, 06 May 2003 02:13:27 GMT
dmitri      2003/05/05 19:13:27

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri/axes
                        PredicateContext.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic
                        DynamicPropertiesModelTest.java
  Log:
  Fixed problem with collection of maps
  
  Revision  Changes    Path
  1.20      +26 -11    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java
  
  Index: PredicateContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- PredicateContext.java	25 Mar 2003 02:41:34 -0000	1.19
  +++ PredicateContext.java	6 May 2003 02:13:26 -0000	1.20
  @@ -99,14 +99,29 @@
           while (parentContext.nextNode()) {
               if (setupDynamicPropertyPointer()) {
                   Object pred = nameTestExpression.computeValue(parentContext);
  -                if (pred instanceof NodePointer) {
  -                    pred = ((NodePointer) pred).getValue();
  +                String propertyName = InfoSetUtil.stringValue(pred);
  +
  +                // At this point it would be nice to say: 
  +                // dynamicPropertyPointer.setPropertyName(propertyName)
  +                // and then: dynamicPropertyPointer.isActual().
  +                // However some PropertyPointers, e.g. DynamicPropertyPointer
  +                // will declare that any property you ask for is actual.
  +                // That's not acceptable for us: we really need to know
  +                // if the property is currently declared. Thus,
  +                // we'll need to perform a search.
  +                boolean ok = false;
  +                String names[] = dynamicPropertyPointer.getPropertyNames();
  +                for (int i = 0; i < names.length; i++) {
  +                    if (names[i].equals(propertyName)) {
  +                        ok = true;
  +                        break;
  +                    }
  +                }
  +                if (ok) {
  +                    dynamicPropertyPointer.setPropertyName(propertyName);
  +                    position++;
  +                    return true;
                   }
  -                dynamicPropertyPointer.setPropertyName(
  -                    InfoSetUtil.stringValue(pred));
  -                position = 1;
  -                done = true;
  -                return true;
               }
               else {
                   Object pred = expression.computeValue(parentContext);
  
  
  
  1.4       +38 -4     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.java
  
  Index: DynamicPropertiesModelTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicPropertiesModelTest.java	11 Mar 2003 00:59:39 -0000	1.3
  +++ DynamicPropertiesModelTest.java	6 May 2003 02:13:27 -0000	1.4
  @@ -62,6 +62,11 @@
   
   package org.apache.commons.jxpath.ri.model.dynamic;
   
  +import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.util.List;
  +import java.util.Map;
  +
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.JXPathTestCase;
   import org.apache.commons.jxpath.TestBean;
  @@ -322,5 +327,34 @@
               "Remove dynamic property collection element",
               "temp2",
               context.getValue("map[@name = 'TestKey2'][1]"));
  +    }
  +    
  +    public void testCollectionOfMaps() {
  +        TestBean bean = (TestBean) context.getContextBean();
  +        List list = new ArrayList();
  +
  +        bean.getMap().put("stuff", list);        
  +
  +        Map m = new HashMap();
  +        m.put("fruit", "apple");
  +        list.add(m);
  +
  +        m = new HashMap();
  +        m.put("berry", "watermelon");
  +        list.add(m);
  +
  +        m = new HashMap();
  +        m.put("fruit", "banana");
  +        list.add(m);
  +
  +        assertXPathValueIterator(
  +            context,
  +            "/map/stuff/fruit",
  +            list("apple", "banana"));
  +
  +        assertXPathValueIterator(
  +            context,
  +            "/map/stuff[@name='fruit']",
  +            list("apple", "banana"));
       }
   }
  
  
  

---------------------------------------------------------------------
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