Top Description Fields Constructors Methods
org.jdom2.xpath.jaxen

pack-priv Class JaxenCompiled<T>

extends AbstractXPathCompiled<T>
implements NamespaceContext, VariableContext
Class Inheritance
All Implemented Interfaces
org.jaxen.VariableContext, org.jaxen.NamespaceContext
Type Parameters
<T>
The generic type of returned data.
Imports
java.util.ArrayList, .Iterator, .List, .Map, org.jaxen.BaseXPath, .JaxenException, .NamespaceContext, .UnresolvableException, .VariableContext, .XPath, org.jdom2.Namespace, org.jdom2.filter.Filter, org.jdom2.xpath.util.AbstractXPathCompiled

Jaxen specific code for XPath management.
Author
Rolf Lear

Field Summary

Modifier and TypeField and Description
private final XPath
xPath

The compiled XPath object to select nodes.

Constructor Summary

AccessConstructor and Description
public
JaxenCompiled(String
The XPath expression
expression
,
Filter<T>
The coercion filter
filter
,
Map<String, Object>
The XPath variable context
variables
,
Namespace[]
The XPath namespace context
namespaces
)

private
JaxenCompiled(JaxenCompiled<T>
The JaxenCompiled instance to clone
toclone
)

Make a copy-constructor available to the clone() method.

Method Summary

Modifier and TypeMethod and Description
public JaxenCompiled<T>
clone()

Overrides org.jdom2.xpath.util.AbstractXPathCompiled.clone.

Implements org.jdom2.xpath.XPathExpression.clone.

Subclasses of this AbstractXPathCompile class must call super.clone() in their clone methods!
protected List<?>
evaluateRawAll(Object
The context against which to evaluate the query
context
)

Implements abstract org.jdom2.xpath.util.AbstractXPathCompiled.evaluateRawAll.

This is the raw expression evaluator to be implemented by the back-end XPath library.
protected Object
evaluateRawFirst(Object
The context against which to evaluate the query
context
)

Implements abstract org.jdom2.xpath.util.AbstractXPathCompiled.evaluateRawFirst.

This is the raw expression evaluator to be implemented by the back-end XPath library.
public Object
getVariableValue(String
the namespace URI to which the prefix parameter is bound in the XPath expression. If the variable reference expression had no prefix, the namespace URI is null.
namespaceURI
,
String
the prefix that was used in the variable reference expression; this value is ignored and has no effect
prefix
,
String
the local name of the variable-reference expression. If there is no prefix, then this is the whole name of the variable.
localName
)

Implements org.jaxen.VariableContext.getVariableValue.

An implementation should return the value of an XPath variable based on the namespace URI and local name of the variable-reference expression.
public String
translateNamespacePrefixToUri(String
the namespace prefix to resolve
prefix
)

Implements org.jaxen.NamespaceContext.translateNamespacePrefixToUri.

Translate the provided namespace prefix into the matching bound namespace URI.
private static final List<Object>

Returns:

The parameter list with NamespaceContainer instances replaced by the wrapped Namespace instances.
unWrap
(List<?>
A list potentially containing NamespaceContainer instances
results
)

Same story, need to be able to replace NamespaceContainer instances with Namespace content.

private static final Object

Returns:

The input parameter unless it is a NamespaceContainer in which case return the wrapped Namespace
unWrapNS
(Object
A result object which could potentially be a NamespaceContainer
o
)

Same story, need to be able to strip NamespaceContainer instances from Namespace content.

Inherited from org.jdom2.xpath.util.AbstractXPathCompiled:
diagnoseevaluateevaluateFirstgetExpressiongetFiltergetNamespacegetNamespacesgetVariablegetVariablegetVariablessetVariablesetVariabletoString

Field Detail

xPathback to summary
private final XPath xPath

The compiled XPath object to select nodes. This attribute can not be made final as it needs to be set upon object deserialization.

Constructor Detail

JaxenCompiledback to summary
public JaxenCompiled(String expression, Filter<T> filter, Map<String, Object> variables, Namespace[] namespaces)
Parameters
expression:String

The XPath expression

filter:Filter<T>

The coercion filter

variables:Map<String, Object>

The XPath variable context

namespaces:Namespace[]

The XPath namespace context

JaxenCompiledback to summary
private JaxenCompiled(JaxenCompiled<T> toclone)

Make a copy-constructor available to the clone() method. This is simpler than trying to do a deep clone anyway.

