Class XPathImpl
- All Implemented Interfaces:
XPath
public class XPathImpl extends Object implements XPath
- Version:
- $Revision: 524814 $
- Author:
- Ramesh Mandava
-
Method Summary
Modifier and Type Method Description XPathExpressioncompile(String expression)Compile an XPath expression for later evaluation.Stringevaluate(String expression, Object item)Evaluate an XPath expression in the specified context and return the result as aString.Objectevaluate(String expression, Object item, QName returnType)Evaluate anXPathexpression in the specified context and return the result as the specified type.Stringevaluate(String expression, InputSource source)Evaluate an XPath expression in the context of the specifiedInputSourceand return the result as aString.Objectevaluate(String expression, InputSource source, QName returnType)Evaluate an XPath expression in the context of the specifiedInputSourceand return the result as the specified type.NamespaceContextgetNamespaceContext()Returns the current namespace context.XPathFunctionResolvergetXPathFunctionResolver()Returns the current function resolver.XPathVariableResolvergetXPathVariableResolver()Returns the current variable resolver.voidreset()Reset thisXPathto its original configuration.voidsetNamespaceContext(NamespaceContext nsContext)Establishes a namespace context.voidsetXPathFunctionResolver(XPathFunctionResolver resolver)Establishes a function resolver.voidsetXPathVariableResolver(XPathVariableResolver resolver)Establishes a variable resolver.
-
Method Details
-
setXPathVariableResolver
Establishes a variable resolver.
- Specified by:
setXPathVariableResolverin interfaceXPath- Parameters:
resolver- Variable Resolver
-
getXPathVariableResolver
Returns the current variable resolver.
- Specified by:
getXPathVariableResolverin interfaceXPath- Returns:
- Current variable resolver
-
setXPathFunctionResolver
Establishes a function resolver.
- Specified by:
setXPathFunctionResolverin interfaceXPath- Parameters:
resolver- XPath function resolver
-
getXPathFunctionResolver
Returns the current function resolver.
- Specified by:
getXPathFunctionResolverin interfaceXPath- Returns:
- Current function resolver
-
setNamespaceContext
Establishes a namespace context.
- Specified by:
setNamespaceContextin interfaceXPath- Parameters:
nsContext- Namespace context to use
-
getNamespaceContext
Returns the current namespace context.
- Specified by:
getNamespaceContextin interfaceXPath- Returns:
- Current Namespace context
-
evaluate
public Object evaluate(String expression, Object item, QName returnType) throws XPathExpressionExceptionEvaluate an
XPathexpression in the specified context and return the result as the specified type.See "Evaluation of XPath Expressions" section of JAXP 1.3 spec for context item evaluation, variable, function and
QNameresolution and return type conversion.If
returnTypeis not one of the types defined inXPathConstants(NUMBER,STRING,BOOLEAN,NODEorNODESET) then anIllegalArgumentExceptionis thrown.If a
nullvalue is provided foritem, an empty document will be used for the context. IfexpressionorreturnTypeisnull, then aNullPointerExceptionis thrown.- Specified by:
evaluatein interfaceXPath- Parameters:
expression- The XPath expression.item- The starting context (node or node list, for example).returnType- The desired return type.- Returns:
- Result of evaluating an XPath expression as an
ObjectofreturnType. - Throws:
XPathExpressionException- Ifexpressioncannot be evaluated.IllegalArgumentException- IfreturnTypeis not one of the types defined inXPathConstants.NullPointerException- IfexpressionorreturnTypeisnull.
-
evaluate
Evaluate an XPath expression in the specified context and return the result as a
String.This method calls
evaluate(String expression, Object item, QName returnType)with areturnTypeofXPathConstants.STRING.See "Evaluation of XPath Expressions" of JAXP 1.3 spec for context item evaluation, variable, function and QName resolution and return type conversion.
If a
nullvalue is provided foritem, an empty document will be used for the context. Ifexpressionisnull, then aNullPointerExceptionis thrown.- Specified by:
evaluatein interfaceXPath- Parameters:
expression- The XPath expression.item- The starting context (node or node list, for example).- Returns:
- The
Stringthat is the result of evaluating the expression and converting the result to aString. - Throws:
XPathExpressionException- Ifexpressioncannot be evaluated.NullPointerException- Ifexpressionisnull.
-
compile
Compile an XPath expression for later evaluation.
If
expressioncontains anyXPathFunctions, they must be available via theXPathFunctionResolver. AnXPathExpressionExceptionwill be thrown if theXPathFunctioncannot be resovled with theXPathFunctionResolver.If
expressionisnull, aNullPointerExceptionis thrown.- Specified by:
compilein interfaceXPath- Parameters:
expression- The XPath expression.- Returns:
- Compiled XPath expression.
- Throws:
XPathExpressionException- Ifexpressioncannot be compiled.NullPointerException- Ifexpressionisnull.
-
evaluate
public Object evaluate(String expression, InputSource source, QName returnType) throws XPathExpressionExceptionEvaluate an XPath expression in the context of the specified
InputSourceand return the result as the specified type.This method builds a data model for the
InputSourceand callsevaluate(String expression, Object item, QName returnType)on the resulting document object.See "Evaluation of XPath Expressions" section of JAXP 1.3 spec for context item evaluation, variable, function and QName resolution and return type conversion.
If
returnTypeis not one of the types defined inXPathConstants, then anIllegalArgumentExceptionis thrown.If
expression,sourceorreturnTypeisnull, then aNullPointerExceptionis thrown.- Specified by:
evaluatein interfaceXPath- Parameters:
expression- The XPath expression.source- The input source of the document to evaluate over.returnType- The desired return type.- Returns:
- The
Objectthat encapsulates the result of evaluating the expression. - Throws:
XPathExpressionException- If expression cannot be evaluated.IllegalArgumentException- IfreturnTypeis not one of the types defined inXPathConstants.NullPointerException- Ifexpression,sourceorreturnTypeisnull.
-
evaluate
Evaluate an XPath expression in the context of the specified
InputSourceand return the result as aString.This method calls
evaluate(String expression, InputSource source, QName returnType)with areturnTypeofXPathConstants.STRING.See "Evaluation of XPath Expressions" section of JAXP 1.3 spec for context item evaluation, variable, function and QName resolution and return type conversion.
If
expressionorsourceisnull, then aNullPointerExceptionis thrown.- Specified by:
evaluatein interfaceXPath- Parameters:
expression- The XPath expression.source- TheInputSourceof the document to evaluate over.- Returns:
- The
Stringthat is the result of evaluating the expression and converting the result to aString. - Throws:
XPathExpressionException- If expression cannot be evaluated.NullPointerException- Ifexpressionorsourceisnull.
-
reset
public void reset()Reset this
XPathto its original configuration.XPathis reset to the same state as when it was created withXPathFactory#newXPath().reset()is designed to allow the reuse of existingXPaths thus saving resources associated with the creation of newXPaths.The reset
XPathis not guaranteed to have the sameXPathFunctionResolver,XPathVariableResolverorNamespaceContextObjects, e.g.Object.equals(Object obj). It is guaranteed to have a functionally equalXPathFunctionResolver,XPathVariableResolverandNamespaceContext.
-