org.inria.ns.reflex.xml.provider.jaxen
Class JaxenXPath

java.lang.Object
  extended by org.inria.ns.reflex.xml.provider.jaxen.JaxenXPath
All Implemented Interfaces:
CompiledExpression, XPath

public class JaxenXPath
extends Object
implements XPath

A compiled XPath expression backed by Jaxen (patched).

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.xml.CompiledExpression
CompiledExpression.Impl
 
Constructor Summary
JaxenXPath(String xpathExpr)
          Construct given an XPath expression string.
 
Method Summary
 Pattern asPattern()
          Return this expression as a pattern.
 boolean booleanValueOf(XPathContext context)
          Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context.
 Object evaluate(XPathContext context)
          Evaluate this XPath against a given context.
 XFactory getXFactory()
          Return the factory that built this compiled XPath expression.
 Number numberValueOf(XPathContext context)
          Retrieve a number-value interpretation of this XPath expression when evaluated against a given context.
 List selectNodes(XPathContext context)
          Select all nodes that are selectable by this XPath expression.
 Object selectSingleNode(XPathContext context)
          Select only the first node that is selectable by this XPath expression.
 String stringValueOf(XPathContext context)
          Retrieve a string-value interpretation of this XPath expression when evaluated against a given context.
 String toString()
          Return the normalized string of this XPath expression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JaxenXPath

public JaxenXPath(String xpathExpr)
           throws XPathSyntaxException
Construct given an XPath expression string.

Parameters:
xpathExpr - The XPath expression.
Throws:
XPathSyntaxException - If there is a syntax error while parsing the expression.
Method Detail

getXFactory

public XFactory getXFactory()
Return the factory that built this compiled XPath expression.

Specified by:
getXFactory in interface CompiledExpression
Returns:
The Jaxen XFactory.
See Also:
JaxenXFactory

evaluate

public Object evaluate(XPathContext context)
                throws XPathException
Evaluate this XPath against a given context.

If the expression evaluates to a single primitive (String, Number or Boolean) type, it is returned directly. Otherwise, the returned value is a List (anode-set, in the terms of the specification) of values.

When using this method, one must be careful to test the class of the returned objects, and of each of the composite members if a List is returned. If the returned members are XML entities, they will be the actual Document, Element or Attribute objects as defined by the concrete XML object-model implementation, directly from the context document. This does not return copies of anything , but merely returns references to entities within the source document.

Specified by:
evaluate in interface CompiledExpression
Parameters:
context - is the Context which gets evaluated.
Returns:
The result of evaluating the XPath expression against the supplied context.
Throws:
XPathException

selectNodes

public List selectNodes(XPathContext context)
                 throws XPathException
Select all nodes that are selectable by this XPath expression. If multiple nodes match, multiple nodes will be returned.

NOTE: In most cases, nodes will be returned in document-order, as defined by the XML Canonicalization specification. The exception occurs when using XPath expressions involving the union operator (denoted with the pipe '|' character).

Specified by:
selectNodes in interface XPath
Parameters:
context - is the Context which gets evaluated.
Returns:
The node-set of all items selected by this XPath expression.
Throws:
XPathException
See Also:
selectSingleNode(org.inria.ns.reflex.xml.xpath.XPathContext)

selectSingleNode

public Object selectSingleNode(XPathContext context)
                        throws XPathException
Select only the first node that is selectable by this XPath expression. If multiple nodes match, only one node will be returned. NOTE: In most cases, the selected node will be the first selectable node in document-order, as defined by the XML Canonicalization specification. The exception occurs when using XPath expressions involving the union operator (denoted with the pipe '|' character).

Specified by:
selectSingleNode in interface XPath
Parameters:
context - is the Context which gets evaluated.
Returns:
The node-set of all items selected by this XPath expression.
Throws:
XPathException
See Also:
selectNodes(org.inria.ns.reflex.xml.xpath.XPathContext)

stringValueOf

public String stringValueOf(XPathContext context)
                     throws XPathException
Retrieve a string-value interpretation of this XPath expression when evaluated against a given context.

The string-value of the expression is determined per the string(..) core function as defined in the XPath specification. This means that an expression that selects more than one nodes will return the string value of the first node in the node set..

Specified by:
stringValueOf in interface XPath
Parameters:
context - is the Context which gets evaluated.
Returns:
The string-value interpretation of this expression.
Throws:
XPathException

booleanValueOf

public boolean booleanValueOf(XPathContext context)
                       throws XPathException
Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context.

The boolean-value of the expression is determined per the boolean(..) core function as defined in the XPath specification. This means that an expression that selects zero nodes will return false, while an expression that selects one-or-more nodes will return true.

Specified by:
booleanValueOf in interface XPath
Parameters:
context - is the Context which gets evaluated.
Returns:
The boolean-value interpretation of this expression.
Throws:
XPathException

numberValueOf

public Number numberValueOf(XPathContext context)
                     throws XPathException
Retrieve a number-value interpretation of this XPath expression when evaluated against a given context.

The number-value of the expression is determined per the number(..) core function as defined in the XPath specification. This means that if this expression selects multiple nodes, the number-value of the first node is returned.

Specified by:
numberValueOf in interface XPath
Parameters:
context - is the Context which gets evaluated.
Returns:
The number-value interpretation of this expression.
Throws:
XPathException

toString

public String toString()
Return the normalized string of this XPath expression.

During parsing, the XPath expression is normalized, removing abbreviations and other convenience notation. This method returns the fully normalized representation of the original expression.

Overrides:
toString in class Object
Returns:
The normalized XPath expression string.

asPattern

public Pattern asPattern()
                  throws BadPatternException
Return this expression as a pattern.

Specified by:
asPattern in interface CompiledExpression
Returns:
A Jaxen pattern.
Throws:
BadPatternException
See Also:
CompiledExpression.asPattern()