org.apache.xpath.axes
Class UnionPathIterator

java.lang.Object
  extended byorg.apache.xpath.Expression
      extended byorg.apache.xpath.patterns.NodeTest
          extended byorg.apache.xpath.axes.PredicatedNodeTest
              extended byorg.apache.xpath.axes.LocPathIterator
                  extended byorg.apache.xpath.axes.UnionPathIterator
All Implemented Interfaces:
Cloneable, DTMIterator, ExpressionNode, PathComponent, Serializable, javax.xml.transform.SourceLocator, SubContextList, XPathVisitable

public class UnionPathIterator
extends LocPathIterator
implements Cloneable, DTMIterator, Serializable, PathComponent

This class extends NodeSetDTM, which implements DTMIterator, and fetches nodes one at a time in document order based on a XPath UnionExpr. As each node is iterated via nextNode(), the node is also stored in the NodeVector, so that previousNode() can easily be done.

See Also:
Serialized Form

Nested Class Summary
(package private)  class UnionPathIterator.iterOwner
           
 
Nested classes inherited from class org.apache.xpath.axes.PredicatedNodeTest
PredicatedNodeTest.PredOwner
 
Field Summary
protected  LocPathIterator[] m_exprs
          The location path iterators, one for each location path contained in the union expression.
protected  DTMIterator[] m_iterators
          The location path iterators, one for each location path contained in the union expression.
 
Fields inherited from class org.apache.xpath.axes.LocPathIterator
m_allowDetach, m_cdtm, m_clones, m_context, m_currentContextNode, m_execContext, m_lastFetched, m_length, m_pos, m_stackFrame
 
Fields inherited from class org.apache.xpath.axes.PredicatedNodeTest
DEBUG_PREDICATECOUNTING, m_foundLast, m_lpi, m_predCount, m_predicateIndex, m_proximityPositions
 
Fields inherited from class org.apache.xpath.patterns.NodeTest
m_name, m_whatToShow, SCORE_NODETEST, SCORE_NONE, SCORE_NSWILD, SCORE_OTHER, SCORE_QNAME, SHOW_BYFUNCTION, SUPPORTS_PRE_STRIPPING, WILD
 
Fields inherited from class org.apache.xpath.Expression
 
Fields inherited from interface org.apache.xml.dtm.DTMIterator
FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP
 
Constructor Summary
UnionPathIterator()
          Constructor to create an instance which you can add location paths to.
UnionPathIterator(Compiler compiler, int opPos)
          Create a UnionPathIterator object, including creation of location path iterators from the opcode list, and call back into the Compiler to create predicate expressions.
 
Method Summary
 void addIterator(DTMIterator expr)
          Add an iterator to the union list.
 void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
          This will traverse the heararchy, calling the visitor for each member.
 Object clone()
          Get a cloned LocPathIterator that holds the same position as this iterator.
protected  LocPathIterator createDTMIterator(Compiler compiler, int opPos)
          Create a new location path iterator.
static LocPathIterator createUnionIterator(Compiler compiler, int opPos)
          This will return an iterator capable of handling the union of paths given.
 boolean deepEquals(Expression expr)
          Compare this object with another object and see if they are equal, include the sub heararchy.
 void detach()
          Detaches the iterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.
 void fixupVariables(Vector vars, int globalsSize)
          This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.
 int getAnalysisBits()
          Get the analysis bits for this walker, as defined in the WalkerFactory.
 int getAxis()
          Returns the axis being iterated, if it is known.
protected  void loadLocationPaths(Compiler compiler, int opPos, int count)
          Initialize the location path iterators.
 int nextNode()
          Returns the next node in the set and advances the position of the iterator in the set.
private  void readObject(ObjectInputStream stream)
          Read the object from a serialization stream.
 void setRoot(int context, Object environment)
          Initialize the context values for this expression after it is cloned.
 
Methods inherited from class org.apache.xpath.axes.LocPathIterator
allowDetachToRelease, asIterator, asNode, bool, cloneWithReset, execute, executeCharsToContentHandler, getContext, getCurrentContextNode, getCurrentNode, getCurrentPos, getDTM, getDTMManager, getExpandEntityReferences, getFilter, getFoundLast, getIsTopLevel, getLastPos, getLength, getPrefixResolver, getRoot, getWhatToShow, getXPathContext, incrementCurrentPos, isDocOrdered, isFresh, isMutable, isNodesetExpr, item, previousNode, reset, returnNextNode, runTo, setCurrentContextNode, setCurrentPos, setEnvironment, setIsTopLevel, setItem, setNextPosition, setShouldCacheNodes, size
 
Methods inherited from class org.apache.xpath.axes.PredicatedNodeTest
acceptNode, callPredicateVisitors, canTraverseOutsideSubtree, countProximityPosition, executePredicates, getLocPathIterator, getPredicate, getPredicateCount, getPredicateIndex, getProximityPosition, getProximityPosition, getProximityPosition, initPredicateInfo, initProximityPosition, isReverseAxes, nodeToString, resetProximityPositions, setLocPathIterator, setPredicateCount
 
Methods inherited from class org.apache.xpath.patterns.NodeTest
calcScore, debugWhatToShow, execute, execute, getDefaultScore, getLocalName, getNamespace, getNodeTypeTest, getStaticScore, initNodeTest, initNodeTest, setLocalName, setNamespace, setStaticScore, setWhatToShow
 
