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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected NamespaceResolverNamespace resolverstatic final booleanChange this tofalseto disable soft caching of CompiledExpressions.Fields inherited from class org.apache.commons.jxpath.JXPathContext
contextBean, decimalFormats, factory, functions, idManager, keyManager, parentContext, vars -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean) Constructs a new JXPathContextReferenceImpl.JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean, Pointer contextPointer) Constructs a new JXPathContextReferenceImpl. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddNodePointerFactory(NodePointerFactory factory) Call this with a custom NodePointerFactory to add support for additional types of objects.static ObjectallocateConditionally(String className, String existenceCheckClassName) Checks if existenceCheckClass exists on the class path.protected CompiledExpressioncompilePath(String xpath) Overridden by each concrete implementation of JXPathContext to perform compilation.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.Gets the absolute root context.protected CompilerReturns a static instance of TreeCompiler.Returns a Pointer for the context bean.getFunction(QName functionName, Object[] parameters) Gets the named Function.Returns the namespace context pointer set withsetNamespaceContextPointer()or, if none has been specified, the context pointer otherwise.Gets the namespace resolver.getNamespaceURI(String prefix) Given a prefix, returns a registered namespace URI.static NodePointerFactory[]Gets the registered NodePointerFactories.getPointer(String xpath) Traverses the XPath and returns a Pointer.getPointer(String xpath, Expression expr) Gets a pointer to the specified path/expression.Gets 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) Gets the value indicated.getValue(String xpath, Expression expr, Class requiredType) Gets the value indicated.getVariablePointer(QName qName) Gets 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.voidregisterNamespace(String prefix, String namespaceURI) Registers a namespace prefix.voidRemoves all elements of the object graph described by the xpath.voidremoveAll(String xpath, Expression expr) Remove all matching nodes.static booleanRemoves support for additional types of objects.voidremovePath(String xpath) Removes the element of the object graph described by the xpath.voidremovePath(String xpath, Expression expr) Remove the specified path.voidsetExceptionHandler(ExceptionHandler exceptionHandler) Sets the ExceptionHandler used by this context, if any.voidsetNamespaceContextPointer(Pointer pointer) Namespace prefixes can be defined implicitly by specifying a pointer to a context where the namespaces are defined.voidModifies the value of the property described by the supplied xpath.voidsetValue(String xpath, Expression expr, Object value) Sets the value of XPath to 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
Change this tofalseto disable soft caching of CompiledExpressions.- See Also:
-
namespaceResolver
Namespace resolver
-
-
Constructor Details
-
JXPathContextReferenceImpl
Constructs a new JXPathContextReferenceImpl.- Parameters:
parentContext- parent contextcontextBean- Object
-
JXPathContextReferenceImpl
public JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean, Pointer contextPointer) Constructs a new JXPathContextReferenceImpl.- Parameters:
parentContext- parent contextcontextBean- ObjectcontextPointer- context pointer
-
-
Method Details
-
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
-
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
-
getNodePointerFactories
Gets the registered NodePointerFactories.- Returns:
- NodePointerFactory[]
-
removeNodePointerFactory
Removes support for additional types of objects.- Parameters:
factory- NodePointerFactory to remove- Returns:
- true if this implementation contained the specified element
- Since:
- 1.4.0.0
-
compilePath
Description copied from class:JXPathContextOverridden by each concrete implementation of JXPathContext to perform compilation. Is called bycompile().- Specified by:
compilePathin classJXPathContext- Parameters:
xpath- to compile- Returns:
- CompiledExpression
-
createPath
Description copied from class:JXPathContextCreates 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:
createPathin 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
Create the given path setting its value to value.- Parameters:
xpath- Stringexpr- compiled Expressionvalue- Object- Returns:
- resulting Pointer
-
createPathAndSetValue
Description copied from class:JXPathContextThe 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:
createPathAndSetValuein classJXPathContext- Parameters:
xpath- indicating position to createvalue- to set- Returns:
- pointer to new location
-
getAbsoluteRootContext
Gets the absolute root context.- Returns:
- EvalContext
-
getCompiler
Returns a static instance of TreeCompiler. Override this to return an alternate compiler.- Returns:
- Compiler
-
getContextPointer
Description copied from class:JXPathContextReturns a Pointer for the context bean.- Specified by:
getContextPointerin classJXPathContext- Returns:
- Pointer
-
getFunction
Gets the named Function.- Parameters:
functionName- nameparameters- function args- Returns:
- Function
-
getNamespaceContextPointer
Description copied from class:JXPathContextReturns the namespace context pointer set withsetNamespaceContextPointer()or, if none has been specified, the context pointer otherwise.- Overrides:
getNamespaceContextPointerin classJXPathContext- Returns:
- The namespace context pointer.
-
getNamespaceResolver
Gets the namespace resolver.- Returns:
- NamespaceResolver
-
getNamespaceURI
Description copied from class:JXPathContextGiven 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:
getNamespaceURIin classJXPathContext- Parameters:
prefix- The namespace prefix to look up- Returns:
- namespace URI or null if the prefix is undefined.
-
getPointer
Description copied from class:JXPathContextTraverses the XPath and returns a Pointer. A Pointer provides easy access to a property.If the XPath matches no properties in the graph the behavior depends on the value that has been configured with
JXPathContext.setLenient(boolean):false(default) the method will throw aJXPathNotFoundException.truethe method returns a pointer whosePointer.getValue()method will always return null.
- Specified by:
getPointerin classJXPathContext- Parameters:
xpath- desired- Returns:
- Pointer A
Pointer, nevernull.
-
getPointer
Gets a pointer to the specified path/expression.- Parameters:
xpath- Stringexpr- compiled Expression- Returns:
- Pointer
-
getPrefix
Gets the prefix associated with the specifed namespace URI.- Overrides:
getPrefixin classJXPathContext- Parameters:
namespaceURI- the ns URI to check.- Returns:
- String prefix
- See Also:
-
getRelativeContext
Description copied from class:JXPathContextReturns 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:
getRelativeContextin classJXPathContext- Parameters:
pointer- Pointer- Returns:
- JXPathContext
-
getValue
Traverses the XPath and returns the resulting object. Primitive types are wrapped into objects.- Specified by:
getValuein classJXPathContext- Parameters:
xpath- expression- Returns:
- Object found
-
getValue
Calls getValue(xpath), converts the result to the required type and returns the result of the conversion.- Specified by:
getValuein classJXPathContext- Parameters:
xpath- expressionrequiredType- Class- Returns:
- Object
-
getValue
Gets the value indicated.- Parameters:
xpath- Stringexpr- Expression- Returns:
- Object
-
getValue
Gets the value indicated.- Parameters:
xpath- expressionexpr- compiled ExpressionrequiredType- Class- Returns:
- Object
-
getVariablePointer
Gets a VariablePointer for the given variable name.- Parameters:
qName- variable name- Returns:
- NodePointer
-
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:
iteratein 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
-
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:
iteratePointersin 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
-
registerNamespace
Description copied from class:JXPathContextRegisters a namespace prefix.- Overrides:
registerNamespacein classJXPathContext- Parameters:
prefix- A namespace prefixnamespaceURI- A URI for that prefix
-
removeAll
Description copied from class:JXPathContextRemoves all elements of the object graph described by the xpath.- Specified by:
removeAllin classJXPathContext- Parameters:
xpath- indicating positions to remove
-
removeAll
Remove all matching nodes.- Parameters:
xpath- expressionexpr- compiled Expression
-
removePath
Description copied from class:JXPathContextRemoves the element of the object graph described by the xpath.- Specified by:
removePathin classJXPathContext- Parameters:
xpath- indicating position to remove
-
removePath
Remove the specified path.- Parameters:
xpath- expressionexpr- compiled Expression
-
setExceptionHandler
Sets the ExceptionHandler used by this context, if any.- Overrides:
setExceptionHandlerin classJXPathContext- Parameters:
exceptionHandler- to set
-
setNamespaceContextPointer
Description copied from class:JXPathContextNamespace 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:
setNamespaceContextPointerin classJXPathContext- Parameters:
pointer- The pointer to the context where prefixes used in XPath expressions should be resolved.
-
setValue
Sets the value of XPath to value.- Parameters:
xpath- pathexpr- compiled Expressionvalue- Object
-
setValue
Description copied from class:JXPathContextModifies 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:
setValuein classJXPathContext- Parameters:
xpath- indicating positionvalue- to set
-