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

java.lang.Object
  extended by org.inria.ns.reflex.xml.xpath.Expression
Direct Known Subclasses:
MixedExpression, StringExpression, XPathExpression

public abstract class Expression
extends Object

An expression is a string that is interpreted as an attribute value template (AVT) in XSLT.

Each expression surrounded by curly braces ({}) stands for an XPath expression. Properties from the data set can be used as XPath variables references , like $varName

The static method parseValueTemplate will compile such a string in an Expression, that will be one of the following sub-types :

At runtime, the expression is computed with the dataset, thanks to the computemethod. The result may be :

Tip

To escape curly braces when parsing an expression, simply use " {{" and "}}" to get respectively " {" and "}".

Notice that the same result can be obtained without using escaping sequence thanks to XPath expression "{'{'}" and "{'}'}".

Author:
Philippe Poulard
See Also:
StringExpression, XPathExpression, MixedExpression, DataSet

Constructor Summary
Expression(String expression, XFactory factory)
          Wraps a string in an Expression object.
 
Method Summary
abstract  Object compute(XPathContext context)
          Provides a runtime computation of the compiled expression using the given dataset.
 Object compute(XPathVariableResolver variableResolver)
          Provides a runtime computation of the compiled expression using the given dataset.
 Object compute(XPathVariableResolver variableResolver, Object contextNode)
          Provides a runtime computation of the compiled expression using the given dataset.
 boolean equals(Object expression)
          Indicates whether some other Expression is "equal to" this one.
 String getExpression()
          Returns the expression string used to compile the Expression.
 int hashCode()
          Returns a hash code value for the Expression.
static Expression parseValueTemplate(Element element, String attributeName)
          Parses an expression string from an element's attribute, as an attribute value template to a compiled Expression.
static Expression parseValueTemplate(Element element, String namespaceURI, String localAttributeName)
          Parses an expression string from an element's attribute, as an attribute value template to a compiled Expression.
static Expression parseValueTemplate(Element element, String namespaceURI, String localAttributeName, XFactory factory)
          Parses an expression string from an element's attribute, as an attribute value template to a compiled Expression.
static Expression parseValueTemplate(String expression, Node node)
          Parses an expression string as an attribute value template to a compiled Expression.
static Expression parseValueTemplate(String expression, Node node, Map namespaceURIs)
          Parses an expression string as an attribute value template to a compiled Expression.
static Expression parseValueTemplate(String expression, Node node, Map namespaceURIs, XFactory factory)
          Parses an expression string as an attribute value template to a compiled Expression.
 String toString()
          Returns the expression string used to compile the Expression.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Expression

public Expression(String expression,
                  XFactory factory)
Wraps a string in an Expression object.

Parameters:
expression - The string to wrap.
factory - The factory that parses XPath expressions.
Method Detail

compute

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

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(XPathVariableResolver variableResolver,
                      Object contextNode)
               throws XPathException
Provides a runtime computation of the compiled expression using the given dataset.

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 abstract Object compute(XPathContext context)
                        throws XPathException
Provides a runtime computation of the compiled expression using the given dataset.

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.

getExpression

public String getExpression()
Returns the expression string used to compile the Expression.

Returns:
The expression string used to compile the Expression.

hashCode

public int hashCode()
Returns a hash code value for the Expression.

Overrides:
hashCode in class Object
Returns:
A hash code value for this Expression.

equals

public boolean equals(Object expression)
Indicates whether some other Expression is "equal to" this one.

Overrides:
equals in class Object
Parameters:
expression - The expression to compare.
Returns:
true if this Expression is the same as the expression argument; false otherwise.

toString

public String toString()
Returns the expression string used to compile the Expression.

Overrides:
toString in class Object
Returns:
The expression string used to compile the Expression.

parseValueTemplate

public static Expression parseValueTemplate(Element element,
                                            String attributeName)
                                     throws XPathException
Parses an expression string from an element's attribute, as an attribute value template to a compiled Expression.

Parameters:
element - The element to which belongs the attribute. Used for namespace prefix resolution when performing XPath expressions.
attributeName - The name of the attribute that contains the expression to parse.
Returns:
The compiled Expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.

parseValueTemplate

public static Expression parseValueTemplate(Element element,
                                            String namespaceURI,
                                            String localAttributeName)
                                     throws XPathException
Parses an expression string from an element's attribute, as an attribute value template to a compiled Expression.

Parameters:
element - The element to which belongs the attribute. Used for namespace prefix resolution when performing XPath expressions.
namespaceURI - The namespace URI of the attribute that contains the expression to parse.
localAttributeName - The local name of the attribute that contains the expression to parse.
Returns:
The compiled Expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.

parseValueTemplate

public static Expression parseValueTemplate(Element element,
                                            String namespaceURI,
                                            String localAttributeName,
                                            XFactory factory)
                                     throws XPathException
Parses an expression string from an element's attribute, as an attribute value template to a compiled Expression.

Parameters:
element - The element to which belongs the attribute. Used for namespace prefix resolution when performing XPath expressions.
namespaceURI - The namespace URI of the attribute that contains the expression to parse.
localAttributeName - The local name of the attribute that contains the expression to parse.
Returns:
The compiled Expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.

parseValueTemplate

public static Expression parseValueTemplate(String expression,
                                            Node node)
                                     throws XPathException
Parses an expression string as an attribute value template to a compiled Expression.

Parameters:
expression - The expression to parse.
node - The node used for namespace prefix resolution when performing XPath expressions.
Returns:
The compiled Expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.

parseValueTemplate

public static Expression parseValueTemplate(String expression,
                                            Node node,
                                            Map namespaceURIs)
                                     throws XPathException
Parses an expression string as an attribute value template to a compiled Expression.

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

parseValueTemplate

public static Expression parseValueTemplate(String expression,
                                            Node node,
                                            Map namespaceURIs,
                                            XFactory factory)
                                     throws XPathException
Parses an expression string as an attribute value template to a compiled Expression. XPath expressions are parsed with the default engine.

Parameters:
expression - The expression to parse.
node - The node used for namespace prefix resolution when performing XPath expressions.
namespaceURIs - A set of couple of { prefix , namespace URI } used for prefix resolution.
factory - The factory to use for parsing XPath expressions.
Returns:
The compiled Expression.
Throws:
XPathException - If the given expression is not a valid XPath expression.