You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by il...@apache.org on 2002/11/13 23:08:21 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath/axes OneStepIterator.java

ilene       2002/11/13 14:08:21

  Modified:    java/src/org/apache/xpath/axes OneStepIterator.java
  Log:
  Committing Gordon Chiu's (grchiu@ca.ibm.com) patches for bugzilla #14365, 14368.
  
  Fixes for processing of last()  function.
  
  Revision  Changes    Path
  1.9       +57 -0     xml-xalan/java/src/org/apache/xpath/axes/OneStepIterator.java
  
  Index: OneStepIterator.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/OneStepIterator.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- OneStepIterator.java	22 Mar 2002 01:04:43 -0000	1.8
  +++ OneStepIterator.java	13 Nov 2002 22:08:21 -0000	1.9
  @@ -196,6 +196,63 @@
     }
   
     /**
  +   *  The number of nodes in the list. The range of valid child node indices
  +   * is 0 to <code>length-1</code> inclusive.
  +   *
  +   * @return The number of nodes in the list, always greater or equal to zero.
  +   */
  +  public int getLength()
  +  {
  +    if(!isReverseAxes())
  +      return super.getLength();
  +      
  +    // Tell if this is being called from within a predicate.
  +    boolean isPredicateTest = (this == m_execContext.getSubContextList());
  +
  +    // And get how many total predicates are part of this step.
  +    int predCount = getPredicateCount();
  +   
  +    // If we have already calculated the length, and the current predicate 
  +    // is the first predicate, then return the length.  We don't cache 
  +    // the anything but the length of the list to the first predicate.
  +    if (-1 != m_length && isPredicateTest && m_predicateIndex < 1)
  +       return m_length;      
  +
  +    int count = 0;
  +    
  +    XPathContext xctxt = getXPathContext();
  +    try
  +    {
  +      OneStepIterator clone = (OneStepIterator) this.cloneWithReset();
  +      
  +      int root = getRoot();
  +      xctxt.pushCurrentNode(root);
  +      clone.setRoot(root, xctxt);
  + 
  +      clone.m_predCount = m_predicateIndex;
  +
  +      int next;
  +
  +      while (DTM.NULL != (next = clone.nextNode()))
  +      {
  +        count++;
  +      }
  +    }
  +    catch (CloneNotSupportedException cnse)
  +    {
  +       // can't happen
  +    }
  +    finally
  +    {
  +      xctxt.popCurrentNode();
  +    }
  +    if (isPredicateTest && m_predicateIndex < 1)
  +      m_length = count;    
  +      
  +    return count;
  +  }
  +
  +  /**
      * Count backwards one proximity position.
      *
      * @param i The predicate index.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org