/**
   * This function is used to fixup variables from QNames to stack frame indexes at stylesheet build
   * time.
   *
   * @param vars List of QNames that correspond to variables. This list should be searched backwards
   *     for the first qualified name that corresponds to the variable reference qname. The position
   *     of the QName in the vector from the start of the vector will be its position in the stack
   *     frame (but variables above the globalsTop value will need to be offset to the current stack
   *     frame).
   */
  public void fixupVariables(java.util.Vector vars, int globalsSize) {
    m_predicateIndex = -1;

    AxesWalker walker = m_firstWalker;

    while (null != walker) {
      walker.fixupVariables(vars, globalsSize);
      walker = walker.getNextWalker();
    }
  }
  /**
   * Get the analysis bits for this walker, as defined in the WalkerFactory.
   *
   * @return One of WalkerFactory#BIT_DESCENDANT, etc.
   */
  public int getAnalysisBits() {
    int bits = 0;
    if (null != m_firstWalker) {
      AxesWalker walker = m_firstWalker;

      while (null != walker) {
        int bit = walker.getAnalysisBits();
        bits |= bit;
        walker = walker.getNextWalker();
      }
    }
    return bits;
  }
  /**
   * Detaches the iterator from the set which it iterated over, releasing any computational
   * resources and placing the iterator in the INVALID state. After<code>detach</code> has been
   * invoked, calls to <code>nextNode</code> or<code>previousNode</code> will raise the exception
   * INVALID_STATE_ERR.
   */
  public void detach() {
    if (m_allowDetach) {
      AxesWalker walker = m_firstWalker;
      while (null != walker) {
        walker.detach();
        walker = walker.getNextWalker();
      }

      m_lastUsedWalker = null;

      // Always call the superclass detach last!
      super.detach();
    }
  }
  /** @see Expression#deepEquals(Expression) */
  public boolean deepEquals(Expression expr) {
    if (!super.deepEquals(expr)) return false;

    AxesWalker walker1 = m_firstWalker;
    AxesWalker walker2 = ((WalkingIterator) expr).m_firstWalker;
    while ((null != walker1) && (null != walker2)) {
      if (!walker1.deepEquals(walker2)) return false;
      walker1 = walker1.getNextWalker();
      walker2 = walker2.getNextWalker();
    }

    if ((null != walker1) || (null != walker2)) return false;

    return true;
  }
Beispiel #5
0
  /**
   * Moves the <code>TreeWalker</code> to the next visible node in document order relative to the
   * current node, and returns the new node. If the current node has no next node, or if the search
   * for nextNode attempts to step upward from the TreeWalker's root node, returns <code>null</code>
   * , and retains the current node.
   *
   * @return The new node, or <code>null</code> if the current node has no next node in the
   *     TreeWalker's logical view.
   */
  public int nextNode() {
    int nextNode = DTM.NULL;
    AxesWalker walker = wi().getLastUsedWalker();

    while (true) {
      if (null == walker) break;

      nextNode = walker.getNextNode();

      if (DTM.NULL == nextNode) {

        walker = walker.m_prevWalker;
      } else {
        if (walker.acceptNode(nextNode) != DTMIterator.FILTER_ACCEPT) {
          continue;
        }

        if (null == walker.m_nextWalker) {
          wi().setLastUsedWalker(walker);

          // return walker.returnNextNode(nextNode);
          break;
        } else {
          AxesWalker prev = walker;

          walker = walker.m_nextWalker;

          walker.setRoot(nextNode);

          walker.m_prevWalker = prev;

          continue;
        }
      } // if(null != nextNode)
    } // while(null != walker)

    return nextNode;
  }
Beispiel #6
0
  /**
   * Do a deep clone of this walker, including next and previous walkers. If the this AxesWalker is
   * on the clone list, don't clone but return the already cloned version.
   *
   * @param cloneOwner non-null reference to the cloned location path iterator to which this clone
   *     will be added.
   * @param cloneList non-null vector of sources in odd elements, and the corresponding clones in
   *     even vectors.
   * @return non-null clone, which may be a new clone, or may be a clone contained on the cloneList.
   */
  AxesWalker cloneDeep(WalkingIterator cloneOwner, Vector cloneList)
      throws CloneNotSupportedException {
    AxesWalker clone = findClone(this, cloneList);
    if (null != clone) return clone;
    clone = (AxesWalker) this.clone();
    clone.setLocPathIterator(cloneOwner);
    if (null != cloneList) {
      cloneList.addElement(this);
      cloneList.addElement(clone);
    }

    if (wi().m_lastUsedWalker == this) cloneOwner.m_lastUsedWalker = clone;

    if (null != m_nextWalker) clone.m_nextWalker = m_nextWalker.cloneDeep(cloneOwner, cloneList);

    // If you don't check for the cloneList here, you'll go into an
    // recursive infinate loop.
    if (null != cloneList) {
      if (null != m_prevWalker) clone.m_prevWalker = m_prevWalker.cloneDeep(cloneOwner, cloneList);
    } else {
      if (null != m_nextWalker) clone.m_nextWalker.m_prevWalker = clone;
    }
    return clone;
  }
Beispiel #7
0
  /**
   * Get the index of the last node that can be itterated to.
   *
   * @param xctxt XPath runtime context.
   * @return the index of the last node that can be itterated to.
   */
  public int getLastPos(XPathContext xctxt) {

    int pos = getProximityPosition();

    AxesWalker walker;

    try {
      walker = (AxesWalker) clone();
    } catch (CloneNotSupportedException cnse) {
      return -1;
    }

    walker.setPredicateCount(walker.getPredicateCount() - 1);
    walker.setNextWalker(null);
    walker.setPrevWalker(null);

    WalkingIterator lpi = wi();
    AxesWalker savedWalker = lpi.getLastUsedWalker();

    try {
      lpi.setLastUsedWalker(walker);

      int next;

      while (DTM.NULL != (next = walker.nextNode())) {
        pos++;
      }

      // TODO: Should probably save this in the iterator.
    } finally {
      lpi.setLastUsedWalker(savedWalker);
    }

    // System.out.println("pos: "+pos);
    return pos;
  }
Beispiel #8
0
 /**
  * Detaches the walker from the set which it iterated over, releasing any computational resources
  * and placing the iterator in the INVALID state.
  */
 public void detach() {
   m_iterator = null;
   super.detach();
 }
Beispiel #9
0
 /**
  * Set the root node of the TreeWalker. (Not part of the DOM2 TreeWalker interface).
  *
  * @param root The context node of this step.
  */
 public void setRoot(int root) {
   super.setRoot(root);
   m_iterator = getDTM(root).getAxisIterator(m_axis);
   m_iterator.setStartNode(root);
 }