Package org.exolab.adaptx.xpath
Class XPathContext
java.lang.Object
org.exolab.adaptx.xpath.XPathContext
- Direct Known Subclasses:
ProcessorState
Base implementation of an XPath context. An XPath context provides
a way to manage a stack of node-sets, resolve variable and
function names, and return the size and position of the context.
This implementation is not thread-safe, care must be taken not to
use the same context when evaluating expressions concurrently.
Impelementations may wish to extend this class and provide additional facilities for locating the document order of a node, or providing a function library.
- Version:
- $Revision: 3633 $
- Author:
- Keith Visco, Assaf Arkin
-
Constructor Summary
ConstructorsConstructorDescriptionXPathContext
(VariableSet variables, NodeSet nodeSet, int position) Constructs a new XPath context.XPathContext
(XPathNode node) Constructs a new XPath context using the given node as the context node.XPathContext
(XPathNode node, VariableSet variables) Constructs a new XPath context using the given node as as the context node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNamespaceBinding
(String prefix, String namespace) Creates a binding within this XPathContext between a given prefix and a namespace URI.int[]
getDocumentOrder
(XPathNode node) Returns the document order of the given node.getElementById
(XPathNode root, String id) Returns the element associated with the given identifier.getFunction
(String uri, String name) Returns the XPath function by the given name, or null if no such function is defined.getNamespaceURI
(String prefix) Returns the namespace associated with the given prefix as defined in this context.getNode()
Returns the context node of this XPathContextReturns the current context node-set.int
Returns the position of the context node.int
getSize()
Returns the size of the context.getVariable
(String name) Returns the XPath result bound to the given variable name.newContext
(NodeSet nodeSet, int position) Creates a new XPathContext with this XPathContext as it's parent.newContext
(XPathNode node) Creates a new XPathContext with this XPathContext as it's parent.Constructs and returns a new empty node-set.newNodeSet
(int size) Constructs and returns a new node-set with the specified size.newNodeSet
(XPathNode node) Constructs and returns a new node-set with one node.void
setNodeSet
(NodeSet nodeSet, int position) Sets the given node-set as the context node-set for this XPathContextvoid
setPosition
(int position) Sets the position of the context node within the context node-set
-
Constructor Details
-
XPathContext
Constructs a new XPath context using the given node as the context node. The size is set to 1 and position is set to 0 and no variable bindings are provided.- Parameters:
node
- the context XPathNode.
-
XPathContext
Constructs a new XPath context using the given node as as the context node. The size is set to 1 and position is set to 0. Variables bindings may be optionally provided.- Parameters:
node
- the context XPathNode.variable
- Variable bindings, or null
-
XPathContext
Constructs a new XPath context. Variables bindings may be optionally provided, size and position are required.- Parameters:
variable
- Variable bindings, or nullnodeSet
- the context node-set for this XPathContextposition
- The position of the context node (zero base)
-
-
Method Details
-
addNamespaceBinding
Creates a binding within this XPathContext between a given prefix and a namespace URI. This namespace binding will be override any binding for the given prefix within a parent context, and will be available to all sub-contexts unless they also override the namespace binding with one of their own.- Parameters:
prefix
- the prefix to associate with the namespacenamespace
- the namespace URI.
-
getNode
Returns the context node of this XPathContext- Returns:
- the context node
-
getPosition
public int getPosition()Returns the position of the context node. The position is a value between zero and the context size minus one. One must be added in order to obtain a value XPath position.- Returns:
- The position of the context node
- See Also:
-
getSize
public int getSize()Returns the size of the context.- Returns:
- The size of the context
-
newContext
Creates a new XPathContext with this XPathContext as it's parent.- Returns:
- the new XPathContext
-
newContext
Creates a new XPathContext with this XPathContext as it's parent.- Returns:
- the new XPathContext
-
newNodeSet
Constructs and returns a new node-set with the specified size.- Parameters:
size
- The size of the node-set- Returns:
- A new node-set with that size
-
newNodeSet
Constructs and returns a new node-set with one node.- Parameters:
node
- The node to include in the node-set- Returns:
- A new node-set
-
newNodeSet
Constructs and returns a new empty node-set.- Returns:
- A new empty node-set
-
getNodeSet
Returns the current context node-set.- Returns:
- The current context node-set
-
setNodeSet
Sets the given node-set as the context node-set for this XPathContext- Parameters:
nodeSet
- the node-set to use as the context node-set.position
- the position of the context node
-
getDocumentOrder
Returns the document order of the given node.- Returns:
- The document order of the given node
-
getElementById
Returns the element associated with the given identifier. Locates the element underneath the specified root node.- Parameters:
root
- The root nodeid
- The element's identifier- Returns:
- The first element in document order with the given identifier, or null if no such element was found
-
getVariable
Returns the XPath result bound to the given variable name. Returns null if the variable was not set.- Parameters:
name
- The variable name- Returns:
- The variable's value
-
getFunction
Returns the XPath function by the given name, or null if no such function is defined.- Parameters:
uri
- The function's namespace URIname
- The function's name within that URI- Returns:
- The XPath function by the given name, or null if no such function is defined
-
getNamespaceURI
Returns the namespace associated with the given prefix as defined in this context. Null is returned if no namespace has been defined.- Parameters:
prefix
- the namespace prefix- Returns:
- the namespace uri or null.
-
setPosition
public void setPosition(int position) Sets the position of the context node within the context node-set- Parameters:
the
- position of the context node within the context node-set- Throws:
IndexOutOfBoundsException
- when the position is not within the bounds of the context node-set.
-