FileDocCategorySizeDatePackage
ReverseAxesWalker.javaAPI DocJava SE 6 API5863Tue Jun 10 00:23:14 BST 2008com.sun.org.apache.xpath.internal.axes

ReverseAxesWalker

public class ReverseAxesWalker extends AxesWalker
Walker for a reverse axes.
see
XPath 2.4 Predicates

Fields Summary
static final long
serialVersionUID
protected DTMAxisIterator
m_iterator
The DTM inner traversal class, that corresponds to the super axis.
Constructors Summary
ReverseAxesWalker(LocPathIterator locPathIterator, int axis)
Construct an AxesWalker using a LocPathIterator.

param
locPathIterator The location path iterator that 'owns' this walker.


                     
     
  
    super(locPathIterator, axis);
  
Methods Summary
protected voidcountProximityPosition(int i)
Count backwards one proximity position.

param
i The predicate index.

    if (i < m_proximityPositions.length)
      m_proximityPositions[i]--;
  
public voiddetach()
Detaches the walker from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.

    m_iterator = null;
    super.detach();
  
public intgetLastPos(com.sun.org.apache.xpath.internal.XPathContext xctxt)
Get the number of nodes in this node list. The function is probably ill named?

param
xctxt The XPath runtime context.
return
the number of nodes in this node list.


    int count = 0;
    AxesWalker savedWalker = wi().getLastUsedWalker();

    try
    {
      ReverseAxesWalker clone = (ReverseAxesWalker) this.clone();

      clone.setRoot(this.getRoot());

      clone.setPredicateCount(this.getPredicateCount() - 1);

      clone.setPrevWalker(null);
      clone.setNextWalker(null);
      wi().setLastUsedWalker(clone);

      // Count 'em all
      // count = 1;
      int next;

      while (DTM.NULL != (next = clone.nextNode()))
      {
        count++;
      }
    }
    catch (CloneNotSupportedException cnse)
    {

      // can't happen
    }
    finally
    {
      wi().setLastUsedWalker(savedWalker);
    }

    return count;
  
protected intgetNextNode()
Get the next node in document order on the axes.

return
the next node in document order on the axes, or null.

    if (m_foundLast)
      return DTM.NULL;

    int next = m_iterator.next();
    
    if (m_isFresh)
      m_isFresh = false;

    if (DTM.NULL == next)
      this.m_foundLast = true;

    return next;
  
protected intgetProximityPosition(int predicateIndex)
Get the current sub-context position. In order to do the reverse axes count, for the moment this re-searches the axes up to the predicate. An optimization on this is to cache the nodes searched, but, for the moment, this case is probably rare enough that the added complexity isn't worth it.

param
predicateIndex The predicate index of the proximity position.
return
The pridicate index, or -1.

    // A negative predicate index seems to occur with
    // (preceding-sibling::*|following-sibling::*)/ancestor::*[position()]/*[position()]
    // -sb
    if(predicateIndex < 0)
      return -1;
      
    int count = m_proximityPositions[predicateIndex];
      
    if (count <= 0)
    {
      AxesWalker savedWalker = wi().getLastUsedWalker();

      try
      {
        ReverseAxesWalker clone = (ReverseAxesWalker) this.clone();

        clone.setRoot(this.getRoot());

        clone.setPredicateCount(predicateIndex);

        clone.setPrevWalker(null);
        clone.setNextWalker(null);
        wi().setLastUsedWalker(clone);

        // Count 'em all
        count++;
        int next;

        while (DTM.NULL != (next = clone.nextNode()))
        {
          count++;
        }

        m_proximityPositions[predicateIndex] = count;
      }
      catch (CloneNotSupportedException cnse)
      {

        // can't happen
      }
      finally
      {
        wi().setLastUsedWalker(savedWalker);
      }
    }
    
    return count;
  
public booleanisDocOrdered()
Returns true if all the nodes in the iteration well be returned in document order. Warning: This can only be called after setRoot has been called!

return
false.

    return false;  // I think.
  
public booleanisReverseAxes()
Tells if this is a reverse axes. Overrides AxesWalker#isReverseAxes.

return
true for this class.

    return true;
  
public voidsetRoot(int root)
Set the root node of the TreeWalker. (Not part of the DOM2 TreeWalker interface).

param
root The context node of this step.

    super.setRoot(root);
    m_iterator = getDTM(root).getAxisIterator(m_axis);
    m_iterator.setStartNode(root);