Package org.apache.xpath
Class XPathContext
java.lang.Object
org.apache.xml.dtm.DTMManager
org.apache.xpath.XPathContext
Default class for the runtime execution context for XPath.
This class extends DTMManager but does not directly implement it.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionThe reader of the primary source tree.static final int
The ammount to use for stacks that record information during the recursive execution.Fields inherited from class org.apache.xml.dtm.DTMManager
IDENT_DTM_DEFAULT, IDENT_DTM_NODE_BITS, IDENT_MAX_DTMS, IDENT_NODE_DEFAULT, m_incremental, m_source_location
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an XPathContext instance.XPathContext
(boolean recursiveVarContext) Create an XPathContext instance.XPathContext
(Object owner) Create an XPathContext instance.XPathContext
(Object owner, boolean recursiveVarContext) Create an XPathContext instance. -
Method Summary
Modifier and TypeMethodDescriptionCreates an emptyDocumentFragment
object.createDTMIterator
(int node) Create a newDTMIterator
that holds exactly one node.createDTMIterator
(int whatToShow, DTMFilter filter, boolean entityReferenceExpansion) Create a newDTMIterator
based only on a whatToShow and a DTMFilter.createDTMIterator
(Object xpathCompiler, int pos) Create a newDTMIterator
based on an XPath invalid input: '<'a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath or a UnionExpr.createDTMIterator
(String xpathString, PrefixResolver presolver) Create a newDTMIterator
based on an XPath invalid input: '<'a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath or a UnionExpr.final int
Get the current context node.final DTMIterator
Get the current context node list.final DTMIterator
Get the current context node list.final int
Get the current node that is the expression's context (i.e. for current() support).final int
Get the current context node.Get the current node list as defined by the XSLT spec.getDTM
(int nodeHandle) Get an instance of a DTM that "owns" a node handle.getDTM
(Source source, boolean unique, DTMWSFilter wsfilter, boolean incremental, boolean doIndexing) Get an instance of a DTM, loaded with the content from the specified source.int
getDTMHandleFromNode
(Node node) Given a W3C DOM node, try and return a DTM handle.int
getDTMIdentity
(DTM dtm) %TBD% DocReturn the DTMManager object.getDTMXRTreeFrag
(int dtmIdentity) Gets DTMXRTreeFrag object if one has already been created.final ErrorListener
Get the ErrorListener where errors and warnings are to be reported.The the expression context for extensions for this context.Get a DTM to be used as a container for a global Result Tree Fragment.final int
Get the current location path iterator root.final PrefixResolver
Get the current namespace context for the xpath.Get the "owner" context of this context, which should be, in the case of XSLT, the Transformer object.final int
final int
Get the current predicate root.final XMLReader
Get primary XMLReader associated with this execution context.Get a DTM to be used as a container for a dynamic Result Tree Fragment.Get the current locater in the stylesheet.final SourceTreeManager
Get the SourceTreeManager associated with this execution context.Get the current axes iterator, or return null if none.final URIResolver
Get the URIResolver associated with this execution context.final VariableStack
Get the variable stack, which is in charge of variables and parameters.boolean
Return the state of the secure processing featurefinal void
Pop the current context node list.final void
Pop the current node that is the expression's context (i.e. for current() support).final void
Pop the current context node.final void
Set the current context node.final void
Pop the current context node, expression node, and prefix resolver.final void
Pop the current location path iterator root.final void
Pop the current namespace context for the xpath.final void
final void
Pop the current predicate root.void
Pop the RTFDTM's context mark.void
Pop the current locater.final void
Pop the last pushed axes iterator.final void
Set the current context node list.final void
pushCurrentExpressionNode
(int n) Set the current node that is the expression's context (i.e. for current() support).final void
pushCurrentNode
(int n) Set the current context node.final void
pushCurrentNodeAndExpression
(int cn, int en) Set the current context node and expression node.final void
pushExpressionState
(int cn, int en, PrefixResolver nc) Push the current context node, expression node, and prefix resolver.final void
pushIteratorRoot
(int n) Set the current location path iterator root.final void
Push a current namespace context for the xpath.final void
Just increment the namespace contest stack, so that setNamespaceContext can be used on the slot.final void
pushPredicatePos
(int n) final void
pushPredicateRoot
(int n) Set the current predicate root.void
Push the RTFDTM's context mark, to allows discarding RTFs added after this point.void
pushSAXLocator
(SourceLocator location) Set the current locater in the stylesheet.void
Push a slot on the locations stack so that setSAXLocator can be repeatedly called.final void
Push a TreeWalker on the stack.boolean
Release a DTM either to a lru pool, or completely remove reference.void
reset()
Reset for new run.void
void
void
void
void
setErrorListener
(ErrorListener listener) Set the ErrorListener where errors and warnings are to be reported.final void
Get the current namespace context for the xpath.void
setPrimaryReader
(XMLReader reader) Set primary XMLReader associated with this execution context.void
setSAXLocator
(SourceLocator location) Set the current locater in the stylesheet.void
setSecureProcessing
(boolean flag) Set the state of the secure processing featurevoid
Set the SourceTreeManager associated with this execution context.void
setURIResolver
(URIResolver resolver) Set the URIResolver associated with this execution context.final void
setVarStack
(VariableStack varStack) Get the variable stack, which is in charge of variables and parameters.Methods inherited from class org.apache.xml.dtm.DTMManager
getDTMIdentityMask, getIncremental, getNodeIdentityMask, getSource_location, getXMLStringFactory, newInstance, setIncremental, setSource_location, setXMLStringFactory
-
Field Details
-
m_primaryReader
The reader of the primary source tree. -
RECURSIONLIMIT
public static final int RECURSIONLIMITThe ammount to use for stacks that record information during the recursive execution.- See Also:
-
-
Constructor Details
-
XPathContext
public XPathContext()Create an XPathContext instance. This is equivalent to calling theXPathContext(boolean)
constructor with the valuetrue
. -
XPathContext
public XPathContext(boolean recursiveVarContext) Create an XPathContext instance.- Parameters:
recursiveVarContext
- Aboolean
value indicating whether the XPath context needs to support pushing of scopes for variable resolution
-
XPathContext
Create an XPathContext instance. This is equivalent to calling the constructorXPathContext(java.lang.Object,boolean)
with the value of the second parameter set totrue
.- Parameters:
owner
- Value that can be retrieved via the getOwnerObject() method.- See Also:
-
XPathContext
Create an XPathContext instance.- Parameters:
owner
- Value that can be retrieved via the getOwnerObject() method.recursiveVarContext
- Aboolean
value indicating whether the XPath context needs to support pushing of scopes for variable resolution- See Also:
-
-
Method Details
-
getDTMManager
Return the DTMManager object. Though XPathContext context extends the DTMManager, it really is a proxy for the real DTMManager. If a caller needs to make a lot of calls to the DTMManager, it is faster if it gets the real one from this function. -
setSecureProcessing
public void setSecureProcessing(boolean flag) Set the state of the secure processing feature -
isSecureProcessing
public boolean isSecureProcessing()Return the state of the secure processing feature -
getDTM
public DTM getDTM(Source source, boolean unique, DTMWSFilter wsfilter, boolean incremental, boolean doIndexing) Get an instance of a DTM, loaded with the content from the specified source. If the unique flag is true, a new instance will always be returned. Otherwise it is up to the DTMManager to return a new instance or an instance that it already created and may be being used by someone else. (I think more parameters will need to be added for error handling, and entity resolution).- Specified by:
getDTM
in classDTMManager
- Parameters:
source
- the specification of the source object, which may be null, in which case it is assumed that node construction will take by some other means.unique
- true if the returned DTM must be unique, probably because it is going to be mutated.wsfilter
- Enables filtering of whitespace nodes, and may be null.incremental
- true if the construction should try and be incremental.doIndexing
- true if the caller considers it worth it to use indexing schemes.- Returns:
- a non-null DTM reference.
-
getDTM
Get an instance of a DTM that "owns" a node handle.- Specified by:
getDTM
in classDTMManager
- Parameters:
nodeHandle
- the nodeHandle.- Returns:
- a non-null DTM reference.
-
getDTMHandleFromNode
Given a W3C DOM node, try and return a DTM handle. Note: calling this may be non-optimal.- Specified by:
getDTMHandleFromNode
in classDTMManager
- Parameters:
node
- Non-null reference to a DOM node.- Returns:
- a valid DTM handle.
-
getDTMIdentity
%TBD% Doc- Specified by:
getDTMIdentity
in classDTMManager
-
createDocumentFragment
Creates an emptyDocumentFragment
object.- Specified by:
createDocumentFragment
in classDTMManager
- Returns:
- A new
DocumentFragment handle
.
-
release
Release a DTM either to a lru pool, or completely remove reference. DTMs without system IDs are always hard deleted. State: experimental.- Specified by:
release
in classDTMManager
- Parameters:
dtm
- The DTM to be released.shouldHardDelete
- True if the DTM should be removed no matter what.- Returns:
- true if the DTM was removed, false if it was put back in a lru pool.
-
createDTMIterator
Create a newDTMIterator
based on an XPath invalid input: '<'a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath or a UnionExpr.- Specified by:
createDTMIterator
in classDTMManager
- Parameters:
xpathCompiler
- ??? Somehow we need to pass in a subpart of the expression. I hate to do this with strings, since the larger expression has already been parsed.pos
- The position in the expression.- Returns:
- The newly created
DTMIterator
.
-
createDTMIterator
Create a newDTMIterator
based on an XPath invalid input: '<'a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath or a UnionExpr.- Specified by:
createDTMIterator
in classDTMManager
- Parameters:
xpathString
- Must be a valid string expressing a invalid input: '<'a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath or a UnionExpr.presolver
- An object that can resolve prefixes to namespace URLs.- Returns:
- The newly created
DTMIterator
.
-
createDTMIterator
public DTMIterator createDTMIterator(int whatToShow, DTMFilter filter, boolean entityReferenceExpansion) Create a newDTMIterator
based only on a whatToShow and a DTMFilter. The traversal semantics are defined as the descendant access.- Specified by:
createDTMIterator
in classDTMManager
- Parameters:
whatToShow
- This flag specifies which node types may appear in the logical view of the tree presented by the iterator. See the description ofNodeFilter
for the set of possibleSHOW_
values.These flags can be combined usingOR
.filter
- TheNodeFilter
to be used with thisTreeWalker
, ornull
to indicate no filter.entityReferenceExpansion
- The value of this flag determines whether entity reference nodes are expanded.- Returns:
- The newly created
NodeIterator
.
-
createDTMIterator
Create a newDTMIterator
that holds exactly one node.- Specified by:
createDTMIterator
in classDTMManager
- Parameters:
node
- The node handle that the DTMIterator will iterate to.- Returns:
- The newly created
DTMIterator
.
-
reset
public void reset()Reset for new run. -
setSAXLocator
Set the current locater in the stylesheet.- Parameters:
location
- The location within the stylesheet.
-
pushSAXLocator
Set the current locater in the stylesheet.- Parameters:
location
- The location within the stylesheet.
-
pushSAXLocatorNull
public void pushSAXLocatorNull()Push a slot on the locations stack so that setSAXLocator can be repeatedly called. -
popSAXLocator
public void popSAXLocator()Pop the current locater. -
getSAXLocator
Get the current locater in the stylesheet.- Returns:
- The location within the stylesheet, or null if not known.
-
getOwnerObject
Get the "owner" context of this context, which should be, in the case of XSLT, the Transformer object. This is needed so that XSLT functions can get the Transformer.- Returns:
- The owner object passed into the constructor, or null.
-
getVarStack
Get the variable stack, which is in charge of variables and parameters.- Returns:
- the variable stack, which should not be null.
-
setVarStack
Get the variable stack, which is in charge of variables and parameters.- Parameters:
varStack
- non-null reference to the variable stack.
-
getSourceTreeManager
Get the SourceTreeManager associated with this execution context.- Returns:
- the SourceTreeManager associated with this execution context.
-
setSourceTreeManager
Set the SourceTreeManager associated with this execution context.- Parameters:
mgr
- the SourceTreeManager to be associated with this execution context.
-
getErrorListener
Get the ErrorListener where errors and warnings are to be reported.- Returns:
- A non-null ErrorListener reference.
-
setErrorListener
Set the ErrorListener where errors and warnings are to be reported.- Parameters:
listener
- A non-null ErrorListener reference.- Throws:
IllegalArgumentException
-
getURIResolver
Get the URIResolver associated with this execution context.- Returns:
- a URI resolver, which may be null.
-
setURIResolver
Set the URIResolver associated with this execution context.- Parameters:
resolver
- the URIResolver to be associated with this execution context, may be null to clear an already set resolver.
-
getPrimaryReader
Get primary XMLReader associated with this execution context.- Returns:
- The reader of the primary source tree.
-
setPrimaryReader
Set primary XMLReader associated with this execution context.- Parameters:
reader
- The reader of the primary source tree.
-
getContextNodeListsStack
-
setContextNodeListsStack
-
getContextNodeList
Get the current context node list.- Returns:
- the current node list,
also refered to here as a
context node list .
-
pushContextNodeList
Set the current context node list.- Parameters:
nl
- the current node list, also refered to here as acontext node list .
-
popContextNodeList
public final void popContextNodeList()Pop the current context node list. -
getCurrentNodeStack
-
setCurrentNodeStack
-
getCurrentNode
public final int getCurrentNode()Get the current context node.- Returns:
- the current node.
-
pushCurrentNodeAndExpression
public final void pushCurrentNodeAndExpression(int cn, int en) Set the current context node and expression node.- Parameters:
cn
- the current node.en
- the sub-expression context node.
-
popCurrentNodeAndExpression
public final void popCurrentNodeAndExpression()Set the current context node. -
pushExpressionState
Push the current context node, expression node, and prefix resolver.- Parameters:
cn
- the current node.en
- the sub-expression context node.nc
- the namespace context (prefix resolver.
-
popExpressionState
public final void popExpressionState()Pop the current context node, expression node, and prefix resolver. -
pushCurrentNode
public final void pushCurrentNode(int n) Set the current context node.- Parameters:
n
- the current node.
-
popCurrentNode
public final void popCurrentNode()Pop the current context node. -
pushPredicateRoot
public final void pushPredicateRoot(int n) Set the current predicate root. -
popPredicateRoot
public final void popPredicateRoot()Pop the current predicate root. -
getPredicateRoot
public final int getPredicateRoot()Get the current predicate root. -
pushIteratorRoot
public final void pushIteratorRoot(int n) Set the current location path iterator root. -
popIteratorRoot
public final void popIteratorRoot()Pop the current location path iterator root. -
getIteratorRoot
public final int getIteratorRoot()Get the current location path iterator root. -
getCurrentExpressionNodeStack
-
setCurrentExpressionNodeStack
-
getPredicatePos
public final int getPredicatePos() -
pushPredicatePos
public final void pushPredicatePos(int n) -
popPredicatePos
public final void popPredicatePos() -
getCurrentExpressionNode
public final int getCurrentExpressionNode()Get the current node that is the expression's context (i.e. for current() support).- Returns:
- The current sub-expression node.
-
pushCurrentExpressionNode
public final void pushCurrentExpressionNode(int n) Set the current node that is the expression's context (i.e. for current() support).- Parameters:
n
- The sub-expression node to be current.
-
popCurrentExpressionNode
public final void popCurrentExpressionNode()Pop the current node that is the expression's context (i.e. for current() support). -
getNamespaceContext
Get the current namespace context for the xpath.- Returns:
- the current prefix resolver for resolving prefixes to namespace URLs.
-
setNamespaceContext
Get the current namespace context for the xpath.- Parameters:
pr
- the prefix resolver to be used for resolving prefixes to namespace URLs.
-
pushNamespaceContext
Push a current namespace context for the xpath.- Parameters:
pr
- the prefix resolver to be used for resolving prefixes to namespace URLs.
-
pushNamespaceContextNull
public final void pushNamespaceContextNull()Just increment the namespace contest stack, so that setNamespaceContext can be used on the slot. -
popNamespaceContext
public final void popNamespaceContext()Pop the current namespace context for the xpath. -
getAxesIteratorStackStacks
-
setAxesIteratorStackStacks
-
pushSubContextList
Push a TreeWalker on the stack.- Parameters:
iter
- A sub-context AxesWalker.
-
popSubContextList
public final void popSubContextList()Pop the last pushed axes iterator. -
getSubContextList
Get the current axes iterator, or return null if none.- Returns:
- the sub-context node list.
-
getCurrentNodeList
Get the current node list as defined by the XSLT spec.- Returns:
- the current node list.
-
getContextNode
public final int getContextNode()Get the current context node.- Returns:
- The current context node.
-
getContextNodes
Get the current context node list.- Returns:
- An iterator for the current context list, as defined in XSLT.
-
getExpressionContext
The the expression context for extensions for this context.- Returns:
- An object that implements the ExpressionContext.
-
getGlobalRTFDTM
Get a DTM to be used as a container for a global Result Tree Fragment. This will always be an instance of (derived from? equivalent to?) SAX2DTM, since each RTF is constructed by temporarily redirecting our SAX output to it. It may be a single DTM containing for multiple fragments, if the implementation supports that. Note: The distinction between this method and getRTFDTM() is that the latter allocates space from the dynamic variable stack (m_rtfdtm_stack), which may be pruned away again as the templates which defined those variables are exited. Global variables may be bound late (see XUnresolvedVariable), and never want to be discarded, hence we need to allocate them separately and don't actually need a stack to track them.- Returns:
- a non-null DTM reference.
-
getRTFDTM
Get a DTM to be used as a container for a dynamic Result Tree Fragment. This will always be an instance of (derived from? equivalent to?) SAX2DTM, since each RTF is constructed by temporarily redirecting our SAX output to it. It may be a single DTM containing for multiple fragments, if the implementation supports that.- Returns:
- a non-null DTM reference.
-
pushRTFContext
public void pushRTFContext()Push the RTFDTM's context mark, to allows discarding RTFs added after this point. (If it doesn't exist we don't push, since we might still be able to get away with not creating it. That requires that excessive pops be harmless.) -
popRTFContext
public void popRTFContext()Pop the RTFDTM's context mark. This discards any RTFs added after the last mark was set. If there is no RTF DTM, there's nothing to pop so this becomes a no-op. If pushes were issued before this was called, we count on the fact that popRewindMark is defined such that overpopping just resets to empty. Complicating factor: We need to handle the case of popping back to a previous RTF DTM, if one of the weird produce-an-RTF-to-build-an-RTF cases arose. Basically: If pop says this DTM is now empty, then return to the previous if one exists, in whatever state we left it in. UGLY, but hopefully the situation which forces us to consider this will arise exceedingly rarely. -
getDTMXRTreeFrag
Gets DTMXRTreeFrag object if one has already been created. Creates new DTMXRTreeFrag object and adds to m_DTMXRTreeFrags HashMap, otherwise.- Parameters:
dtmIdentity
-- Returns:
- DTMXRTreeFrag
-