Class JXPathContextReferenceImpl


  • public class JXPathContextReferenceImpl
    extends JXPathContext
    The reference implementation of JXPathContext.
    Version:
    $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $
    Author:
    Dmitri Plotnikov
    • Field Detail

      • 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
      • COMPILER

        private static final Compiler COMPILER
      • compiled

        private static java.util.Map compiled
      • cleanupCount

        private static int cleanupCount
      • nodeFactories

        private static final java.util.Vector nodeFactories
      • namespaceResolver

        protected NamespaceResolver namespaceResolver
        Namespace resolver
      • rootPointer

        private Pointer rootPointer
      • contextPointer

        private Pointer contextPointer
    • Constructor Detail

      • JXPathContextReferenceImpl

        protected JXPathContextReferenceImpl​(JXPathContext parentContext,
                                             java.lang.Object contextBean)
        Create a new JXPathContextReferenceImpl.
        Parameters:
        parentContext - parent context
        contextBean - Object
      • JXPathContextReferenceImpl

        public JXPathContextReferenceImpl​(JXPathContext parentContext,
                                          java.lang.Object contextBean,
                                          Pointer contextPointer)
        Create a new JXPathContextReferenceImpl.
        Parameters:
        parentContext - parent context
        contextBean - Object
        contextPointer - context pointer
    • Method Detail

      • createNodeFactoryArray

        private static void createNodeFactoryArray()
        Create the default node factory array.
      • 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
      • getNodePointerFactories

        public static NodePointerFactory[] getNodePointerFactories()
        Get the registered NodePointerFactories.
        Returns:
        NodePointerFactory[]
      • getCompiler

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

        protected CompiledExpression compilePath​(java.lang.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
      • compileExpression

        private Expression compileExpression​(java.lang.String xpath)
        Compile the given expression.
        Parameters:
        xpath - to compile
        Returns:
        Expression
      • getValue

        public java.lang.Object getValue​(java.lang.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 java.lang.Object getValue​(java.lang.String xpath,
                                         Expression expr)
        Get the value indicated.
        Parameters:
        xpath - String
        expr - Expression
        Returns:
        Object
      • getValue

        public java.lang.Object getValue​(java.lang.String xpath,
                                         java.lang.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 java.lang.Object getValue​(java.lang.String xpath,
                                         Expression expr,
                                         java.lang.Class requiredType)
        Get the value indicated.
        Parameters:
        xpath - expression
        expr - compiled Expression
        requiredType - Class
        Returns:
        Object
      • iterate

        public java.util.Iterator iterate​(java.lang.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 java.util.Iterator iterate​(java.lang.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
      • getPointer

        public Pointer getPointer​(java.lang.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 pointer will be null.
        Specified by:
        getPointer in class JXPathContext
        Parameters:
        xpath - desired
        Returns:
        Pointer
      • getPointer

        public Pointer getPointer​(java.lang.String xpath,
                                  Expression expr)
        Get a pointer to the specified path/expression.
        Parameters:
        xpath - String
        expr - compiled Expression
        Returns:
        Pointer
      • setValue

        public void setValue​(java.lang.String xpath,
                             java.lang.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
      • setValue

        public void setValue​(java.lang.String xpath,
                             Expression expr,
                             java.lang.Object value)
        Set the value of xpath to value.
        Parameters:
        xpath - path
        expr - compiled Expression
        value - Object
      • createPath

        public Pointer createPath​(java.lang.String xpath,
                                  Expression expr)
        Create the given path.
        Parameters:
        xpath - String
        expr - compiled Expression
        Returns:
        resulting Pointer
      • createPathAndSetValue

        public Pointer createPathAndSetValue​(java.lang.String xpath,
                                             java.lang.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
      • createPathAndSetValue

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

        private Pointer setValue​(java.lang.String xpath,
                                 Expression expr,
                                 java.lang.Object value,
                                 boolean create)
        Set the specified value.
        Parameters:
        xpath - path
        expr - compiled Expression
        value - destination value
        create - whether to create missing node(s)
        Returns:
        Pointer created
      • checkSimplePath

        private void checkSimplePath​(Expression expr)
        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

        public java.util.Iterator iteratePointers​(java.lang.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 java.util.Iterator iteratePointers​(java.lang.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
      • removePath

        public void removePath​(java.lang.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​(java.lang.String xpath,
                               Expression expr)
        Remove the specified path.
        Parameters:
        xpath - expression
        expr - compiled Expression
      • removeAll

        public void removeAll​(java.lang.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​(java.lang.String xpath,
                              Expression expr)
        Remove all matching nodes.
        Parameters:
        xpath - expression
        expr - compiled Expression
      • 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
      • getAbsoluteRootPointer

        private NodePointer getAbsoluteRootPointer()
        Get absolute root pointer.
        Returns:
        NodePointer
      • getEvalContext

        private EvalContext getEvalContext()
        Get the evaluation context.
        Returns:
        EvalContext
      • getAbsoluteRootContext

        public EvalContext getAbsoluteRootContext()
        Get the absolute root context.
        Returns:
        EvalContext
      • getVariablePointer

        public NodePointer getVariablePointer​(QName name)
        Get a VariablePointer for the given variable name.
        Parameters:
        name - variable name
        Returns:
        NodePointer
      • getFunction

        public Function getFunction​(QName functionName,
                                    java.lang.Object[] parameters)
        Get the named Function.
        Parameters:
        functionName - name
        parameters - function args
        Returns:
        Function
      • registerNamespace

        public void registerNamespace​(java.lang.String prefix,
                                      java.lang.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
      • getNamespaceURI

        public java.lang.String getNamespaceURI​(java.lang.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.
      • 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.
      • getNamespaceResolver

        public NamespaceResolver getNamespaceResolver()
        Get the namespace resolver.
        Returns:
        NamespaceResolver
      • allocateConditionally

        public static java.lang.Object allocateConditionally​(java.lang.String className,
                                                             java.lang.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