|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.xpath.XPathVisitor org.apache.xalan.templates.XSLTVisitor org.apache.xalan.templates.RedundentExprEliminator
This class eleminates redundent XPaths from a given subtree, and also collects all absolute paths within the subtree. First it must be called as a visitor to the subtree, and then eleminateRedundent must be called.
Nested Class Summary | |
(package private) class |
RedundentExprEliminator.MultistepExprHolder
Since we want to sort multistep expressions by length, use a linked list with elements of type MultistepExprHolder. |
Field Summary | |
static boolean |
DEBUG
|
static boolean |
DIAGNOSE_MULTISTEPLIST
|
static boolean |
DIAGNOSE_NUM_PATHS_REDUCED
|
(package private) AbsPathChecker |
m_absPathChecker
|
(package private) Vector |
m_absPaths
|
(package private) boolean |
m_isSameContext
|
(package private) Vector |
m_paths
|
(package private) static int |
m_uniquePsuedoVarID
|
(package private) VarNameCollector |
m_varNameCollector
So we can reuse it over and over again. |
(package private) static String |
PSUEDOVARNAMESPACE
|
Constructor Summary | |
RedundentExprEliminator()
Construct a RedundentExprEliminator. |
Method Summary | |
protected ElemVariable |
addVarDeclToElem(ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi,
ElemVariable psuedoVar)
Add the given variable to the psuedoVarRecipient. |
protected static void |
assertion(boolean b,
String msg)
Simple assertion. |
private void |
assertIsLocPathIterator(Expression expr1,
ExpressionOwner eo)
Assert that the expression is a LocPathIterator, and, if not, try to give some diagnostic info. |
protected LocPathIterator |
changePartToRef(QName uniquePsuedoVarName,
WalkingIterator wi,
int numSteps,
boolean isGlobal)
Change a given number of steps to a single variable reference. |
protected void |
changeToVarRef(QName varName,
ExpressionOwner owner,
Vector paths,
ElemTemplateElement psuedoVarRecipient)
Change the expression owned by the owner argument to a variable reference of the given name. |
protected int |
countAncestors(ElemTemplateElement elem)
Count the number of ancestors that a ElemTemplateElement has. |
protected int |
countSteps(LocPathIterator lpi)
Count the steps in a given location path. |
protected ElemVariable |
createGlobalPsuedoVarDecl(QName uniquePsuedoVarName,
StylesheetRoot stylesheetRoot,
LocPathIterator lpi)
Create a psuedo variable reference that will represent the shared redundent XPath, for a local reduction. |
protected WalkingIterator |
createIteratorFromSteps(WalkingIterator wi,
int numSteps)
Create a new WalkingIterator from the steps in another WalkingIterator. |
protected ElemVariable |
createLocalPsuedoVarDecl(QName uniquePsuedoVarName,
ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi)
Create a psuedo variable reference that will represent the shared redundent XPath, for a local reduction. |
protected RedundentExprEliminator.MultistepExprHolder |
createMultistepExprList(Vector paths)
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. |
protected ElemVariable |
createPsuedoVarDecl(ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi,
boolean isGlobal)
Create a psuedo variable reference that will represent the shared redundent XPath, and add it to the stylesheet. |
protected void |
diagnoseLineNumber(Expression expr)
Tell what line number belongs to a given expression. |
protected void |
diagnoseMultistepList(int matchCount,
int lengthToTest,
boolean isGlobal)
Print out diagnostics about partial multistep evaluation. |
protected void |
diagnoseNumPaths(Vector paths,
int numPathsEliminated,
int numUniquePathsEliminated)
Print out to std err the number of paths reduced. |
protected void |
eleminateRedundent(ElemTemplateElement psuedoVarRecipient,
Vector paths)
Method to be called after the all expressions within an node context have been visited. |
void |
eleminateRedundentGlobals(StylesheetRoot stylesheet)
Method to be called after the all global expressions within a stylesheet have been collected. |
void |
eleminateRedundentLocals(ElemTemplateElement psuedoVarRecipient)
Method to be called after the all expressions within an node context have been visited. |
protected void |
eleminateSharedPartialPaths(ElemTemplateElement psuedoVarRecipient,
Vector paths)
Eliminate the shared partial paths in the expression list. |
protected int |
findAndEliminateRedundant(int start,
int firstOccuranceIndex,
ExpressionOwner firstOccuranceOwner,
ElemTemplateElement psuedoVarRecipient,
Vector paths)
Look through the vector from start point, looking for redundant occurances. |
protected ElemTemplateElement |
findCommonAncestor(RedundentExprEliminator.MultistepExprHolder head)
Given a linked list of expressions, find the common ancestor that is suitable for holding a psuedo variable for shared access. |
protected ElemTemplateElement |
getElemFromExpression(Expression expr)
From an XPath expression component, get the ElemTemplateElement owner. |
protected ElemTemplateElement |
getPrevElementWithinContext(ElemTemplateElement elem)
Get the previous sibling or parent of the given template, stopping at xsl:for-each, xsl:template, or xsl:stylesheet. |
protected ElemVariable |
getPrevVariableElem(ElemTemplateElement elem)
Find the previous occurance of a xsl:variable. |
boolean |
isAbsolute(LocPathIterator path)
Tell if the given LocPathIterator is relative to an absolute path, i.e. |
protected boolean |
isNotSameAsOwner(RedundentExprEliminator.MultistepExprHolder head,
ElemTemplateElement ete)
Find out if the given ElemTemplateElement is not the same as one of the ElemTemplateElement owners of the expressions. |
protected boolean |
isParam(ExpressionNode expr)
Tell if the expr param is contained within an xsl:param. |
protected RedundentExprEliminator.MultistepExprHolder |
matchAndEliminatePartialPaths(RedundentExprEliminator.MultistepExprHolder testee,
RedundentExprEliminator.MultistepExprHolder head,
boolean isGlobal,
int lengthToTest,
ElemTemplateElement varScope)
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. |
protected int |
oldFindAndEliminateRedundant(int start,
int firstOccuranceIndex,
ExpressionOwner firstOccuranceOwner,
ElemTemplateElement psuedoVarRecipient,
Vector paths)
To be removed. |
(package private) boolean |
partialIsVariable(RedundentExprEliminator.MultistepExprHolder testee,
int lengthToTest)
Check if results of partial reduction will just be a variable, in which case, skip it. |
protected boolean |
stepsEqual(WalkingIterator iter1,
WalkingIterator iter2,
int numSteps)
Compare a given number of steps between two iterators, to see if they are equal. |
private static void |
validateNewAddition(Vector paths,
ExpressionOwner owner,
LocPathIterator path)
Validate some assumptions about the new LocPathIterator and it's owner and the state of the list. |
(package private) boolean |
visitInstruction(ElemTemplateElement elem)
Visit an XSLT instruction. |
boolean |
visitLocationPath(ExpressionOwner owner,
LocPathIterator path)
Visit a LocationPath. |
boolean |
visitPredicate(ExpressionOwner owner,
Expression pred)
Visit a predicate within a location path. |
(package private) boolean |
visitTopLevelInstruction(ElemTemplateElement elem)
Visit an XSLT top-level instruction. |
Methods inherited from class org.apache.xalan.templates.XSLTVisitor |
visitAVT, visitExtensionElement, visitLiteralResultElement, visitStylesheet, visitTopLevelVariableOrParamDecl, visitVariableOrParamDecl |
Methods inherited from class org.apache.xpath.XPathVisitor |
visitBinaryOperation, visitFunction, visitMatchPattern, visitNumberLiteral, visitStep, visitStringLiteral, visitUnaryOperation, visitUnionPath, visitUnionPattern, visitVariableRef |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
Vector m_paths
Vector m_absPaths
boolean m_isSameContext
AbsPathChecker m_absPathChecker
static int m_uniquePsuedoVarID
static final String PSUEDOVARNAMESPACE
public static boolean DEBUG
public static boolean DIAGNOSE_NUM_PATHS_REDUCED
public static boolean DIAGNOSE_MULTISTEPLIST
VarNameCollector m_varNameCollector
Constructor Detail |
public RedundentExprEliminator()
Method Detail |
public void eleminateRedundentLocals(ElemTemplateElement psuedoVarRecipient)
psuedoVarRecipient
- The recipient of the psuedo vars. The
variables will be inserted as first children of the element, before
any existing variables.public void eleminateRedundentGlobals(StylesheetRoot stylesheet)
protected void eleminateRedundent(ElemTemplateElement psuedoVarRecipient, Vector paths)
psuedoVarRecipient
- The owner of the subtree from where the
paths were collected.paths
- A vector of paths that hold ExpressionOwner objects,
which must yield LocationPathIterators.protected void eleminateSharedPartialPaths(ElemTemplateElement psuedoVarRecipient, Vector paths)
psuedoVarRecipient
- The recipient of the psuedo vars.paths
- A vector of paths that hold ExpressionOwner objects,
which must yield LocationPathIterators.protected RedundentExprEliminator.MultistepExprHolder matchAndEliminatePartialPaths(RedundentExprEliminator.MultistepExprHolder testee, RedundentExprEliminator.MultistepExprHolder head, boolean isGlobal, int lengthToTest, ElemTemplateElement varScope)
boolean partialIsVariable(RedundentExprEliminator.MultistepExprHolder testee, int lengthToTest)
protected void diagnoseLineNumber(Expression expr)
protected ElemTemplateElement findCommonAncestor(RedundentExprEliminator.MultistepExprHolder head)
protected boolean isNotSameAsOwner(RedundentExprEliminator.MultistepExprHolder head, ElemTemplateElement ete)
head
- Head of linked list of expression owners.ete
- The ElemTemplateElement that is a candidate for a psuedo
variable parent.
protected int countAncestors(ElemTemplateElement elem)
elem
- An representation of an element in an XSLT stylesheet.
protected void diagnoseMultistepList(int matchCount, int lengthToTest, boolean isGlobal)
protected LocPathIterator changePartToRef(QName uniquePsuedoVarName, WalkingIterator wi, int numSteps, boolean isGlobal)
uniquePsuedoVarName
- The name of the variable reference.wi
- The walking iterator that is to be changed.numSteps
- The number of steps to be changed.isGlobal
- true if this will be a global reference.protected WalkingIterator createIteratorFromSteps(WalkingIterator wi, int numSteps)
wi
- The iterator from where the steps will be taken.numSteps
- The number of steps from the first to copy into the new
iterator.
protected boolean stepsEqual(WalkingIterator iter1, WalkingIterator iter2, int numSteps)
iter1
- The first iterator to compare.iter2
- The second iterator to compare.numSteps
- The number of steps to compare.
protected RedundentExprEliminator.MultistepExprHolder createMultistepExprList(Vector paths)
paths
- Vector of ExpressionOwner objects, which may contain null entries.
The ExpressionOwner objects must own LocPathIterator objects.
protected int findAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException
start
- The position to start looking in the vector.firstOccuranceOwner
- The owner of the expression we are looking for.psuedoVarRecipient
- Where to put the psuedo variables.
org.w3c.dom.DOMException
protected int oldFindAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException
org.w3c.dom.DOMException
protected int countSteps(LocPathIterator lpi)
lpi
- The location path iterator that owns the steps.
protected void changeToVarRef(QName varName, ExpressionOwner owner, Vector paths, ElemTemplateElement psuedoVarRecipient)
varName
- The name of the variable which will be referenced.owner
- The owner of the expression which will be replaced by a variable ref.paths
- The paths list that the iterator came from, mainly to determine
if this is a local or global reduction.psuedoVarRecipient
- The element within whose scope the variable is
being inserted, possibly a StylesheetRoot.protected ElemVariable createPsuedoVarDecl(ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi, boolean isGlobal) throws org.w3c.dom.DOMException
psuedoVarRecipient
- The broadest scope of where the variable
should be inserted, usually an xsl:template or xsl:for-each.lpi
- The LocationPathIterator that the variable should represent.isGlobal
- true if the paths are global.
org.w3c.dom.DOMException
protected ElemVariable createGlobalPsuedoVarDecl(QName uniquePsuedoVarName, StylesheetRoot stylesheetRoot, LocPathIterator lpi) throws org.w3c.dom.DOMException
uniquePsuedoVarName
- The name of the new variable.stylesheetRoot
- The broadest scope of where the variable
should be inserted, which must be a StylesheetRoot element in this case.lpi
- The LocationPathIterator that the variable should represent.
org.w3c.dom.DOMException
protected ElemVariable createLocalPsuedoVarDecl(QName uniquePsuedoVarName, ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi) throws org.w3c.dom.DOMException
uniquePsuedoVarName
- The name of the new variable.psuedoVarRecipient
- The broadest scope of where the variable
should be inserted, usually an xsl:template or xsl:for-each.lpi
- The LocationPathIterator that the variable should represent.
org.w3c.dom.DOMException
protected ElemVariable addVarDeclToElem(ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi, ElemVariable psuedoVar) throws org.w3c.dom.DOMException
org.w3c.dom.DOMException
protected boolean isParam(ExpressionNode expr)
protected ElemVariable getPrevVariableElem(ElemTemplateElement elem)
elem
- Should be non-null template element.
protected ElemTemplateElement getPrevElementWithinContext(ElemTemplateElement elem)
elem
- Should be non-null template element.
protected ElemTemplateElement getElemFromExpression(Expression expr)
expr
- Should be static expression with proper parentage.
public boolean isAbsolute(LocPathIterator path)
public boolean visitLocationPath(ExpressionOwner owner, LocPathIterator path)
visitLocationPath
in class XPathVisitor
owner
- The owner of the expression, to which the expression can
be reset if rewriting takes place.path
- The LocationPath object.
public boolean visitPredicate(ExpressionOwner owner, Expression pred)
visitPredicate
in class XPathVisitor
owner
- The owner of the expression, to which the expression can
be reset if rewriting takes place.pred
- The predicate object.
boolean visitTopLevelInstruction(ElemTemplateElement elem)
visitTopLevelInstruction
in class XSLTVisitor
elem
- The xsl instruction element object.
boolean visitInstruction(ElemTemplateElement elem)
visitInstruction
in class XSLTVisitor
elem
- The xsl instruction element object.
protected void diagnoseNumPaths(Vector paths, int numPathsEliminated, int numUniquePathsEliminated)
private final void assertIsLocPathIterator(Expression expr1, ExpressionOwner eo) throws RuntimeException
RuntimeException
private static void validateNewAddition(Vector paths, ExpressionOwner owner, LocPathIterator path) throws RuntimeException
RuntimeException
protected static void assertion(boolean b, String msg)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |