Package org.apache.commons.jxpath.ri
Class JXPathContextReferenceImpl
java.lang.Object
org.apache.commons.jxpath.JXPathContext
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl
The reference implementation of JXPathContext.
- Version:
- $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static int
private static Map
private static final Compiler
private Pointer
protected NamespaceResolver
Namespace resolverprivate static final Vector
private static NodePointerFactory[]
private Pointer
static final boolean
Change this tofalse
to disable soft caching of CompiledExpressions.Fields inherited from class org.apache.commons.jxpath.JXPathContext
contextBean, decimalFormats, factory, functions, idManager, keyManager, parentContext, vars
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JXPathContextReferenceImpl
(JXPathContext parentContext, Object contextBean) Create a new JXPathContextReferenceImpl.JXPathContextReferenceImpl
(JXPathContext parentContext, Object contextBean, Pointer contextPointer) Create a new JXPathContextReferenceImpl. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addNodePointerFactory
(NodePointerFactory factory) Call this with a custom NodePointerFactory to add support for additional types of objects.static Object
allocateConditionally
(String className, String existenceCheckClassName) Checks if existenceCheckClass exists on the class path.private void
checkSimplePath
(Expression expr) Checks if the path follows the JXPath restrictions on the type of path that can be passed to create...private Expression
compileExpression
(String xpath) Compile the given expression.protected CompiledExpression
compilePath
(String xpath) Overridden by each concrete implementation of JXPathContext to perform compilation.private static void
Create the default node factory array.createPath
(String xpath) Creates missing elements of the path by invoking anAbstractFactory
, which should first be installed on the context by callingJXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)
.createPath
(String xpath, Expression expr) Create the given path.createPathAndSetValue
(String xpath, 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)
.createPathAndSetValue
(String xpath, Expression expr, Object value) Create the given path setting its value to value.Get the absolute root context.private NodePointer
Get absolute root pointer.protected Compiler
Returns a static instance of TreeCompiler.Returns a Pointer for the context bean.private EvalContext
Get the evaluation context.getFunction
(QName functionName, Object[] parameters) Get the named Function.Returns the namespace context pointer set withsetNamespaceContextPointer()
or, if none has been specified, the context pointer otherwise.Get the namespace resolver.getNamespaceURI
(String prefix) Given a prefix, returns a registered namespace URI.static NodePointerFactory[]
Get the registered NodePointerFactories.getPointer
(String xpath) Traverses the xpath and returns a Pointer.getPointer
(String xpath, Expression expr) Get a pointer to the specified path/expression.Get the prefix associated with the specifed namespace URI.getRelativeContext
(Pointer pointer) Returns a JXPathContext that is relative to the current JXPathContext.Traverses the xpath and returns the resulting object.Calls getValue(xpath), converts the result to the required type and returns the result of the conversion.getValue
(String xpath, Expression expr) Get the value indicated.getValue
(String xpath, Expression expr, Class requiredType) Get the value indicated.getVariablePointer
(QName name) Get a VariablePointer for the given variable name.Traverses the xpath and returns a Iterator of all results found for the path.iterate
(String xpath, Expression expr) Traverses the xpath and returns a Iterator of all results found for the path.iteratePointers
(String xpath) Traverses the xpath and returns an Iterator of Pointers.iteratePointers
(String xpath, Expression expr) Traverses the xpath and returns an Iterator of Pointers.void
registerNamespace
(String prefix, String namespaceURI) Registers a namespace prefix.void
Removes all elements of the object graph described by the xpath.void
removeAll
(String xpath, Expression expr) Remove all matching nodes.void
removePath
(String xpath) Removes the element of the object graph described by the xpath.void
removePath
(String xpath, Expression expr) Remove the specified path.void
setNamespaceContextPointer
(Pointer pointer) Namespace prefixes can be defined implicitly by specifying a pointer to a context where the namespaces are defined.void
Modifies the value of the property described by the supplied xpath.void
setValue
(String xpath, Expression expr, Object value) Set the value of xpath to value.private Pointer
setValue
(String xpath, Expression expr, Object value, boolean create) Set the specified value.Methods inherited from class org.apache.commons.jxpath.JXPathContext
compile, getContextBean, getDecimalFormatSymbols, getFactory, getFunctions, getIdentityManager, getKeyManager, getLocale, getNodeSetByKey, getParentContext, getPointerByID, getPointerByKey, getVariables, isLenient, newContext, newContext, selectNodes, selectSingleNode, setDecimalFormatSymbols, setFactory, setFunctions, setIdentityManager, setKeyManager, setLenient, setLocale, setVariables
-
Field Details
-
USE_SOFT_CACHE
public static final boolean USE_SOFT_CACHEChange this tofalse
to disable soft caching of CompiledExpressions.- See Also:
-
COMPILER
-
compiled
-
cleanupCount
private static int cleanupCount -
nodeFactoryArray
-
CLEANUP_THRESHOLD
private static final int CLEANUP_THRESHOLD- See Also:
-
nodeFactories
-
namespaceResolver
Namespace resolver -
rootPointer
-
contextPointer
-
-
Constructor Details
-
JXPathContextReferenceImpl
Create a new JXPathContextReferenceImpl.- Parameters:
parentContext
- parent contextcontextBean
- Object
-
JXPathContextReferenceImpl
public JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean, Pointer contextPointer) Create a new JXPathContextReferenceImpl.- Parameters:
parentContext
- parent contextcontextBean
- ObjectcontextPointer
- context pointer
-
-
Method Details
-
createNodeFactoryArray
private static void createNodeFactoryArray()Create the default node factory array. -
addNodePointerFactory
Call this with a custom NodePointerFactory to add support for additional types of objects. Make sure the factory returns a name that puts it in the right position on the list of factories.- Parameters:
factory
- NodePointerFactory to add
-
getNodePointerFactories
Get the registered NodePointerFactories.- Returns:
- NodePointerFactory[]
-
getCompiler
Returns a static instance of TreeCompiler. Override this to return an alternate compiler.- Returns:
- Compiler
-
compilePath
Description copied from class:JXPathContext
Overridden by each concrete implementation of JXPathContext to perform compilation. Is called bycompile()
.- Specified by:
compilePath
in classJXPathContext
- Parameters:
xpath
- to compile- Returns:
- CompiledExpression
-
compileExpression
Compile the given expression.- Parameters:
xpath
- to compile- Returns:
- Expression
-
getValue
Traverses the xpath and returns the resulting object. Primitive types are wrapped into objects.- Specified by:
getValue
in classJXPathContext
- Parameters:
xpath
- expression- Returns:
- Object found
-
getValue
Get the value indicated.- Parameters:
xpath
- Stringexpr
- Expression- Returns:
- Object
-
getValue
Calls getValue(xpath), converts the result to the required type and returns the result of the conversion.- Specified by:
getValue
in classJXPathContext
- Parameters:
xpath
- expressionrequiredType
- Class- Returns:
- Object
-
getValue
Get the value indicated.- Parameters:
xpath
- expressionexpr
- compiled ExpressionrequiredType
- Class- 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.- Specified by:
iterate
in classJXPathContext
- Parameters:
xpath
- expression- Returns:
- Iterator
-
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:
xpath
- expressionexpr
- compiled Expression- Returns:
- Iterator
-
getPointer
Description copied from class:JXPathContext
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.- Specified by:
getPointer
in classJXPathContext
- Parameters:
xpath
- desired- Returns:
- Pointer
-
getPointer
Get a pointer to the specified path/expression.- Parameters:
xpath
- Stringexpr
- compiled Expression- Returns:
- Pointer
-
setValue
Description copied from class:JXPathContext
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)
- Specified by:
setValue
in classJXPathContext
- Parameters:
xpath
- indicating positionvalue
- to set
-
setValue
Set the value of xpath to value.- Parameters:
xpath
- pathexpr
- compiled Expressionvalue
- Object
-
createPath
Description copied from class:JXPathContext
Creates missing 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 the AbstractFactory fails to create an instance for a path element.
- Specified by:
createPath
in classJXPathContext
- Parameters:
xpath
- indicating destination to create- Returns:
- pointer to new location
-
createPath
Create the given path.- Parameters:
xpath
- Stringexpr
- compiled Expression- Returns:
- resulting Pointer
-
createPathAndSetValue
Description copied from class:JXPathContext
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, but 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)
- Specified by:
createPathAndSetValue
in classJXPathContext
- Parameters:
xpath
- indicating position to createvalue
- to set- Returns:
- pointer to new location
-
createPathAndSetValue
Create the given path setting its value to value.- Parameters:
xpath
- Stringexpr
- compiled Expressionvalue
- Object- Returns:
- resulting Pointer
-
setValue
Set the specified value.- Parameters:
xpath
- pathexpr
- compiled Expressionvalue
- destination valuecreate
- whether to create missing node(s)- Returns:
- Pointer created
-
checkSimplePath
Checks if the path follows the JXPath restrictions on the type of path that can be passed to create... methods.- Parameters:
expr
- Expression to check
-
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.- Specified by:
iteratePointers
in classJXPathContext
- Parameters:
xpath
- expression- 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:
xpath
- expressionexpr
- compiled Expression- Returns:
- Iterator
-
removePath
Description copied from class:JXPathContext
Removes the element of the object graph described by the xpath.- Specified by:
removePath
in classJXPathContext
- Parameters:
xpath
- indicating position to remove
-
removePath
Remove the specified path.- Parameters:
xpath
- expressionexpr
- compiled Expression
-
removeAll
Description copied from class:JXPathContext
Removes all elements of the object graph described by the xpath.- Specified by:
removeAll
in classJXPathContext
- Parameters:
xpath
- indicating positions to remove
-
removeAll
Remove all matching nodes.- Parameters:
xpath
- expressionexpr
- compiled Expression
-
getRelativeContext
Description copied from class:JXPathContext
Returns a JXPathContext that is relative to the current JXPathContext. The supplied pointer becomes the context pointer of the new context. The relative context inherits variables, extension functions, locale etc from the parent context.- Specified by:
getRelativeContext
in classJXPathContext
- Parameters:
pointer
- Pointer- Returns:
- JXPathContext
-
getContextPointer
Description copied from class:JXPathContext
Returns a Pointer for the context bean.- Specified by:
getContextPointer
in classJXPathContext
- Returns:
- Pointer
-
getAbsoluteRootPointer
Get absolute root pointer.- Returns:
- NodePointer
-
getEvalContext
Get the evaluation context.- Returns:
- EvalContext
-
getAbsoluteRootContext
Get the absolute root context.- Returns:
- EvalContext
-
getVariablePointer
Get a VariablePointer for the given variable name.- Parameters:
name
- variable name- Returns:
- NodePointer
-
getFunction
Get the named Function.- Parameters:
functionName
- nameparameters
- function args- Returns:
- Function
-
registerNamespace
Description copied from class:JXPathContext
Registers a namespace prefix.- Overrides:
registerNamespace
in classJXPathContext
- Parameters:
prefix
- A namespace prefixnamespaceURI
- A URI for that prefix
-
getNamespaceURI
Description copied from class:JXPathContext
Given a prefix, returns a registered namespace URI. If the requested prefix was not defined explicitly using the registerNamespace method, JXPathContext will then check the context node to see if the prefix is defined there. SeesetNamespaceContextPointer
.- Overrides:
getNamespaceURI
in classJXPathContext
- Parameters:
prefix
- The namespace prefix to look up- Returns:
- namespace URI or null if the prefix is undefined.
-
getPrefix
Get the prefix associated with the specifed namespace URI.- Overrides:
getPrefix
in classJXPathContext
- Parameters:
namespaceURI
- the ns URI to check.- Returns:
- String prefix
- See Also:
-
setNamespaceContextPointer
Description copied from class:JXPathContext
Namespace prefixes can be defined implicitly by specifying a pointer to a context where the namespaces are defined. By default, NamespaceContextPointer is the same as the Context Pointer, seegetContextPointer()
- Overrides:
setNamespaceContextPointer
in classJXPathContext
- Parameters:
pointer
- The pointer to the context where prefixes used in XPath expressions should be resolved.
-
getNamespaceContextPointer
Description copied from class:JXPathContext
Returns the namespace context pointer set withsetNamespaceContextPointer()
or, if none has been specified, the context pointer otherwise.- Overrides:
getNamespaceContextPointer
in classJXPathContext
- Returns:
- The namespace context pointer.
-
getNamespaceResolver
Get the namespace resolver.- Returns:
- NamespaceResolver
-
allocateConditionally
Checks if existenceCheckClass exists on the class path. If so, allocates an instance of the specified class, otherwise returns null.- Parameters:
className
- to instantiateexistenceCheckClassName
- guard class- Returns:
- className instance
-