|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.xpath.XPathExpressionImpl
public class XPathExpressionImpl
The JAXP XPathExpression interface represents a compiled XPath expression that can be repeatedly evaluated. This class is Saxon's implementation of that interface.
The class also includes some methods retained from Saxon's original XPath API. When these methods are used, the object contains the context node and other state, so it is not thread-safe.
Constructor Summary | |
---|---|
protected |
XPathExpressionImpl(Expression exp,
Executable exec)
The constructor is protected, to ensure that instances can only be created using the createExpression() method of XPathEvaluator |
Method Summary | |
---|---|
List |
evaluate()
Deprecated. since 9.0. This method is not present in the JAXP interface. Either use the JAXP methods such as evaluate(Object, QName) , or use the Saxon XPath
API instead of JAXP. |
String |
evaluate(InputSource inputSource)
Evaluate the XPath expression against an input source to obtain a string result |
Object |
evaluate(InputSource inputSource,
QName qName)
Evaluate the XPath expression against an input source to obtain a result of a specified type |
String |
evaluate(Object node)
Evaluate the expression to return a string value |
Object |
evaluate(Object node,
QName qName)
JAXP 1.3 evaluate() method |
Object |
evaluateSingle()
Deprecated. since 9.0. This method is not present in the JAXP interface. Either use the JAXP methods such as evaluate(Object, QName) , or use the Saxon XPath
API instead of JAXP. |
AtomicValue |
evaluateSortKey(int n,
XPathContext c)
Callback for evaluating the sort keys. |
Configuration |
getConfiguration()
Get the Configuration under which this XPath expression was compiled |
Expression |
getInternalExpression()
Low-level method to get the internal Saxon expression object. |
SlotManager |
getStackFrameMap()
Get the stack frame map. |
protected void |
privatelySetContextNode(NodeInfo node)
Protected, undeprecated version of setContextNode() for use by deprecated paths within the package (exists to avoid deprecation warnings when compiling Saxon) |
SequenceIterator |
rawIterator(Item contextItem)
Get a raw iterator over the results of the expression. |
void |
setContextNode(NodeInfo node)
Deprecated. since 9.0. Using this method is not thread-safe. Use a method instead such as evaluate(Object, QName) that allows the context node to be specified
as a parameter to the call. |
void |
setSortKey(XPathExpressionImpl sortKey)
Deprecated. since 9.0. This method is not present in the JAXP interface. The recommended way to get a sorted result is to use XQuery instead of XPath. |
protected void |
setStackFrameMap(SlotManager map)
Define the number of slots needed for local variables within the expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected XPathExpressionImpl(Expression exp, Executable exec)
exp
- the compiled expressionexec
- the executableMethod Detail |
---|
protected void setStackFrameMap(SlotManager map)
map
- description of the stack framepublic SlotManager getStackFrameMap()
public Configuration getConfiguration()
public void setSortKey(XPathExpressionImpl sortKey)
sortKey
- an XPathExpression, which will be applied to each item in the sequence;
the result of this expression determines the ordering of the list returned by the evaluate()
method. The sortKey can be null, to clear a previous sort key. Note that the expression is
not automatically atomized; if it selects nodes, these should be explicitly converted to
atomic values by calling the string() or data() functions.public void setContextNode(NodeInfo node)
evaluate(Object, QName)
that allows the context node to be specified
as a parameter to the call.
node
- the context nodeprotected void privatelySetContextNode(NodeInfo node)
node
- the context nodepublic List evaluate() throws XPathException
evaluate(Object, QName)
, or use the Saxon XPath
API instead of JAXP.
setContextNode(net.sf.saxon.om.NodeInfo)
.
evaluate(Object, javax.xml.namespace.QName)
with the second argument set to NODESET.
XPathException
public Object evaluateSingle() throws XPathException
evaluate(Object, QName)
, or use the Saxon XPath
API instead of JAXP.
setContextNode(net.sf.saxon.om.NodeInfo)
.
XPathException
public SequenceIterator rawIterator(Item contextItem) throws XPathException
contextItem
- the context item for evaluating the expression
XPathException
public Object evaluate(Object node, QName qName) throws XPathExpressionException
evaluate
in interface XPathExpression
node
- The context node. This must use a representation of nodes that this implementation understands.
This may be a Saxon NodeInfo, or a node in one of the external object models supported, for example
DOM, DOM4J, JDOM, or XOM, provided the support module for that object model is loaded.
Contrary to the interface specification, Saxon does not supply an empty
document when the value is null. This is because Saxon supports multiple object models,
and it's unclear what kind of document node would be appropriate. Instead, Saxon uses
the node supplied to the setContextNode(net.sf.saxon.om.NodeInfo)
method if available, and if none
is available, executes the XPath expression with the context item undefined.
Saxon does not allow a NodeList to be supplied for this parameter. It's not clear what this would be intended to mean.
qName
- Indicates the type of result required. This must be one of the constants defined in
the JAXP XPathConstants
class.
Saxon will attempt to convert the actual result of the expression to the required type using the
XPath 1.0 conversion rules.
QName | Return Value |
BOOLEAN | The effective boolean value of the actual result, as a Java Boolean object |
STRING | The result of applying the string() function to the actual result, as a Java String object |
NUMBER | The result of applying the number() function to the actual result, as a Java Double object |
NODE | A single node, in the native data model supplied as input. If the expression returns more than one node, the first is returned. If the expression returns an empty sequence, null is returned. If the expression returns an atomic value, or if the first item in the result sequence is an atomic value, an exception is thrown. |
NODESET | This is interpreted as allowing any sequence, of nodes or atomic values. If the first argument is a wrapper around a DOM Node, then the result is returned as a DOM NodeList, and an exception is then thrown if the result sequence contains a value that is not a DOM Node. In all other cases the result is returned as a Java List object, unless it is empty, in which case null is returned. The contents of the list may be node objects (in the native data model supplied as input), or Java objects representing the XPath atomic values in the actual result: String for an xs:string, Double for a xs:double, Long for an xs:integer, and so on. (For safety, cast the values to a type such as xs:string within the XPath expression). |
XPathExpressionException
- if evaluation of the expression fails or if the
result cannot be converted to the requested type.public String evaluate(Object node) throws XPathExpressionException
evaluate
in interface XPathExpression
node
- the initial context node. This must be either an instance of NodeInfo or a node
recognized by a known external object model.
Contrary to the interface specification, Saxon does not supply an empty
document when the value is null. This is because Saxon supports multiple object models,
and it's unclear what kind of document node would be appropriate. Instead, Saxon uses
the node supplied to the setContextNode(net.sf.saxon.om.NodeInfo)
method if available, and if none
is available, executes the XPath expression with the context item undefined.
XPathExpressionException
- if evaluation failspublic Object evaluate(InputSource inputSource, QName qName) throws XPathExpressionException
evaluate
in interface XPathExpression
inputSource
- The input source document against which the expression is evaluated.
(Note that there is no caching. This will be parsed, and the parsed result will be discarded.)
If the supplied value is null then (contrary to the JAXP specifications), the XPath expression
is evaluated with the context item undefined.qName
- The type required, identified by a constant in XPathConstants
evaluate(Object, javax.xml.namespace.QName)
XPathExpressionException
public String evaluate(InputSource inputSource) throws XPathExpressionException
evaluate
in interface XPathExpression
inputSource
- The input source document against which the expression is evaluated.
(Note that there is no caching. This will be parsed, and the parsed result will be discarded.)
XPathExpressionException
- in the event of an XPath dynamic error
NullPointerException
- If inputSource
is null
.public AtomicValue evaluateSortKey(int n, XPathContext c) throws XPathException
evaluateSortKey
in interface SortKeyEvaluator
XPathException
public Expression getInternalExpression()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |