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/java/org/apache/commons/jxpath/ri/axes PredicateContext.java
Date Sat, 12 Oct 2002 21:02:25 GMT
dmitri      2002/10/12 14:02:25

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
                        PropertyIterator.java BeanPropertyPointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri/axes
                        PredicateContext.java
  Log:
  Fixed bugs in iteratePointers() when iterating over a scalar value
  
  Revision  Changes    Path
  1.5       +7 -4      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java
  
  Index: PropertyIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PropertyIterator.java	16 Jun 2002 03:22:22 -0000	1.4
  +++ PropertyIterator.java	12 Oct 2002 21:02:24 -0000	1.5
  @@ -104,6 +104,9 @@
               }
               this.startPropertyIndex = ((PropertyPointer)startWith).getPropertyIndex();
               this.startIndex = startWith.getIndex();
  +            if (this.startIndex == NodePointer.WHOLE_COLLECTION){
  +                this.startIndex = 0;
  +            }
               this.includeStart = false;
               if (reverse && startIndex == -1){
                   this.includeStart = true;
  
  
  
  1.8       +17 -18    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java
  
  Index: BeanPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BeanPropertyPointer.java	10 Aug 2002 16:13:04 -0000	1.7
  +++ BeanPropertyPointer.java	12 Oct 2002 21:02:24 -0000	1.8
  @@ -165,8 +165,12 @@
   
       public void setIndex(int index){
           if (this.index != index){
  -            super.setIndex(index);
  -            value = UNINITIALIZED;
  +            // When dealing with a scalar, index == 0 is equivalent to
  +            // WHOLE_COLLECTION, so do not change it.
  +            if (this.index != WHOLE_COLLECTION || index != 0 || isCollection()){
  +                super.setIndex(index);
  +                value = UNINITIALIZED;
  +            }
           }
       }
   
  @@ -178,20 +182,15 @@
        */
       public Object getNode(){
           if (value == UNINITIALIZED){
  -            PropertyDescriptor pd = getPropertyDescriptor();
  -            if (pd == null){
  -                value = null;
  +            Object baseValue = getBaseValue();
  +            if (index == WHOLE_COLLECTION){
  +                value = baseValue;
  +            }
  +            else if (value != null && index >= 0 && index < getLength()){
  +                value = ValueUtils.getValue(baseValue, index);
               }
               else {
  -                if (index == WHOLE_COLLECTION){
  -                    value = ValueUtils.getValue(getBean(), pd);
  -                }
  -                else if (index >= 0 && index < getLength()){
  -                    value = ValueUtils.getValue(getBean(), pd, index);
  -                }
  -                else {
  -                    value = null;
  -                }
  +                value = null;
               }
           }
           return value;
  
  
  
  1.14      +13 -5     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- PredicateContext.java	10 Aug 2002 16:13:03 -0000	1.13
  +++ PredicateContext.java	12 Oct 2002 21:02:24 -0000	1.14
  @@ -61,7 +61,7 @@
    */
   package org.apache.commons.jxpath.ri.axes;
   
  -
  +import java.util.Iterator;
   import org.apache.commons.jxpath.ri.EvalContext;
   import org.apache.commons.jxpath.ri.compiler.CoreOperation;
   import org.apache.commons.jxpath.ri.compiler.Expression;
  @@ -109,9 +109,17 @@
               }
               else {
                   Object pred = expression.computeValue(parentContext);
  +                if (pred instanceof Iterator){
  +                    if (!((Iterator)pred).hasNext()){
  +                        return false;
  +                    }
  +                    pred = ((Iterator)pred).next();
  +                }
  +
                   if (pred instanceof NodePointer){
                       pred = ((NodePointer)pred).getNode();
                   }
  +
                   if (pred instanceof Number){
                       int pos = (int)InfoSetUtil.doubleValue(pred);
                       position++;
  
  
  

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


Mime
View raw message