Class Uberspect

  • All Implemented Interfaces:
    JexlUberspect

    public class Uberspect
    extends java.lang.Object
    implements JexlUberspect
    Implements Uberspect to provide the default introspective functionality of JEXL.

    This is the class to derive to customize introspection.

    Since:
    1.0
    • Field Detail

      • TRY_FAILED

        public static final java.lang.Object TRY_FAILED
        Publicly exposed special failure object returned by tryInvoke.
      • logger

        protected final org.apache.commons.logging.Log logger
        The logger to use for all warnings and errors.
      • version

        private final java.util.concurrent.atomic.AtomicInteger version
        The introspector version.
      • ref

        private volatile java.lang.ref.Reference<Introspector> ref
        The soft reference to the introspector currently in use.
      • loader

        private volatile java.lang.ref.Reference<java.lang.ClassLoader> loader
        The class loader reference; used to recreate the introspector when necessary.
      • operatorMap

        private final java.util.Map<java.lang.Class<? extends JexlArithmetic>,​java.util.Set<JexlOperator>> operatorMap
        The map from arithmetic classes to overloaded operator sets.

        This map keeps track of which operator methods are overloaded per JexlArithmetic classes allowing a fail fast test during interpretation by avoiding seeking a method when there is none.

    • Constructor Detail

      • Uberspect

        public Uberspect​(org.apache.commons.logging.Log runtimeLogger,
                         JexlUberspect.ResolverStrategy sty)
        Creates a new Uberspect.
        Parameters:
        runtimeLogger - the logger used for all logging needs
        sty - the resolver strategy
      • Uberspect

        public Uberspect​(org.apache.commons.logging.Log runtimeLogger,
                         JexlUberspect.ResolverStrategy sty,
                         JexlPermissions perms)
        Creates a new Uberspect.
        Parameters:
        runtimeLogger - the logger used for all logging needs
        sty - the resolver strategy
        perms - the introspector permissions
    • Method Detail

      • base

        protected final Introspector base()
        Gets the current introspector base.

        If the reference has been collected, this method will recreate the underlying introspector.

        Returns:
        the introspector
      • getArithmetic

        public JexlArithmetic.Uberspect getArithmetic​(JexlArithmetic arithmetic)
        Description copied from interface: JexlUberspect
        Gets an arithmetic operator resolver for a given arithmetic instance.
        Specified by:
        getArithmetic in interface JexlUberspect
        Parameters:
        arithmetic - the arithmetic instance
        Returns:
        the arithmetic uberspect or null if no operator method were overridden
      • getClassByName

        public final java.lang.Class<?> getClassByName​(java.lang.String className)
        Gets a class by name through this introspector class loader.
        Specified by:
        getClassByName in interface JexlUberspect
        Parameters:
        className - the class name
        Returns:
        the class instance or null if it could not be found
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Description copied from interface: JexlUberspect
        Gets the current class loader.
        Specified by:
        getClassLoader in interface JexlUberspect
        Returns:
        the class loader
      • getConstructor

        public JexlMethod getConstructor​(java.lang.Object ctorHandle,
                                         java.lang.Object... args)
        Description copied from interface: JexlUberspect
        Returns a class constructor.
        Specified by:
        getConstructor in interface JexlUberspect
        Parameters:
        ctorHandle - a class or class name
        args - constructor arguments
        Returns:
        a JexlMethod
      • getField

        public final java.lang.reflect.Field getField​(java.lang.Class<?> c,
                                                      java.lang.String key)
        Gets the field named by key for the class c.
        Parameters:
        c - Class in which the field search is taking place
        key - Name of the field being searched for
        Returns:
        a Field or null if it does not exist or is not accessible
      • getFieldNames

        public final java.lang.String[] getFieldNames​(java.lang.Class<?> c)
        Gets the accessible field names known for a given class.
        Parameters:
        c - the class
        Returns:
        the class field names
      • getIterator

        public java.util.Iterator<?> getIterator​(java.lang.Object obj)
        Description copied from interface: JexlUberspect
        Gets an iterator from an object.
        Specified by:
        getIterator in interface JexlUberspect
        Parameters:
        obj - to get the iterator from
        Returns:
        an iterator over obj or null
      • getMethod

        public final java.lang.reflect.Method getMethod​(java.lang.Class<?> c,
                                                        MethodKey key)
        Gets the method defined by key and for the Class c.
        Parameters:
        c - Class in which the method search is taking place
        key - MethodKey of the method being searched for
        Returns:
        a Method or null if no unambiguous method could be found through introspection.
      • getMethod

        public final java.lang.reflect.Method getMethod​(java.lang.Class<?> c,
                                                        java.lang.String name,
                                                        java.lang.Object[] params)
        Gets the method defined by name and params for the Class c.
        Parameters:
        c - Class in which the method search is taking place
        name - Name of the method being searched for
        params - An array of Objects (not Classes) that describe the parameters
        Returns:
        a Method or null if no unambiguous method could be found through introspection.
      • getMethod

        public JexlMethod getMethod​(java.lang.Object obj,
                                    java.lang.String method,
                                    java.lang.Object... args)
        Description copied from interface: JexlUberspect
        Returns a JexlMethod.
        Specified by:
        getMethod in interface JexlUberspect
        Parameters:
        obj - the object
        method - the method name
        args - method arguments
        Returns:
        a JexlMethod
      • getMethodNames

        public final java.lang.String[] getMethodNames​(java.lang.Class<?> c)
        Gets the accessible methods names known for a given class.
        Parameters:
        c - the class
        Returns:
        the class method names
      • getMethods

        public final java.lang.reflect.Method[] getMethods​(java.lang.Class<?> c,
                                                           java.lang.String methodName)
        Gets all the methods with a given name from this map.
        Parameters:
        c - the class
        methodName - the seeked methods name
        Returns:
        the array of methods
      • getPropertyGet

        public JexlPropertyGet getPropertyGet​(java.lang.Object obj,
                                              java.lang.Object identifier)
        Description copied from interface: JexlUberspect
        Property getter.

        returns a JelPropertySet apropos to an expression like bar.woogie.

        Specified by:
        getPropertyGet in interface JexlUberspect
        Parameters:
        obj - the object to get the property from
        identifier - property name
        Returns:
        a JexlPropertyGet or null
      • getPropertySet

        public JexlPropertySet getPropertySet​(java.lang.Object obj,
                                              java.lang.Object identifier,
                                              java.lang.Object arg)
        Description copied from interface: JexlUberspect
        Property setter.

        Seeks a JelPropertySet apropos to an expression like foo.bar = "geir".

        Specified by:
        getPropertySet in interface JexlUberspect
        Parameters:
        obj - the object to get the property from.
        identifier - property name
        arg - value to set
        Returns:
        a JexlPropertySet or null
      • getVersion

        public int getVersion()
        Description copied from interface: JexlUberspect
        Gets this uberspect version.
        Specified by:
        getVersion in interface JexlUberspect
        Returns:
        the class loader modification count
      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader nloader)
        Description copied from interface: JexlUberspect
        Sets the class loader to use.

        This increments the version.

        Specified by:
        setClassLoader in interface JexlUberspect
        Parameters:
        nloader - the class loader