org.inria.ns.reflex.xml.xpath
Class XPathExpression

java.lang.Object
  extended by org.inria.ns.reflex.xml.xpath.Expression
      extended by org.inria.ns.reflex.xml.xpath.XPathExpression

public class XPathExpression
extends Expression

An XPathExpression is used to compute an XPath expression with a given data set.

The static method parseValueTemplate will compile a curly braces delimited XPath expression string in an XPathExpression object.

At runtime :

A Node may be used as context to compute the XPath expression. If specified, the XPathExpression used must return a Node object.

Dealing with namespace URIs

When prefixes are used in XPath expression, each must be mapped to a namespace URI; with this object, it may be done thanks to :

Author:
Philippe Poulard

Constructor Summary
XPathExpression(String expression)
          Creates a new instance of XPathExpression for an absolute expression that doesn't use namespace prefixes.
XPathExpression(String expression, Node node, Map namespaceURIs)
          Creates a new instance of XPathExpression.
XPathExpression(String expression, Node node, Map namespaceURIs, XFactory factory)
          Creates a new instance of XPathExpression.
 
Method Summary
 boolean booleanValueOf(XPathVariableResolver variableResolver)
          Provides a runtime computation of the compiled expression with the dataset.
 Object compute()
          Perform a runtime computation of the compiled expression.
 Object compute(XPathContext context)
          Provides a runtime computation of the compiled expression using the given dataset.
 Object compute(XPathVariableResolver variableResolver)
          Perform a runtime computation of the compiled expression with the dataset.
 Number numberValueOf(XPathVariableResolver variableResolver)
          Provides a runtime computation of the compiled expression with the dataset.
 List selectNodes(XPathVariableResolver variableResolver)
          Provides a runtime computation of the compiled expression with the dataset.
 Node selectSingleNode(XPathVariableResolver variableResolver)
          Provides a runtime computation of the compiled expression with the dataset.
 String stringValueOf(XPathVariableResolver variableResolver)
          Provides a runtime computation of the compiled expression with the dataset.
 
Methods inherited from class org.inria.ns.reflex.xml.xpath.Expression
compute, equals, getExpression, hashCode, parseValueTemplate, parseValueTemplate, parseValueTemplate, parseValueTemplate, parseValueTemplate, parseValueTemplate, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XPathExpression

public XPathExpression(String expression)
                throws XPathException
Creates a new instance of XPathExpression for an absolute expression that doesn't use namespace prefixes.

Parameters:
expression - The string used to compile the Expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.

XPathExpression

public XPathExpression(String expression,
                       Node node,
                       Map namespaceURIs)
                throws XPathException
Creates a new instance of XPathExpression.

Parameters:
expression - The string used to compile the Expression.
node - The node used for namespace prefix resolution when performing XPath expressions, or null if none.
namespaceURIs - A set of couple of { prefix , namespace URI } used for prefix resolution, or null if none.
Throws:
XPathException - If the given expression is not a valid XPath expression.

XPathExpression

public XPathExpression(String expression,
                       Node node,
                       Map namespaceURIs,
                       XFactory factory)
                throws XPathException
Creates a new instance of XPathExpression.

Parameters:
expression - The string used to compile the Expression.
node - The node used for namespace prefix resolution when performing XPath expressions, or null if none.
namespaceURIs - A set of couple of { prefix , namespace URI } used for prefix resolution, or null if none.
factory - The factory to use for parsing the XPath expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.
Method Detail

compute

public Object compute(XPathContext context)
               throws XPathException
Provides a runtime computation of the compiled expression using the given dataset.

Specified by:
compute in class Expression
Parameters:
variableResolver - The resolver used to retrieve the variables used for the computation.
Returns:
The result of the evaluated expression.
Throws:
XPathException - When the expression rises an XPath error at runtime.

compute

public Object compute()
               throws XPathException
Perform a runtime computation of the compiled expression. XPath variables ( $foo) are not bounded to a value. Single objects are unwrapped from their list (ArrayList).

Returns:
The result of the evaluated expression, as an Object.
Throws:
XPathException - When the expression rises an XPath error at runtime.

compute

public Object compute(XPathVariableResolver variableResolver)
               throws XPathException
Perform a runtime computation of the compiled expression with the dataset. Single objects are unwrapped from their list ( ArrayList). When using XPath variables, objects from the data set mustn't be ArrayList.

Overrides:
compute in class Expression
Parameters:
variableResolver - The set of variables used for the computation.
Returns:
The result of the evaluated expression, as an Object .
Throws:
XPathException - When the expression rises an XPath error at runtime.

selectSingleNode

public Node selectSingleNode(XPathVariableResolver variableResolver)
                      throws XPathException
Provides a runtime computation of the compiled expression with the dataset.

Parameters:
variableResolver - The set of variables used for the computation.
Returns:
The result of the evaluated expression, as a Node (if the expression gives more than one Node, the first one is returned).
Throws:
XPathException - When the expression rises an XPath error at runtime, or if a Node object can't be returned.

selectNodes

public List selectNodes(XPathVariableResolver variableResolver)
                 throws XPathException
Provides a runtime computation of the compiled expression with the dataset.

Parameters:
variableResolver - The set of variables used for the computation.
Returns:
The result of the evaluated expression, as a List.
Throws:
XPathException - When the expression rises an XPath error at runtime, or if a List object can't be returned.

booleanValueOf

public boolean booleanValueOf(XPathVariableResolver variableResolver)
                       throws XPathException
Provides a runtime computation of the compiled expression with the dataset.

Parameters:
variableResolver - The set of variables used for the computation.
Returns:
The result of the evaluated expression, as a boolean .
Throws:
XPathException - When the expression rises an XPath error at runtime.

stringValueOf

public String stringValueOf(XPathVariableResolver variableResolver)
                     throws XPathException
Provides a runtime computation of the compiled expression with the dataset.

Parameters:
variableResolver - The set of variables used for the computation.
Returns:
The result of the evaluated expression, as a String .
Throws:
XPathException - When the expression rises an XPath error at runtime.

numberValueOf

public Number numberValueOf(XPathVariableResolver variableResolver)
                     throws XPathException
Provides a runtime computation of the compiled expression with the dataset.

Parameters:
variableResolver - The set of variables used for the computation.
Returns:
The result of the evaluated expression, as a Number .
Throws:
XPathException - When the expression rises an XPath error at runtime.