Methods inherited from class org.apache.xpath.Expression
asIteratorRaw, assertion, error, execute, exprAddChild, exprGetChild, exprGetNumChildren, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, num, warn, xstr
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.xml.dtm.DTMIterator
allowDetachToRelease, cloneWithReset, getCurrentNode, getCurrentPos, getDTM, getDTMManager, getExpandEntityReferences, getLength, getRoot, getWhatToShow, isDocOrdered, isFresh, isMutable, item, previousNode, reset, runTo, setCurrentPos, setItem, setShouldCacheNodes
 

Field Detail

m_exprs

protected LocPathIterator[] m_exprs
The location path iterators, one for each location path contained in the union expression.


m_iterators

protected DTMIterator[] m_iterators
The location path iterators, one for each location path contained in the union expression.

Constructor Detail

UnionPathIterator

public UnionPathIterator()
Constructor to create an instance which you can add location paths to.


UnionPathIterator

public UnionPathIterator(Compiler compiler,
                         int opPos)
                  throws javax.xml.transform.TransformerException
Create a UnionPathIterator object, including creation of location path iterators from the opcode list, and call back into the Compiler to create predicate expressions.

Parameters:
compiler - The Compiler which is creating this expression.
opPos - The position of this iterator in the opcode list from the compiler.
Throws:
javax.xml.transform.TransformerException
Method Detail

setRoot

public void setRoot(int context,
                    Object environment)
Initialize the context values for this expression after it is cloned.

Specified by:
setRoot in interface DTMIterator
Overrides:
setRoot in class LocPathIterator

addIterator

public void addIterator(DTMIterator expr)
Add an iterator to the union list.


detach

public void detach()
Detaches the iterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. Afterdetach has been invoked, calls to nextNode orpreviousNode will raise the exception INVALID_STATE_ERR.

Specified by:
detach in interface DTMIterator
Overrides:
detach in class LocPathIterator

createUnionIterator

public static LocPathIterator createUnionIterator(Compiler compiler,
                                                  int opPos)
                                           throws javax.xml.transform.TransformerException
This will return an iterator capable of handling the union of paths given.

Parameters:
compiler - The Compiler which is creating this expression.
opPos - The position of this iterator in the opcode list from the compiler.
Returns:
Object that is derived from LocPathIterator.
Throws:
javax.xml.transform.TransformerException

getAnalysisBits

public int getAnalysisBits()
Get the analysis bits for this walker, as defined in the WalkerFactory.

Specified by:
getAnalysisBits in interface PathComponent
Overrides:
getAnalysisBits in class LocPathIterator
Returns:
One of WalkerFactory#BIT_DESCENDANT, etc.

readObject

private void readObject(ObjectInputStream stream)
                 throws IOException,
                        javax.xml.transform.TransformerException
Read the object from a serialization stream.

Parameters:
stream - Input stream to read from
Throws:
IOException
javax.xml.transform.TransformerException

clone

public Object clone()
             throws CloneNotSupportedException
Get a cloned LocPathIterator that holds the same position as this iterator.

Specified by:
clone in interface DTMIterator
Overrides:
clone in class PredicatedNodeTest
Returns:
A clone of this iterator that holds the same node position.
Throws:
CloneNotSupportedException

createDTMIterator

protected LocPathIterator createDTMIterator(Compiler compiler,
                                            int opPos)
                                     throws javax.xml.transform.TransformerException
Create a new location path iterator.

Parameters:
compiler - The Compiler which is creating this expression.
opPos - The position of this iterator in the
Returns:
New location path iterator.
Throws:
javax.xml.transform.TransformerException

loadLocationPaths

protected void loadLocationPaths(Compiler compiler,
                                 int opPos,
                                 int count)
                          throws javax.xml.transform.TransformerException
Initialize the location path iterators. Recursive.

Parameters:
compiler - The Compiler which is creating this expression.
opPos - The position of this iterator in the opcode list from the compiler.
count - The insert position of the iterator.
Throws:
javax.xml.transform.TransformerException

nextNode

public int nextNode()
Returns the next node in the set and advances the position of the iterator in the set. After a DTMIterator is created, the first call to nextNode() returns the first node in the set.

Specified by:
nextNode in interface DTMIterator
Specified by:
nextNode in class LocPathIterator
Returns:
The next Node in the set being iterated over, or null if there are no more members in that set.

fixupVariables

public void fixupVariables(Vector vars,
                           int globalsSize)
This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.

Overrides:
fixupVariables in class PredicatedNodeTest
Parameters:
vars - List of QNames that correspond to variables. This list should be searched backwards for the first qualified name that corresponds to the variable reference qname. The position of the QName in the vector from the start of the vector will be its position in the stack frame (but variables above the globalsTop value will need to be offset to the current stack frame).

getAxis

public int getAxis()
Returns the axis being iterated, if it is known.

Specified by:
getAxis in interface DTMIterator
Overrides:
getAxis in class LocPathIterator
Returns:
Axis.CHILD, etc., or -1 if the axis is not known or is of multiple types.

callVisitors

public void callVisitors(ExpressionOwner owner,
                         XPathVisitor visitor)
Description copied from interface: XPathVisitable
This will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.

Specified by:
callVisitors in interface XPathVisitable
Overrides:
callVisitors in class LocPathIterator
See Also:
XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)

deepEquals

public boolean deepEquals(Expression expr)
Description copied from class: Expression
Compare this object with another object and see if they are equal, include the sub heararchy.

Overrides:
deepEquals in class PredicatedNodeTest
See Also:
Expression.deepEquals(Expression)