Search in sources :

Example 6 with AxesWalker

use of org.apache.xpath.axes.AxesWalker in project j2objc by google.

the class RedundentExprEliminator method countSteps.

/**
   * Count the steps in a given location path.
   * 
   * @param lpi The location path iterator that owns the steps.
   * @return The number of steps in the given location path.
   */
protected int countSteps(LocPathIterator lpi) {
    if (lpi instanceof WalkingIterator) {
        WalkingIterator wi = (WalkingIterator) lpi;
        AxesWalker aw = wi.getFirstWalker();
        int count = 0;
        while (null != aw) {
            count++;
            aw = aw.getNextWalker();
        }
        return count;
    } else
        return 1;
}
Also used : AxesWalker(org.apache.xpath.axes.AxesWalker) WalkingIterator(org.apache.xpath.axes.WalkingIterator)

Example 7 with AxesWalker

use of org.apache.xpath.axes.AxesWalker in project j2objc by google.

the class RedundentExprEliminator method createIteratorFromSteps.

/**
   * Create a new WalkingIterator from the steps in another WalkingIterator.
   * 
   * @param wi The iterator from where the steps will be taken.
   * @param numSteps The number of steps from the first to copy into the new 
   *                 iterator.
   * @return The new iterator.
   */
protected WalkingIterator createIteratorFromSteps(final WalkingIterator wi, int numSteps) {
    WalkingIterator newIter = new WalkingIterator(wi.getPrefixResolver());
    try {
        AxesWalker walker = (AxesWalker) wi.getFirstWalker().clone();
        newIter.setFirstWalker(walker);
        walker.setLocPathIterator(newIter);
        for (int i = 1; i < numSteps; i++) {
            AxesWalker next = (AxesWalker) walker.getNextWalker().clone();
            walker.setNextWalker(next);
            next.setLocPathIterator(newIter);
            walker = next;
        }
        walker.setNextWalker(null);
    } catch (CloneNotSupportedException cnse) {
        throw new WrappedRuntimeException(cnse);
    }
    return newIter;
}
Also used : AxesWalker(org.apache.xpath.axes.AxesWalker) WalkingIterator(org.apache.xpath.axes.WalkingIterator) WrappedRuntimeException(org.apache.xml.utils.WrappedRuntimeException)

Example 8 with AxesWalker

use of org.apache.xpath.axes.AxesWalker in project robovm by robovm.

the class RedundentExprEliminator method stepsEqual.

/**
   * Compare a given number of steps between two iterators, to see if they are equal.
   * 
   * @param iter1 The first iterator to compare.
   * @param iter2 The second iterator to compare.
   * @param numSteps The number of steps to compare.
   * @return true If the given number of steps are equal.
   * 
   */
protected boolean stepsEqual(WalkingIterator iter1, WalkingIterator iter2, int numSteps) {
    AxesWalker aw1 = iter1.getFirstWalker();
    AxesWalker aw2 = iter2.getFirstWalker();
    for (int i = 0; (i < numSteps); i++) {
        if ((null == aw1) || (null == aw2))
            return false;
        if (!aw1.deepEquals(aw2))
            return false;
        aw1 = aw1.getNextWalker();
        aw2 = aw2.getNextWalker();
    }
    assertion((null != aw1) || (null != aw2), "Total match is incorrect!");
    return true;
}
Also used : AxesWalker(org.apache.xpath.axes.AxesWalker)

Aggregations

AxesWalker (org.apache.xpath.axes.AxesWalker)8 WalkingIterator (org.apache.xpath.axes.WalkingIterator)4 Vector (java.util.Vector)2 WrappedRuntimeException (org.apache.xml.utils.WrappedRuntimeException)2 FilterExprIteratorSimple (org.apache.xpath.axes.FilterExprIteratorSimple)2 FilterExprWalker (org.apache.xpath.axes.FilterExprWalker)2 Variable (org.apache.xpath.operations.Variable)2