示例#1
0
  /**
   * 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.
   */
  public int getLastPos(XPathContext xctxt) {

    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;
  }
示例#2
0
  /**
   * 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.
   */
  protected int getProximityPosition(int predicateIndex) {
    // 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;
  }