T
- The generic type of the returned results.public class XPathBuilder<T>
extends java.lang.Object
XPathExpression
instances without having
to manage your own Namespace and Variable contexts.Constructor and Description |
---|
XPathBuilder(java.lang.String expression,
Filter<T> filter)
Create a skeleton XPathBuilder with the given expression and result
filter.
|
Modifier and Type | Method and Description |
---|---|
XPathExpression<T> |
compileWith(XPathFactory factory)
Compile an XPathExpression using the details currently stored in the
XPathBuilder.
|
java.lang.String |
getExpression()
Get the XPath expression.
|
Filter<T> |
getFilter()
Get the Filter instance used for coercion.
|
Namespace |
getNamespace(java.lang.String prefix)
Get the Namespace associated with the given prefix.
|
java.lang.Object |
getVariable(java.lang.String qname)
Get the variable value associated with the given name.
|
boolean |
setNamespace(Namespace namespace)
Define a Namespace to be available for the XPath expression.
|
boolean |
setNamespace(java.lang.String prefix,
java.lang.String uri)
Define a Namespace to be available for the XPath expression.
|
boolean |
setNamespaces(java.util.Collection<Namespace> namespaces)
Add a number of namespaces to this XPathBuilder
|
boolean |
setVariable(java.lang.String qname,
java.lang.Object value)
Define or redefine an XPath expression variable value.
|
public boolean setVariable(java.lang.String qname, java.lang.Object value)
Variables without a prefix are in the "" Namespace.
Variables can have a null value. The XPathExpression
can change
the variable value before the expression is evaluated, and, some XPath
libraries support a null variable value. See
XPathExpression.setVariable(String, Namespace, Object)
.
In order to validate that a Variable is unique you have to know the
namespace associated with the prefix. This class is designed to make it
possible to make the namespace associations after the variables have been
added. As a result it is not possible to validate the uniqueness of a
variable name until the compileWith(XPathFactory)
method is
called.
As a consequence of the above, this class assumes that each unique prefix
is for a unique Namespace URI (thus calling this method with different
QNames is assumed to be setting different variables). This may lead to an
IllegalArgumentException when the compileWith(XPathFactory)
method is called.
This method does not validate the format of the variable name either, it instead postpones the validation until the expression is compiled. As a result you may encounter IllegalArgumentExceptions at compile time if the variable names are not valid XPath QNames ("name" or "prefix:name").
qname
- The variable name to define.value
- The variable value to set.java.lang.NullPointerException
- if the name is null.public boolean setNamespace(java.lang.String prefix, java.lang.String uri)
prefix
- The namespace prefix to define.uri
- The namespace URI to define.public boolean setNamespace(Namespace namespace)
namespace
- The namespace to define.java.lang.NullPointerException
- if the namespace is null.public boolean setNamespaces(java.util.Collection<Namespace> namespaces)
namespaces
- The namespaces to set.java.lang.NullPointerException
- if the namespace collection, or any of its members are null.public java.lang.Object getVariable(java.lang.String qname)
setVariable(String, Object)
for notes on how the Namespaces need
to be established before an authoritative reference to a variable can be
made. As a result, this method uses the simple variable QName name to
reference the variable.qname
- The variable name to get the variable value for.java.lang.NullPointerException
- if the qname is null.public Namespace getNamespace(java.lang.String prefix)
prefix
- The Namespace prefix to get the Namespace for.public Filter<T> getFilter()
public java.lang.String getExpression()
public XPathExpression<T> compileWith(XPathFactory factory)
factory
- The XPath factory to use for compiling.java.lang.IllegalArgumentException
- if the expression cannot be compiled.Copyright © 2021 Jason Hunter, Brett McLaughlin. All Rights Reserved.