Parameters
toclone:JaxenCompiled<T>

The JaxenCompiled instance to clone

Method Detail

cloneback to summary
public JaxenCompiled<T> clone()

Overrides org.jdom2.xpath.util.AbstractXPathCompiled.clone.

Implements org.jdom2.xpath.XPathExpression.clone.

Doc from org.jdom2.xpath.util.AbstractXPathCompiled.clone.

Subclasses of this AbstractXPathCompile class must call super.clone() in their clone methods!

This would be a sample clone method from a subclass:

		public XPathExpression<T> clone() {
			@SuppressWarnings("unchecked")
			final MyXPathCompiled<T> ret = (MyXPathCompiled<T>)super.clone();
			// change any fields that need to be cloned.
			....
			return ret;
		}
Here's the documentation from 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.

Returns:JaxenCompiled<T>

Doc from org.jdom2.xpath.XPathExpression.clone.

a new XPathExpression instance that shares the same core details as this.

Annotations
@Override
evaluateRawAllback to summary
protected List<?> evaluateRawAll(Object context)

Implements abstract org.jdom2.xpath.util.AbstractXPathCompiled.evaluateRawAll.

Doc from org.jdom2.xpath.util.AbstractXPathCompiled.evaluateRawAll.

This is the raw expression evaluator to be implemented by the back-end XPath library.

Parameters
context:Object

The context against which to evaluate the query

Returns:List<?>

A list of XPath results.

Annotations
@Override
evaluateRawFirstback to summary
protected Object evaluateRawFirst(Object context)

Implements abstract org.jdom2.xpath.util.AbstractXPathCompiled.evaluateRawFirst.

Doc from org.jdom2.xpath.util.AbstractXPathCompiled.evaluateRawFirst.

This is the raw expression evaluator to be implemented by the back-end XPath library. When this method is processed the implementing library is free to stop processing when the result that would be the first result is retrieved.

Only the first value in the result will be processed (if any).

Parameters
context:Object

The context against which to evaluate the query

Returns:Object

The first item in the XPath results, or null if there are no results.

Annotations
@Override
getVariableValueback to summary
public Object getVariableValue(String namespaceURI, String prefix, String localName) throws UnresolvableException

Implements org.jaxen.VariableContext.getVariableValue.

Doc from org.jaxen.VariableContext.getVariableValue.

An implementation should return the value of an XPath variable based on the namespace URI and local name of the variable-reference expression.

It must not use the prefix parameter to select a variable, because a prefix could be bound to any namespace; the prefix parameter could be used in debugging output or other generated information. The prefix may otherwise be ignored.

Parameters
namespaceURI:String

the namespace URI to which the prefix parameter is bound in the XPath expression. If the variable reference expression had no prefix, the namespace URI is null.

prefix:String

the prefix that was used in the variable reference expression; this value is ignored and has no effect

localName:String

the local name of the variable-reference expression. If there is no prefix, then this is the whole name of the variable.

Returns:Object

the variable's value (which can be null)

Annotations
@Override
Exceptions
UnresolvableException:
when the variable cannot be resolved
translateNamespacePrefixToUriback to summary
public String translateNamespacePrefixToUri(String prefix)

Implements org.jaxen.NamespaceContext.translateNamespacePrefixToUri.

Doc from org.jaxen.NamespaceContext.translateNamespacePrefixToUri.

Translate the provided namespace prefix into the matching bound namespace URI.

In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI. This method should return null for the empty prefix. Similarly, the prefix "xml" always resolves to the URI "http://www.w3.org/XML/1998/namespace".

Parameters
prefix:String

the namespace prefix to resolve

Returns:String

the namespace URI bound to the prefix; or null if there is no such namespace

Annotations
@Override
unWrapback to summary
private static final List<Object> unWrap(List<?> results)

Same story, need to be able to replace NamespaceContainer instances with Namespace content.

Parameters
results:List<?>

A list potentially containing NamespaceContainer instances

Returns:List<Object>

The parameter list with NamespaceContainer instances replaced by the wrapped Namespace instances.

unWrapNSback to summary
private static final Object unWrapNS(Object o)

Same story, need to be able to strip NamespaceContainer instances from Namespace content.

Parameters
o:Object

A result object which could potentially be a NamespaceContainer

Returns:Object

The input parameter unless it is a NamespaceContainer in which case return the wrapped Namespace