Ejemplo n.º 1
0
  /**
   * Returns the next node in the set and advances the position of the iterator in the set. After a
   * NodeIterator is created, the first call to nextNode() returns the first node in the set.
   *
   * @return The next <code>Node</code> in the set being iterated over, or <code>null</code> if
   *     there are no more members in that set.
   */
  public int nextNode() {
    if (m_foundLast) return DTM.NULL;

    // If the variable stack position is not -1, we'll have to
    // set our position in the variable stack, so our variable access
    // will be correct.  Iterators that are at the top level of the
    // expression need to reset the variable stack, while iterators
    // in predicates do not need to, and should not, since their execution
    // may be much later than top-level iterators.
    // m_varStackPos is set in setRoot, which is called
    // from the execute method.
    if (-1 == m_stackFrame) {
      return returnNextNode(m_firstWalker.nextNode());
    } else {
      VariableStack vars = m_execContext.getVarStack();

      // These three statements need to be combined into one operation.
      int savedStart = vars.getStackFrame();

      vars.setStackFrame(m_stackFrame);

      int n = returnNextNode(m_firstWalker.nextNode());

      // These two statements need to be combined into one operation.
      vars.setStackFrame(savedStart);

      return n;
    }
  }
 /*     */ public int nextNode() /*     */ {
   /* 137 */ if (this.m_foundLast)
   /*     */ {
     /* 139 */ this.m_lastFetched = -1;
     /* 140 */ return -1;
     /*     */ }
   /*     */
   /* 143 */ if (-1 == this.m_lastFetched)
   /*     */ {
     /* 145 */ resetProximityPositions();
     /*     */ }
   /*     */ VariableStack vars;
   /*     */ int savedStart;
   /* 152 */ if (-1 != this.m_stackFrame)
   /*     */ {
     /* 154 */ VariableStack vars = this.m_execContext.getVarStack();
     /*     */
     /* 157 */ int savedStart = vars.getStackFrame();
     /*     */
     /* 159 */ vars.setStackFrame(this.m_stackFrame);
     /*     */ }
   /*     */ else
   /*     */ {
     /* 164 */ vars = null;
     /* 165 */ savedStart = 0;
     /*     */ }
   /*     */ try
   /*     */ {
     /*     */ int next;
     /*     */ do
     /*     */ {
       /* 172 */ next = getNextNode();
       /*     */ }
     /* 174 */ while ((-1 != next) && /* 176 */ (1 != acceptNode(next)) && /* 184 */ (next != -1));
     /*     */ int i;
     /* 186 */ if (-1 != next)
     /*     */ {
       /* 188 */ this.m_pos += 1;
       /* 189 */ return next;
       /*     */ }
     /*     */
     /* 193 */ this.m_foundLast = true;
     /*     */
     /* 195 */ return -1;
     /*     */ }
   /*     */ finally
   /*     */ {
     /* 200 */ if (-1 != this.m_stackFrame)
     /*     */ {
       /* 203 */ vars.setStackFrame(savedStart);
       /*     */ }
     /*     */ }
   /*     */ }
  /**
   * Returns the next node in the set and advances the position of the iterator in the set. After a
   * NodeIterator is created, the first call to nextNode() returns the first node in the set.
   *
   * @return The next <code>Node</code> in the set being iterated over, or <code>null</code> if
   *     there are no more members in that set.
   */
  public int nextNode() {
    if (m_foundLast) return DTM.NULL;

    int next;

    com.sun.org.apache.xpath.internal.VariableStack vars;
    int savedStart;
    if (-1 != m_stackFrame) {
      vars = m_execContext.getVarStack();

      // These three statements need to be combined into one operation.
      savedStart = vars.getStackFrame();

      vars.setStackFrame(m_stackFrame);
    } else {
      // Yuck.  Just to shut up the compiler!
      vars = null;
      savedStart = 0;
    }

    try {
      if (DEBUG) System.out.println("m_pattern" + m_pattern.toString());

      do {
        next = getNextNode();

        if (DTM.NULL != next) {
          if (DTMIterator.FILTER_ACCEPT == acceptNode(next, m_execContext)) break;
          else continue;
        } else break;
      } while (next != DTM.NULL);

      if (DTM.NULL != next) {
        if (DEBUG) {
          System.out.println("next: " + next);
          System.out.println("name: " + m_cdtm.getNodeName(next));
        }
        incrementCurrentPos();

        return next;
      } else {
        m_foundLast = true;

        return DTM.NULL;
      }
    } finally {
      if (-1 != m_stackFrame) {
        // These two statements need to be combined into one operation.
        vars.setStackFrame(savedStart);
      }
    }
  }