public abstract class JaxpXPathEvaluator extends Object implements XPathEvaluator, XPathVariableResolver
XPathEvaluator. Because it's based on the JAXP API (JSR-206), it's ideal
for keeping a common code base which can work with different engines, as long as they implement that API.
This base class contains all of the logic necessary to comply with the XPathEvaluator contract. Implementations only
need to implement createXPathFactory() in order to provide the XPathFactory implementation it wishes to use.
Another important feature of this implementation is that it caches compiled versions of executed expressions to provide better
performance. Expressions that haven't been used for more than a minute are automatically evicted.
In addition to the registerNamespaces(Map) and registerNamespaces(NamespaceManager) methods, this
implementation also provides out of the box support for the standard namespaces defined in XPathNamespaceContext
In order to allow binding expression parameters to flow variables, this class also implements the XPathVariableResolver
interface. Because this class caches compiled expressions which might be executed concurrently in different threads, we need a
way to correlate different Event instances to each invocation of the resolveVariable(QName) method. To do
that, it uses a ThreadLocal in the evaluationEvent attribute, so that we can determine the corresponding event
for each thread evaluating an XPath expression. Notice that because xpath evaluation is an operation that happens in RAM memory
(basically because the DOM Node needs to be completely loaded), we can use a ThreadLocal without risking
failure if this is executed in a non-blocking environment.| Constructor and Description |
|---|
JaxpXPathEvaluator() |
| Modifier and Type | Method and Description |
|---|---|
protected XPathExpression |
compile(String expression) |
protected abstract XPathFactory |
createXPathFactory()
Returns the
XPathFactory to be used when compiling expressions |
String |
evaluate(String xpathExpression,
Node input,
Event event)
|
Object |
evaluate(String xpathExpression,
Node input,
XPathReturnType returnType,
Event event)
Evaluates the
xpathExpression over the input and returns the evaluation as a type in concordance with
returnType. |
Map<String,String> |
getRegisteredNamespaces()
Returns a
Map with the registered namespaces. |
protected NamespaceContext |
newNamespaceContext() |
protected XPath |
newXPath() |
void |
registerNamespaces(Map<String,String> namespaces)
Registers the given namespaces so that they can be recognized during evaluation
|
void |
registerNamespaces(NamespaceManager namespaceManager)
Registers the namespaces in
namespaceManager |
Object |
resolveVariable(QName variableName)
Resolves the given variable against the flow variables in the
Event held by evaluationEvent |
protected abstract XPathFactory createXPathFactory()
XPathFactory to be used when compiling expressionsXPathFactorypublic String evaluate(String xpathExpression, Node input, Event event)
xpathExpression over the input and returns the evaluation as a String.
If xpathExpression contains parameters, they will be resolved against the flow variables in eventevaluate in interface XPathEvaluatorxpathExpression - the xpathExpression to be evaluatedinput - a Nodeevent - the current Event.public Object evaluate(String xpathExpression, Node input, XPathReturnType returnType, Event event)
xpathExpression over the input and returns the evaluation as a type in concordance with
returnType.
If xpathExpression contains parameters, they will be resolved against the flow variables in eventevaluate in interface XPathEvaluatorxpathExpression - the xpathExpression to be evaluatedinput - a NodereturnType - a XPathReturnType that will be used to decide the return type of the evaluationevent - the current Event.returnTypepublic Object resolveVariable(QName variableName)
Event held by evaluationEventresolveVariable in interface XPathVariableResolvervariableName - the variable namenullpublic void registerNamespaces(Map<String,String> namespaces)
registerNamespaces in interface XPathEvaluatornamespaces - a Map in which the key is a namespace prefix and the value is its URI as a Stringpublic void registerNamespaces(NamespaceManager namespaceManager)
namespaceManagerregisterNamespaces in interface XPathEvaluatornamespaceManager - a NamespaceManagerpublic Map<String,String> getRegisteredNamespaces()
Map with the registered namespaces. The key of the map is the namespace prefix and the value is its URI as
a String Returns an immutable map with the current registered namespaces. The returned map will not reflect any changes
performed afterwards.getRegisteredNamespaces in interface XPathEvaluatorMapprotected XPath newXPath()
protected XPathExpression compile(String expression) throws XPathExpressionException
XPathExpressionExceptionprotected NamespaceContext newNamespaceContext()
Copyright © 2003–2016 MuleSoft, Inc.. All rights reserved.