Package org.apache.commons.jxpath
Interface CompiledExpression
- All Known Implementing Classes:
JXPathCompiledExpression
public interface CompiledExpression
Represents a compiled XPath. The interpretation of compiled XPaths may be faster, because it bypasses the compilation step. The reference implementation of
JXPathContext
also globally caches some of the results of compilation, so the direct use of JXPathContext is not always less efficient than the use
of CompiledExpression.
Use CompiledExpression only when there is a need to evaluate the same expression multiple times and the CompiledExpression can be conveniently cached.
To acquire a CompiledExpression, call JXPathContext.compile
-
Method Summary
Modifier and TypeMethodDescriptioncreatePath
(JXPathContext context) Creates intermediate elements of the path by invoking anAbstractFactory
, which should first be installed on the context by callingJXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)
.createPathAndSetValue
(JXPathContext context, Object value) The same as setValue, except it creates intermediate elements of the path by invoking anAbstractFactory
, which should first be installed on the context by callingJXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)
.getPointer
(JXPathContext context, String xpath) Traverses the XPath and returns a Pointer.getValue
(JXPathContext context) Evaluates the XPath and returns the resulting object.getValue
(JXPathContext context, Class requiredType) Evaluates the xpath, converts the result to the specified class and returns the resulting object.iterate
(JXPathContext context) Traverses the XPath and returns a Iterator of all results found for the path.iteratePointers
(JXPathContext context) Traverses the XPath and returns an Iterator of Pointers.void
removeAll
(JXPathContext context) Remove all graph elements described by this expression.void
removePath
(JXPathContext context) Remove the graph element described by this expression.void
setValue
(JXPathContext context, Object value) Modifies the value of the property described by the supplied xpath.
-
Method Details
-
createPath
Creates intermediate elements of the path by invoking anAbstractFactory
, which should first be installed on the context by callingJXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)
.- Parameters:
context
- base- Returns:
- Pointer created
-
createPathAndSetValue
The same as setValue, except it creates intermediate elements of the path by invoking anAbstractFactory
, which should first be installed on the context by callingJXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)
.Will throw an exception if one of the following conditions occurs:
- Elements of the XPath aleady exist, by the path does not in fact describe an existing property
- The AbstractFactory fails to create an instance for an intermediate element.
- The property is not writable (no public, non-static set method)
- Parameters:
context
- basevalue
- to set- Returns:
- Pointer created
-
getPointer
Traverses the XPath and returns a Pointer. A Pointer provides easy access to a property. If the XPath matches no properties in the graph, the pointer will be null.- Parameters:
context
- basexpath
- string- Returns:
- Pointer found
-
getValue
Evaluates the XPath and returns the resulting object. Primitive types are wrapped into objects.- Parameters:
context
- to evaluate- Returns:
- Object
-
getValue
Evaluates the xpath, converts the result to the specified class and returns the resulting object.- Parameters:
context
- to evaluaterequiredType
- return type- Returns:
- Object
-
iterate
Traverses the XPath and returns a Iterator of all results found for the path. If the XPath matches no properties in the graph, the Iterator will not be null.- Parameters:
context
- base- Returns:
- Iterator
-
iteratePointers
Traverses the XPath and returns an Iterator of Pointers. A Pointer provides easy access to a property. If the XPath matches no properties in the graph, the Iterator be empty, but not null.- Parameters:
context
- to iterate- Returns:
- Iterator
-
removeAll
Remove all graph elements described by this expression.- Parameters:
context
- base
-
removePath
Remove the graph element described by this expression.- Parameters:
context
- base
-
setValue
Modifies the value of the property described by the supplied xpath. Will throw an exception if one of the following conditions occurs:- The XPath does not in fact describe an existing property
- The property is not writable (no public, non-static set method)
- Parameters:
context
- basevalue
- to set
-