use of org.apache.xpath.axes.LocPathIterator in project j2objc by google.
the class RedundentExprEliminator method matchAndEliminatePartialPaths.
/**
* For a given path, see if there are any partitial matches in the list,
* and, if there are, replace those partial paths with psuedo variable refs,
* and create the psuedo variable decl.
*
* @return The head of the list, which may have changed.
*/
protected MultistepExprHolder matchAndEliminatePartialPaths(MultistepExprHolder testee, MultistepExprHolder head, boolean isGlobal, int lengthToTest, ElemTemplateElement varScope) {
if (null == testee.m_exprOwner)
return head;
// Start with the longest possible match, and move down.
WalkingIterator iter1 = (WalkingIterator) testee.m_exprOwner.getExpression();
if (partialIsVariable(testee, lengthToTest))
return head;
MultistepExprHolder matchedPaths = null;
MultistepExprHolder matchedPathsTail = null;
MultistepExprHolder meh = head;
while (null != meh) {
if ((meh != testee) && (null != meh.m_exprOwner)) {
WalkingIterator iter2 = (WalkingIterator) meh.m_exprOwner.getExpression();
if (stepsEqual(iter1, iter2, lengthToTest)) {
if (null == matchedPaths) {
try {
matchedPaths = (MultistepExprHolder) testee.clone();
// So it won't be processed again.
testee.m_exprOwner = null;
} catch (CloneNotSupportedException cnse) {
}
matchedPathsTail = matchedPaths;
matchedPathsTail.m_next = null;
}
try {
matchedPathsTail.m_next = (MultistepExprHolder) meh.clone();
// So it won't be processed again.
meh.m_exprOwner = null;
} catch (CloneNotSupportedException cnse) {
}
matchedPathsTail = matchedPathsTail.m_next;
matchedPathsTail.m_next = null;
}
}
meh = meh.m_next;
}
int matchCount = 0;
if (null != matchedPaths) {
ElemTemplateElement root = isGlobal ? varScope : findCommonAncestor(matchedPaths);
WalkingIterator sharedIter = (WalkingIterator) matchedPaths.m_exprOwner.getExpression();
WalkingIterator newIter = createIteratorFromSteps(sharedIter, lengthToTest);
ElemVariable var = createPseudoVarDecl(root, newIter, isGlobal);
if (DIAGNOSE_MULTISTEPLIST)
System.err.println("Created var: " + var.getName() + (isGlobal ? "(Global)" : ""));
while (null != matchedPaths) {
ExpressionOwner owner = matchedPaths.m_exprOwner;
WalkingIterator iter = (WalkingIterator) owner.getExpression();
if (DIAGNOSE_MULTISTEPLIST)
diagnoseLineNumber(iter);
LocPathIterator newIter2 = changePartToRef(var.getName(), iter, lengthToTest, isGlobal);
owner.setExpression(newIter2);
matchedPaths = matchedPaths.m_next;
}
}
if (DIAGNOSE_MULTISTEPLIST)
diagnoseMultistepList(matchCount, lengthToTest, isGlobal);
return head;
}
use of org.apache.xpath.axes.LocPathIterator in project j2objc by google.
the class RedundentExprEliminator method findAndEliminateRedundant.
/**
* Look through the vector from start point, looking for redundant occurances.
* When one or more are found, create a psuedo variable declaration, insert
* it into the stylesheet, and replace the occurance with a reference to
* the psuedo variable. When a redundent variable is found, it's slot in
* the vector will be replaced by null.
*
* @param start The position to start looking in the vector.
* @param firstOccuranceIndex The position of firstOccuranceOwner.
* @param firstOccuranceOwner The owner of the expression we are looking for.
* @param psuedoVarRecipient Where to put the psuedo variables.
*
* @return The number of expression occurances that were modified.
*/
protected int findAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException {
MultistepExprHolder head = null;
MultistepExprHolder tail = null;
int numPathsFound = 0;
int n = paths.size();
Expression expr1 = firstOccuranceOwner.getExpression();
if (DEBUG)
assertIsLocPathIterator(expr1, firstOccuranceOwner);
boolean isGlobal = (paths == m_absPaths);
LocPathIterator lpi = (LocPathIterator) expr1;
int stepCount = countSteps(lpi);
for (int j = start; j < n; j++) {
ExpressionOwner owner2 = (ExpressionOwner) paths.elementAt(j);
if (null != owner2) {
Expression expr2 = owner2.getExpression();
boolean isEqual = expr2.deepEquals(lpi);
if (isEqual) {
LocPathIterator lpi2 = (LocPathIterator) expr2;
if (null == head) {
head = new MultistepExprHolder(firstOccuranceOwner, stepCount, null);
tail = head;
numPathsFound++;
}
tail.m_next = new MultistepExprHolder(owner2, stepCount, null);
tail = tail.m_next;
// Null out the occurance, so we don't have to test it again.
paths.setElementAt(null, j);
// foundFirst = true;
numPathsFound++;
}
}
}
// Change all globals in xsl:templates, etc, to global vars no matter what.
if ((0 == numPathsFound) && isGlobal) {
head = new MultistepExprHolder(firstOccuranceOwner, stepCount, null);
numPathsFound++;
}
if (null != head) {
ElemTemplateElement root = isGlobal ? psuedoVarRecipient : findCommonAncestor(head);
LocPathIterator sharedIter = (LocPathIterator) head.m_exprOwner.getExpression();
ElemVariable var = createPseudoVarDecl(root, sharedIter, isGlobal);
if (DIAGNOSE_MULTISTEPLIST)
System.err.println("Created var: " + var.getName() + (isGlobal ? "(Global)" : ""));
QName uniquePseudoVarName = var.getName();
while (null != head) {
ExpressionOwner owner = head.m_exprOwner;
if (DIAGNOSE_MULTISTEPLIST)
diagnoseLineNumber(owner.getExpression());
changeToVarRef(uniquePseudoVarName, owner, paths, root);
head = head.m_next;
}
// Replace the first occurance with the variable's XPath, so
// that further reduction may take place if needed.
paths.setElementAt(var.getSelect(), firstOccuranceIndex);
}
return numPathsFound;
}
use of org.apache.xpath.axes.LocPathIterator in project j2objc by google.
the class RedundentExprEliminator method createMultistepExprList.
/**
* For the reduction of location path parts, create a list of all
* the multistep paths with more than one step, sorted by the
* number of steps, with the most steps occuring earlier in the list.
* If the list is only one member, don't bother returning it.
*
* @param paths Vector of ExpressionOwner objects, which may contain null entries.
* The ExpressionOwner objects must own LocPathIterator objects.
* @return null if no multipart paths are found or the list is only of length 1,
* otherwise the first MultistepExprHolder in a linked list of these objects.
*/
protected MultistepExprHolder createMultistepExprList(Vector paths) {
MultistepExprHolder first = null;
int n = paths.size();
for (int i = 0; i < n; i++) {
ExpressionOwner eo = (ExpressionOwner) paths.elementAt(i);
if (null == eo)
continue;
// Assuming location path iterators should be OK.
LocPathIterator lpi = (LocPathIterator) eo.getExpression();
int numPaths = countSteps(lpi);
if (numPaths > 1) {
if (null == first)
first = new MultistepExprHolder(eo, numPaths, null);
else
first = first.addInSortedOrder(eo, numPaths);
}
}
if ((null == first) || (first.getLength() <= 1))
return null;
else
return first;
}
use of org.apache.xpath.axes.LocPathIterator in project robovm by robovm.
the class RedundentExprEliminator method oldFindAndEliminateRedundant.
/**
* To be removed.
*/
protected int oldFindAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException {
QName uniquePseudoVarName = null;
boolean foundFirst = false;
int numPathsFound = 0;
int n = paths.size();
Expression expr1 = firstOccuranceOwner.getExpression();
if (DEBUG)
assertIsLocPathIterator(expr1, firstOccuranceOwner);
boolean isGlobal = (paths == m_absPaths);
LocPathIterator lpi = (LocPathIterator) expr1;
for (int j = start; j < n; j++) {
ExpressionOwner owner2 = (ExpressionOwner) paths.elementAt(j);
if (null != owner2) {
Expression expr2 = owner2.getExpression();
boolean isEqual = expr2.deepEquals(lpi);
if (isEqual) {
LocPathIterator lpi2 = (LocPathIterator) expr2;
if (!foundFirst) {
foundFirst = true;
// Insert variable decl into psuedoVarRecipient
// We want to insert this into the first legitimate
// position for a variable.
ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, isGlobal);
if (null == var)
return 0;
uniquePseudoVarName = var.getName();
changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
// Replace the first occurance with the variable's XPath, so
// that further reduction may take place if needed.
paths.setElementAt(var.getSelect(), firstOccuranceIndex);
numPathsFound++;
}
changeToVarRef(uniquePseudoVarName, owner2, paths, psuedoVarRecipient);
// Null out the occurance, so we don't have to test it again.
paths.setElementAt(null, j);
// foundFirst = true;
numPathsFound++;
}
}
}
// Change all globals in xsl:templates, etc, to global vars no matter what.
if ((0 == numPathsFound) && (paths == m_absPaths)) {
ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, true);
if (null == var)
return 0;
uniquePseudoVarName = var.getName();
changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
paths.setElementAt(var.getSelect(), firstOccuranceIndex);
numPathsFound++;
}
return numPathsFound;
}
use of org.apache.xpath.axes.LocPathIterator in project robovm by robovm.
the class RedundentExprEliminator method matchAndEliminatePartialPaths.
/**
* For a given path, see if there are any partitial matches in the list,
* and, if there are, replace those partial paths with psuedo variable refs,
* and create the psuedo variable decl.
*
* @return The head of the list, which may have changed.
*/
protected MultistepExprHolder matchAndEliminatePartialPaths(MultistepExprHolder testee, MultistepExprHolder head, boolean isGlobal, int lengthToTest, ElemTemplateElement varScope) {
if (null == testee.m_exprOwner)
return head;
// Start with the longest possible match, and move down.
WalkingIterator iter1 = (WalkingIterator) testee.m_exprOwner.getExpression();
if (partialIsVariable(testee, lengthToTest))
return head;
MultistepExprHolder matchedPaths = null;
MultistepExprHolder matchedPathsTail = null;
MultistepExprHolder meh = head;
while (null != meh) {
if ((meh != testee) && (null != meh.m_exprOwner)) {
WalkingIterator iter2 = (WalkingIterator) meh.m_exprOwner.getExpression();
if (stepsEqual(iter1, iter2, lengthToTest)) {
if (null == matchedPaths) {
try {
matchedPaths = (MultistepExprHolder) testee.clone();
// So it won't be processed again.
testee.m_exprOwner = null;
} catch (CloneNotSupportedException cnse) {
}
matchedPathsTail = matchedPaths;
matchedPathsTail.m_next = null;
}
try {
matchedPathsTail.m_next = (MultistepExprHolder) meh.clone();
// So it won't be processed again.
meh.m_exprOwner = null;
} catch (CloneNotSupportedException cnse) {
}
matchedPathsTail = matchedPathsTail.m_next;
matchedPathsTail.m_next = null;
}
}
meh = meh.m_next;
}
int matchCount = 0;
if (null != matchedPaths) {
ElemTemplateElement root = isGlobal ? varScope : findCommonAncestor(matchedPaths);
WalkingIterator sharedIter = (WalkingIterator) matchedPaths.m_exprOwner.getExpression();
WalkingIterator newIter = createIteratorFromSteps(sharedIter, lengthToTest);
ElemVariable var = createPseudoVarDecl(root, newIter, isGlobal);
if (DIAGNOSE_MULTISTEPLIST)
System.err.println("Created var: " + var.getName() + (isGlobal ? "(Global)" : ""));
while (null != matchedPaths) {
ExpressionOwner owner = matchedPaths.m_exprOwner;
WalkingIterator iter = (WalkingIterator) owner.getExpression();
if (DIAGNOSE_MULTISTEPLIST)
diagnoseLineNumber(iter);
LocPathIterator newIter2 = changePartToRef(var.getName(), iter, lengthToTest, isGlobal);
owner.setExpression(newIter2);
matchedPaths = matchedPaths.m_next;
}
}
if (DIAGNOSE_MULTISTEPLIST)
diagnoseMultistepList(matchCount, lengthToTest, isGlobal);
return head;
}
Aggregations