T
- The generic type of the returned values.public abstract class AbstractXPathCompiled<T> extends java.lang.Object implements XPathExpression<T>
super.clone();
Constructor and Description |
---|
AbstractXPathCompiled(java.lang.String query,
Filter<T> filter,
java.util.Map<java.lang.String,java.lang.Object> variables,
Namespace[] namespaces)
Construct an XPathExpression.
|
Modifier and Type | Method and Description |
---|---|
XPathExpression<T> |
clone()
Subclasses of this AbstractXPathCompile class must call super.clone() in
their clone methods!
|
XPathDiagnostic<T> |
diagnose(java.lang.Object context,
boolean firstonly)
Evaluate the XPath query against the supplied context, but return
additional data which may be useful for diagnosing problems with XPath
queries.
|
java.util.List<T> |
evaluate(java.lang.Object context)
Process the compiled XPathExpression against the specified context.
|
T |
evaluateFirst(java.lang.Object context)
Return the first value in the XPath query result set type-cast to the
return type of this XPathExpression.
|
protected abstract java.util.List<?> |
evaluateRawAll(java.lang.Object context)
This is the raw expression evaluator to be implemented by the back-end
XPath library.
|
protected abstract java.lang.Object |
evaluateRawFirst(java.lang.Object context)
This is the raw expression evaluator to be implemented by the back-end
XPath library.
|
java.lang.String |
getExpression()
Get the XPath expression
|
Filter<T> |
getFilter()
Get the
Filter<T> used to coerce the raw XPath results in to
the correct Generic type. |
Namespace |
getNamespace(java.lang.String prefix)
Get the Namespace associated with a given prefix.
|
Namespace[] |
getNamespaces()
Get the Namespaces that were used to compile this XPathExpression.
|
java.lang.Object |
getVariable(java.lang.String qname)
Get the variable value associated to the given variable qname.
|
java.lang.Object |
getVariable(java.lang.String name,
Namespace uri)
Get the variable value associated to the given variable name.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
getVariables()
utility method that allows descendant classes to access the variables
that were set on this expression, in a format that can be used in a constructor (qname/value).
|
java.lang.Object |
setVariable(java.lang.String name,
Namespace uri,
java.lang.Object value)
Change the defined value for a variable to some new value.
|
java.lang.Object |
setVariable(java.lang.String qname,
java.lang.Object value)
Change the defined value for a variable to some new value.
|
java.lang.String |
toString() |
public AbstractXPathCompiled(java.lang.String query, Filter<T> filter, java.util.Map<java.lang.String,java.lang.Object> variables, Namespace[] namespaces)
query
- The XPath queryfilter
- The coercion filter.variables
- A map of variables.namespaces
- The namespaces referenced from the query.for conditions which throw
{@link NullPointerException} or {@link IllegalArgumentException}.
public XPathExpression<T> clone()
This would be a sample clone method from a subclass:
Here's the documentation from
public XPathExpression<T> clone() {
@SuppressWarnings("unchecked")
final MyXPathCompiled<T> ret = (MyXPathCompiled<T>)super.clone();
// change any fields that need to be cloned.
....
return ret;
}
XPathExpression.clone()
Create a new instance of this XPathExpression that duplicates this instance.
The 'cloned' instance will have the same XPath query, namespace declarations, and variables. Changing a value associated with a variable on the cloned instance will not change this instance's values, and it is safe to run the evaluate methods on the cloned copy at the same time as this copy.
clone
in interface XPathExpression<T>
clone
in class java.lang.Object
public final java.lang.String getExpression()
XPathExpression
getExpression
in interface XPathExpression<T>
public final Namespace getNamespace(java.lang.String prefix)
XPathExpression
getNamespace
in interface XPathExpression<T>
prefix
- The prefix to select the Namespace URI for.public Namespace[] getNamespaces()
XPathExpression
getNamespaces
in interface XPathExpression<T>
public final java.lang.Object getVariable(java.lang.String name, Namespace uri)
XPathExpression
getVariable
in interface XPathExpression<T>
name
- the variable localname to retrieve the value for.uri
- the Namespace in which the variable name was declared.public java.lang.Object getVariable(java.lang.String qname)
XPathExpression
qname must consist of an optional namespace prefix and colon, followed
by a mandatory variable localname. If the prefix is not specified, then
the Namespace is assumed to be the Namespace.NO_NAMESPACE
. If
the prefix is specified, it must match with one of the declared
Namespaces for this XPathExpression
getVariable
in interface XPathExpression<T>
qname
- the variable qname to retrieve the value for.public java.lang.Object setVariable(java.lang.String name, Namespace uri, java.lang.Object value)
XPathExpression
The value of the variable may be null. Some XPath libraries support a null value, and if the library that this expression is for does not support a null value it should be translated to something meaningful for that library, typically the empty string.
setVariable
in interface XPathExpression<T>
name
- The variable localname to change.uri
- the Namespace in which the variable name is declared.value
- The new value to set.public java.lang.Object setVariable(java.lang.String qname, java.lang.Object value)
XPathExpression
The value of the variable may be null. Some XPath libraries support a null value, and if the library that this expression is for does not support a null value it should be translated to something meaningful for that library, typically the empty string.
qname must consist of an optional namespace prefix and colon, followed
by a mandatory variable localname. If the prefix is not specified, then
the Namespace is assumed to be the Namespace.NO_NAMESPACE
. If
the prefix is specified, it must match with one of the declared
Namespaces for this XPathExpression
setVariable
in interface XPathExpression<T>
qname
- The variable qname to change.value
- The new value to set.protected java.util.Map<java.lang.String,java.lang.Object> getVariables()
public final Filter<T> getFilter()
XPathExpression
Filter<T>
used to coerce the raw XPath results in to
the correct Generic type.getFilter
in interface XPathExpression<T>
Filter<T>
used to coerce the raw XPath results in to
the correct Generic type.public java.util.List<T> evaluate(java.lang.Object context)
XPathExpression
In the JDOM2 XPath API the results of the raw XPath query are processed
by the attached Filter<T>
instance to coerce the results in to
the correct generic type for this XPathExpression. The Filter process may
cause some XPath results to be removed from the final results. You may
instead want to call the XPathExpression.diagnose(Object, boolean)
method to
have access to both the raw XPath results as well as the filtered and
generically typed results.
evaluate
in interface XPathExpression<T>
context
- The context against which to process the query.public T evaluateFirst(java.lang.Object context)
XPathExpression
The concept of the 'first' result is applied before any JDOM Filter is applied. Thus, if the underlying XPath query has some results, the first result is sent through the filter. If it matches it is returned, if it does not match, then null is returned (even if some subsequent result underlying XPath result would pass the filter).
This allows the XPath implementation to optimise the evaluateFirst method by potentially using 'short-circuit' conditions in the evaluation.
evaluateFirst
in interface XPathExpression<T>
context
- The context against which to evaluate the expression. This will
typically be a Document, Element, or some other JDOM object.public XPathDiagnostic<T> diagnose(java.lang.Object context, boolean firstonly)
XPathExpression
diagnose
in interface XPathExpression<T>
context
- The context against which to run the query.firstonly
- Indicate whether the XPath expression can be terminated after the
first successful result value.XPathDiagnostic
instance.public java.lang.String toString()
toString
in class java.lang.Object
protected abstract java.util.List<?> evaluateRawAll(java.lang.Object context)
context
- The context against which to evaluate the queryprotected abstract java.lang.Object evaluateRawFirst(java.lang.Object context)
Only the first value in the result will be processed (if any).
context
- The context against which to evaluate the queryCopyright © 2021 Jason Hunter, Brett McLaughlin. All Rights Reserved.