Package org.apache.commons.jxpath.ri

# Class JXPathContextReferenceImpl

java.lang.Object
org.apache.commons.jxpath.JXPathContext
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl

public class JXPathContextReferenceImpl extends JXPathContext
The reference implementation of JXPathContext.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected NamespaceResolver`
  `namespaceResolver`
  Namespace resolver
  `static final boolean`
  `USE_SOFT_CACHE`
  Change this to `false` 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

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean)`
  Constructs a new JXPathContextReferenceImpl.
  ``
  `JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean, Pointer contextPointer)`
  Constructs a new JXPathContextReferenceImpl.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static 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.
  `protected CompiledExpression`
  `compilePath(String xpath)`
  Overridden by each concrete implementation of JXPathContext to perform compilation.
  `Pointer`
  `createPath(String xpath)`
  Creates missing elements of the path by invoking an `AbstractFactory`, which should first be installed on the context by calling `JXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)`.
  `Pointer`
  `createPath(String xpath, Expression expr)`
  Create the given path.
  `Pointer`
  `createPathAndSetValue(String xpath, Object value)`
  The same as setValue, except it creates intermediate elements of the path by invoking an `AbstractFactory`, which should first be installed on the context by calling `JXPathContext.setFactory(org.apache.commons.jxpath.AbstractFactory)`.
  `Pointer`
  `createPathAndSetValue(String xpath, Expression expr, Object value)`
  Create the given path setting its value to value.
  `EvalContext`
  `getAbsoluteRootContext()`
  Gets the absolute root context.
  `protected Compiler`
  `getCompiler()`
  Returns a static instance of TreeCompiler.
  `Pointer`
  `getContextPointer()`
  Returns a Pointer for the context bean.
  `Function`
  `getFunction(QName functionName, Object[] parameters)`
  Gets the named Function.
  `Pointer`
  `getNamespaceContextPointer()`
  Returns the namespace context pointer set with `setNamespaceContextPointer()` or, if none has been specified, the context pointer otherwise.
  `NamespaceResolver`
  `getNamespaceResolver()`
  Gets the namespace resolver.
  `String`
  `getNamespaceURI(String prefix)`
  Given a prefix, returns a registered namespace URI.
  `static NodePointerFactory[]`
  `getNodePointerFactories()`
  Gets the registered NodePointerFactories.
  `Pointer`
  `getPointer(String xpath)`
  Traverses the XPath and returns a Pointer.
  `Pointer`
  `getPointer(String xpath, Expression expr)`
  Gets a pointer to the specified path/expression.
  `String`
  `getPrefix(String namespaceURI)`
  Gets the prefix associated with the specifed namespace URI.
  `JXPathContext`
  `getRelativeContext(Pointer pointer)`
  Returns a JXPathContext that is relative to the current JXPathContext.
  `Object`
  `getValue(String xpath)`
  Traverses the XPath and returns the resulting object.
  `Object`
  `getValue(String xpath, Class requiredType)`
  Calls getValue(xpath), converts the result to the required type and returns the result of the conversion.
  `Object`
  `getValue(String xpath, Expression expr)`
  Gets the value indicated.
  `Object`
  `getValue(String xpath, Expression expr, Class requiredType)`
  Gets the value indicated.
  `NodePointer`
  `getVariablePointer(QName qName)`
  Gets a VariablePointer for the given variable name.
  `Iterator`
  `iterate(String xpath)`
  Traverses the XPath and returns a Iterator of all results found for the path.
  `Iterator`
  `iterate(String xpath, Expression expr)`
  Traverses the XPath and returns a Iterator of all results found for the path.
  `Iterator<Pointer>`
  `iteratePointers(String xpath)`
  Traverses the XPath and returns an Iterator of Pointers.
  `Iterator<Pointer>`
  `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`
  `removeAll(String xpath)`
  Removes all elements of the object graph described by the xpath.
  `void`
  `removeAll(String xpath, Expression expr)`
  Remove all matching nodes.
  `static boolean`
  `removeNodePointerFactory(NodePointerFactory factory)`
  Removes support for additional types of objects.
  `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`
  `setExceptionHandler(ExceptionHandler exceptionHandler)`
  Sets the ExceptionHandler used by this context, if any.
  `void`
  `setNamespaceContextPointer(Pointer pointer)`
  Namespace prefixes can be defined implicitly by specifying a pointer to a context where the namespaces are defined.
  `void`
  `setValue(String xpath, Object value)`
  Modifies the value of the property described by the supplied xpath.
  `void`
  `setValue(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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### USE_SOFT_CACHE

    public static final boolean USE_SOFT_CACHE
    Change this to `false` to disable soft caching of CompiledExpressions.
    See Also:
      - Constant Field Values

  - ### namespaceResolver

    protected NamespaceResolver namespaceResolver
    Namespace resolver

- ## Constructor Details

  - ### JXPathContextReferenceImpl

    protected JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean)
    Constructs a new JXPathContextReferenceImpl.
    Parameters:
      `parentContext` - parent context
      `contextBean` - Object

  - ### JXPathContextReferenceImpl

    public JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean, Pointer contextPointer)
    Constructs a new JXPathContextReferenceImpl.
    Parameters:
      `parentContext` - parent context
      `contextBean` - Object
      `contextPointer` - context pointer

- ## Method Details

  - ### addNodePointerFactory

    public static void addNodePointerFactory(NodePointerFactory factory)
    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

    public static Object allocateConditionally(String className, String existenceCheckClassName)
    Checks if existenceCheckClass exists on the class path. If so, allocates an instance of the specified class, otherwise returns null.
    Parameters:
      `className` - to instantiate
      `existenceCheckClassName` - guard class
    Returns:
      className instance

  - ### getNodePointerFactories

    public static NodePointerFactory[] getNodePointerFactories()
    Gets the registered NodePointerFactories.
    Returns:
      NodePointerFactory[]

  - ### removeNodePointerFactory

    public static boolean removeNodePointerFactory(NodePointerFactory factory)
    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

    protected CompiledExpression compilePath(String xpath)
    Description copied from class: `JXPathContext`
    Overridden by each concrete implementation of JXPathContext to perform compilation. Is called by `compile()`.
    Specified by:
      `compilePath` in class `JXPathContext`
    Parameters:
      `xpath` - to compile
    Returns:
      CompiledExpression

  - ### createPath

    public Pointer createPath(String xpath)
    Description copied from class: `JXPathContext`
    Creates missing elements of the path by invoking an `AbstractFactory`, which should first be installed on the context by calling `JXPathContext.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 class `JXPathContext`
    Parameters:
      `xpath` - indicating destination to create
    Returns:
      pointer to new location

  - ### createPath

    public Pointer createPath(String xpath, Expression expr)
    Create the given path.
    Parameters:
      `xpath` - String
      `expr` - compiled Expression
    Returns:
      resulting Pointer

  - ### createPathAndSetValue

    public Pointer createPathAndSetValue(String xpath, Expression expr, Object value)
    Create the given path setting its value to value.
    Parameters:
      `xpath` - String
      `expr` - compiled Expression
      `value` - Object
    Returns:
      resulting Pointer

  - ### createPathAndSetValue

    public Pointer createPathAndSetValue(String xpath, Object value)
    Description copied from class: `JXPathContext`
    The same as setValue, except it creates intermediate elements of the path by invoking an `AbstractFactory`, which should first be installed on the context by calling `JXPathContext.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 class `JXPathContext`
    Parameters:
      `xpath` - indicating position to create
      `value` - to set
    Returns:
      pointer to new location

  - ### getAbsoluteRootContext

    public EvalContext getAbsoluteRootContext()
    Gets the absolute root context.
    Returns:
      EvalContext

  - ### getCompiler

    protected Compiler getCompiler()
    Returns a static instance of TreeCompiler. Override this to return an alternate compiler.
    Returns:
      Compiler

  - ### getContextPointer

    public Pointer getContextPointer()
    Description copied from class: `JXPathContext`
    Returns a Pointer for the context bean.
    Specified by:
      `getContextPointer` in class `JXPathContext`
    Returns:
      Pointer

  - ### getFunction

    public Function getFunction(QName functionName, Object[] parameters)
    Gets the named Function.
    Parameters:
      `functionName` - name
      `parameters` - function args
    Returns:
      Function

  - ### getNamespaceContextPointer

    public Pointer getNamespaceContextPointer()
    Description copied from class: `JXPathContext`
    Returns the namespace context pointer set with `setNamespaceContextPointer()` or, if none has been specified, the context pointer otherwise.
    Overrides:
      `getNamespaceContextPointer` in class `JXPathContext`
    Returns:
      The namespace context pointer.

  - ### getNamespaceResolver

    public NamespaceResolver getNamespaceResolver()
    Gets the namespace resolver.
    Returns:
      NamespaceResolver

  - ### getNamespaceURI

    public String getNamespaceURI(String prefix)
    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. See `setNamespaceContextPointer`.
    Overrides:
      `getNamespaceURI` in class `JXPathContext`
    Parameters:
      `prefix` - The namespace prefix to look up
    Returns:
      namespace URI or null if the prefix is undefined.

  - ### getPointer

    public Pointer getPointer(String xpath)
    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 behavior depends on the value that has been configured with `JXPathContext.setLenient(boolean)`:

    - `false` (default) the method will throw a `JXPathNotFoundException`.
    - `true` the method returns a pointer whose `Pointer.getValue()` method will always return null.
    Specified by:
      `getPointer` in class `JXPathContext`
    Parameters:
      `xpath` - desired
    Returns:
      Pointer A `Pointer`, never `null`.

  - ### getPointer

    public Pointer getPointer(String xpath, Expression expr)
    Gets a pointer to the specified path/expression.
    Parameters:
      `xpath` - String
      `expr` - compiled Expression
    Returns:
      Pointer

  - ### getPrefix

    public String getPrefix(String namespaceURI)
    Gets the prefix associated with the specifed namespace URI.
    Overrides:
      `getPrefix` in class `JXPathContext`
    Parameters:
      `namespaceURI` - the ns URI to check.
    Returns:
      String prefix
    See Also:
      - `JXPathContext.getPrefix(java.lang.String)`

  - ### getRelativeContext

    public JXPathContext getRelativeContext(Pointer pointer)
    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 class `JXPathContext`
    Parameters:
      `pointer` - Pointer
    Returns:
      JXPathContext

  - ### getValue

    public Object getValue(String xpath)
    Traverses the XPath and returns the resulting object. Primitive types are wrapped into objects.
    Specified by:
      `getValue` in class `JXPathContext`
    Parameters:
      `xpath` - expression
    Returns:
      Object found

  - ### getValue

    public Object getValue(String xpath, Class requiredType)
    Calls getValue(xpath), converts the result to the required type and returns the result of the conversion.
    Specified by:
      `getValue` in class `JXPathContext`
    Parameters:
      `xpath` - expression
      `requiredType` - Class
    Returns:
      Object

  - ### getValue

    public Object getValue(String xpath, Expression expr)
    Gets the value indicated.
    Parameters:
      `xpath` - String
      `expr` - Expression
    Returns:
      Object

  - ### getValue

    public Object getValue(String xpath, Expression expr, Class requiredType)
    Gets the value indicated.
    Parameters:
      `xpath` - expression
      `expr` - compiled Expression
      `requiredType` - Class
    Returns:
      Object

  - ### getVariablePointer

    public NodePointer getVariablePointer(QName qName)
    Gets a VariablePointer for the given variable name.
    Parameters:
      `qName` - variable name
    Returns:
      NodePointer

  - ### iterate

    public Iterator iterate(String xpath)
    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 class `JXPathContext`
    Parameters:
      `xpath` - expression
    Returns:
      Iterator

  - ### iterate

    public Iterator iterate(String xpath, Expression expr)
    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` - expression
      `expr` - compiled Expression
    Returns:
      Iterator

  - ### iteratePointers

    public Iterator<Pointer> iteratePointers(String xpath)
    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 class `JXPathContext`
    Parameters:
      `xpath` - expression
    Returns:
      Iterator

  - ### iteratePointers

    public Iterator<Pointer> iteratePointers(String xpath, Expression expr)
    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` - expression
      `expr` - compiled Expression
    Returns:
      Iterator

  - ### registerNamespace

    public void registerNamespace(String prefix, String namespaceURI)
    Description copied from class: `JXPathContext`
    Registers a namespace prefix.
    Overrides:
      `registerNamespace` in class `JXPathContext`
    Parameters:
      `prefix` - A namespace prefix
      `namespaceURI` - A URI for that prefix

  - ### removeAll

    public void removeAll(String xpath)
    Description copied from class: `JXPathContext`
    Removes all elements of the object graph described by the xpath.
    Specified by:
      `removeAll` in class `JXPathContext`
    Parameters:
      `xpath` - indicating positions to remove

  - ### removeAll

    public void removeAll(String xpath, Expression expr)
    Remove all matching nodes.
    Parameters:
      `xpath` - expression
      `expr` - compiled Expression

  - ### removePath

    public void removePath(String xpath)
    Description copied from class: `JXPathContext`
    Removes the element of the object graph described by the xpath.
    Specified by:
      `removePath` in class `JXPathContext`
    Parameters:
      `xpath` - indicating position to remove

  - ### removePath

    public void removePath(String xpath, Expression expr)
    Remove the specified path.
    Parameters:
      `xpath` - expression
      `expr` - compiled Expression

  - ### setExceptionHandler

    public void setExceptionHandler(ExceptionHandler exceptionHandler)
    Sets the ExceptionHandler used by this context, if any.
    Overrides:
      `setExceptionHandler` in class `JXPathContext`
    Parameters:
      `exceptionHandler` - to set

  - ### setNamespaceContextPointer

    public void setNamespaceContextPointer(Pointer pointer)
    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, see `getContextPointer()`
    Overrides:
      `setNamespaceContextPointer` in class `JXPathContext`
    Parameters:
      `pointer` - The pointer to the context where prefixes used in XPath expressions should be resolved.

  - ### setValue

    public void setValue(String xpath, Expression expr, Object value)
    Sets the value of XPath to value.
    Parameters:
      `xpath` - path
      `expr` - compiled Expression
      `value` - Object

  - ### setValue

    public void setValue(String xpath, Object value)
    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 class `JXPathContext`
    Parameters:
      `xpath` - indicating position
      `value` - to set