use of org.apache.xpath.axes.AxesWalker in project robovm by robovm.
the class RedundentExprEliminator method changePartToRef.
/**
* Change a given number of steps to a single variable reference.
*
* @param uniquePseudoVarName The name of the variable reference.
* @param wi The walking iterator that is to be changed.
* @param numSteps The number of steps to be changed.
* @param isGlobal true if this will be a global reference.
*/
protected LocPathIterator changePartToRef(final QName uniquePseudoVarName, WalkingIterator wi, final int numSteps, final boolean isGlobal) {
Variable var = new Variable();
var.setQName(uniquePseudoVarName);
var.setIsGlobal(isGlobal);
if (isGlobal) {
ElemTemplateElement elem = getElemFromExpression(wi);
StylesheetRoot root = elem.getStylesheetRoot();
Vector vars = root.getVariablesAndParamsComposed();
var.setIndex(vars.size() - 1);
}
// Walk to the first walker after the one's we are replacing.
AxesWalker walker = wi.getFirstWalker();
for (int i = 0; i < numSteps; i++) {
assertion(null != walker, "Walker should not be null!");
walker = walker.getNextWalker();
}
if (null != walker) {
FilterExprWalker few = new FilterExprWalker(wi);
few.setInnerExpression(var);
few.exprSetParent(wi);
few.setNextWalker(walker);
walker.setPrevWalker(few);
wi.setFirstWalker(few);
return wi;
} else {
FilterExprIteratorSimple feis = new FilterExprIteratorSimple(var);
feis.exprSetParent(wi.exprGetParent());
return feis;
}
}
use of org.apache.xpath.axes.AxesWalker in project robovm by robovm.
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;
}
use of org.apache.xpath.axes.AxesWalker in project robovm by robovm.
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;
}
use of org.apache.xpath.axes.AxesWalker in project j2objc by google.
the class RedundentExprEliminator method changePartToRef.
/**
* Change a given number of steps to a single variable reference.
*
* @param uniquePseudoVarName The name of the variable reference.
* @param wi The walking iterator that is to be changed.
* @param numSteps The number of steps to be changed.
* @param isGlobal true if this will be a global reference.
*/
protected LocPathIterator changePartToRef(final QName uniquePseudoVarName, WalkingIterator wi, final int numSteps, final boolean isGlobal) {
Variable var = new Variable();
var.setQName(uniquePseudoVarName);
var.setIsGlobal(isGlobal);
if (isGlobal) {
ElemTemplateElement elem = getElemFromExpression(wi);
StylesheetRoot root = elem.getStylesheetRoot();
Vector vars = root.getVariablesAndParamsComposed();
var.setIndex(vars.size() - 1);
}
// Walk to the first walker after the one's we are replacing.
AxesWalker walker = wi.getFirstWalker();
for (int i = 0; i < numSteps; i++) {
assertion(null != walker, "Walker should not be null!");
walker = walker.getNextWalker();
}
if (null != walker) {
FilterExprWalker few = new FilterExprWalker(wi);
few.setInnerExpression(var);
few.exprSetParent(wi);
few.setNextWalker(walker);
walker.setPrevWalker(few);
wi.setFirstWalker(few);
return wi;
} else {
FilterExprIteratorSimple feis = new FilterExprIteratorSimple(var);
feis.exprSetParent(wi.exprGetParent());
return feis;
}
}
use of org.apache.xpath.axes.AxesWalker in project j2objc by google.
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;
}
Aggregations