Class JaxenXPath

java.lang.Object
  extended by XPath
      extended by JaxenXPath
All Implemented Interfaces:
java.io.Serializable

 class JaxenXPath
extends XPath

A non-public concrete XPath implementation for Jaxen.


Nested Class Summary
private  class JaxenXPath.NSContext
           
 
Field Summary
private  java.lang.Object currentContext
          The current context for XPath expression evaluation.
private static java.lang.String CVS_ID
           
private  org.jaxen.jdom.JDOMXPath xPath
          The compiled XPath object to select nodes.
 
Constructor Summary
JaxenXPath(java.lang.String expr)
          Creates a new XPath wrapper object, compiling the specified XPath expression.
 
Method Summary
 void addNamespace(Namespace namespace)
          Adds a namespace definition to the list of namespaces known of this XPath expression.
 boolean equals(java.lang.Object o)
           
 java.lang.String getXPath()
          Returns the wrapped XPath expression as a string.
 int hashCode()
           
 java.lang.Number numberValueOf(java.lang.Object context)
          Returns the number value of the first item selected by applying the wrapped XPath expression to the given context.
 java.util.List selectNodes(java.lang.Object context)
          Evaluates the wrapped XPath expression and returns the list of selected items.
 java.lang.Object selectSingleNode(java.lang.Object context)
          Evaluates the wrapped XPath expression and returns the first entry in the list of selected nodes (or atomics).
 void setVariable(java.lang.String name, java.lang.Object value)
          Defines an XPath variable and sets its value.
private  void setXPath(java.lang.String expr)
          Compiles and sets the XPath expression wrapped by this object.
 java.lang.String toString()
           
 java.lang.String valueOf(java.lang.Object context)
          Returns the string value of the first node selected by applying the wrapped XPath expression to the given context.
 
Methods inherited from class XPath
addNamespace, newInstance, selectNodes, selectSingleNode, setXPathClass, writeReplace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CVS_ID

private static final java.lang.String CVS_ID
See Also:
Constant Field Values

xPath

private transient org.jaxen.jdom.JDOMXPath xPath
The compiled XPath object to select nodes. This attribute can not be made final as it needs to be set upon object deserialization.


currentContext

private java.lang.Object currentContext
The current context for XPath expression evaluation.

Constructor Detail

JaxenXPath

public JaxenXPath(java.lang.String expr)
           throws JDOMException
Creates a new XPath wrapper object, compiling the specified XPath expression.

Parameters:
expr - the XPath expression to wrap.
Throws:
JDOMException - if the XPath expression is invalid.
Method Detail

selectNodes

public java.util.List selectNodes(java.lang.Object context)
                           throws JDOMException
Evaluates the wrapped XPath expression and returns the list of selected items.

Specified by:
selectNodes in class XPath
Parameters:
context - the node to use as context for evaluating the XPath expression.
Returns:
the list of selected items, which may be of types: Element, Attribute, Text, CDATA, Comment, ProcessingInstruction, Boolean, Double, or String.
Throws:
JDOMException - if the evaluation of the XPath expression on the specified context failed.

selectSingleNode

public java.lang.Object selectSingleNode(java.lang.Object context)
                                  throws JDOMException
Evaluates the wrapped XPath expression and returns the first entry in the list of selected nodes (or atomics).

Specified by:
selectSingleNode in class XPath
Parameters:
context - the node to use as context for evaluating the XPath expression.
Returns:
the first selected item, which may be of types: Element, Attribute, Text, CDATA, Comment, ProcessingInstruction, Boolean, Double, String, or null if no item was selected.
Throws:
JDOMException - if the evaluation of the XPath expression on the specified context failed.

valueOf

public java.lang.String valueOf(java.lang.Object context)
                         throws JDOMException
Returns the string value of the first node selected by applying the wrapped XPath expression to the given context.

Specified by:
valueOf in class XPath
Parameters:
context - the element to use as context for evaluating the XPath expression.
Returns:
the string value of the first node selected by applying the wrapped XPath expression to the given context.
Throws:
JDOMException - if the XPath expression is invalid or its evaluation on the specified context failed.

numberValueOf

public java.lang.Number numberValueOf(java.lang.Object context)
                               throws JDOMException
Returns the number value of the first item selected by applying the wrapped XPath expression to the given context.

Specified by:
numberValueOf in class XPath
Parameters:
context - the element to use as context for evaluating the XPath expression.
Returns:
the number value of the first item selected by applying the wrapped XPath expression to the given context, null if no node was selected or the special value Double.NaN (Not-a-Number) if the selected value can not be converted into a number value.
Throws:
JDOMException - if the XPath expression is invalid or its evaluation on the specified context failed.

setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value)
                 throws java.lang.IllegalArgumentException
Defines an XPath variable and sets its value.

Specified by:
setVariable in class XPath
Parameters:
name - the variable name.
value - the variable value.
Throws:
java.lang.IllegalArgumentException - if name is not a valid XPath variable name or if the value type is not supported by the underlying implementation

addNamespace

public void addNamespace(Namespace namespace)
Adds a namespace definition to the list of namespaces known of this XPath expression.

Note: In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI.

Specified by:
addNamespace in class XPath
Parameters:
namespace - the namespace.

getXPath

public java.lang.String getXPath()
Returns the wrapped XPath expression as a string.

Specified by:
getXPath in class XPath
Returns:
the wrapped XPath expression as a string.

setXPath

private void setXPath(java.lang.String expr)
               throws JDOMException
Compiles and sets the XPath expression wrapped by this object.

Parameters:
expr - the XPath expression to wrap.
Throws:
JDOMException - if the XPath expression is invalid.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object