java.lang.Object
org.apache.commons.jexl3.internal.introspection.Introspector

public final class Introspector extends Object
This basic function of this class is to return a Method object for a particular class given the name of a method and the parameters to the method in the form of an Object[].

The first time the Introspector sees a class it creates a class method map for the class in question. Basically the class method map is a Hashtable where Method objects are keyed by the aggregation of the method name and the array of parameters classes. This mapping is performed for all the public methods of a class and stored.

Since:
1.0
  • Field Details

    • CTOR_MISS

      private static final Constructor<?> CTOR_MISS
      The cache-miss marker for the constructors map.
    • logger

      private final org.apache.commons.logging.Log logger
      the logger.
    • loader

      private ClassLoader loader
      The class loader used to solve constructors if needed.
    • permissions

      private final JexlPermissions permissions
      The permissions.
    • lock

      private final ReadWriteLock lock
      The read/write lock.
    • classMethodMaps

      private final Map<Class<?>,ClassMap> classMethodMaps
      Holds the method maps for the classes we know about, keyed by Class.
    • constructorsMap

      private final Map<MethodKey,Constructor<?>> constructorsMap
      Holds the map of classes ctors we know about as well as unknown ones.
    • constructibleClasses

      private final Map<String,Class<?>> constructibleClasses
      Holds the set of classes we have introspected.
  • Constructor Details

    • Introspector

      public Introspector(org.apache.commons.logging.Log log, ClassLoader cloader)
      Create the introspector.
      Parameters:
      log - the logger to use
      cloader - the class loader
    • Introspector

      public Introspector(org.apache.commons.logging.Log log, ClassLoader cloader, JexlPermissions perms)
      Create the introspector.
      Parameters:
      log - the logger to use
      cloader - the class loader
      perms - the permissions
  • Method Details

    • getClassByName

      public Class<?> getClassByName(String className)
      Gets a class by name through this introspector class loader.
      Parameters:
      className - the class name
      Returns:
      the class instance or null if it could not be found
    • getMethod

      public Method getMethod(Class<?> c, String name, Object... params)
      Gets a method defined by a class, a name and a set of parameters.
      Parameters:
      c - the class
      name - the method name
      params - the method parameters
      Returns:
      the desired method object
      Throws:
      MethodKey.AmbiguousException - if no unambiguous method could be found through introspection
    • getMethod

      public Method getMethod(Class<?> c, MethodKey key)
      Gets the method defined by the MethodKey for the class c.
      Parameters:
      c - Class in which the method search is taking place
      key - Key of the method being searched for
      Returns:
      The desired method object
      Throws:
      MethodKey.AmbiguousException - if no unambiguous method could be found through introspection
    • getField

      public Field getField(Class<?> c, 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:
      the desired field or null if it does not exist or is not accessible
    • getFieldNames

      public String[] getFieldNames(Class<?> c)
      Gets the array of accessible field names known for a given class.
      Parameters:
      c - the class
      Returns:
      the class field names
    • getMethodNames

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

      public Method[] getMethods(Class<?> c, String methodName)
      Gets the array of accessible method known for a given class.
      Parameters:
      c - the class
      methodName - the method name
      Returns:
      the array of methods (null or not empty)
    • getConstructor

      public Constructor<?> getConstructor(MethodKey key)
      Gets the constructor defined by the MethodKey.
      Parameters:
      key - Key of the constructor being searched for
      Returns:
      The desired constructor object or null if no unambiguous constructor could be found through introspection.
    • getConstructor

      public Constructor<?> getConstructor(Class<?> c, MethodKey key)
      Gets the constructor defined by the MethodKey.
      Parameters:
      c - the class we want to instantiate
      key - Key of the constructor being searched for
      Returns:
      The desired constructor object or null if no unambiguous constructor could be found through introspection.
    • getMap

      private ClassMap getMap(Class<?> c)
      Gets the ClassMap for a given class.
      Parameters:
      c - the class
      Returns:
      the class map
    • setLoader

      public void setLoader(ClassLoader classLoader)
      Sets the class loader used to solve constructors.

      Also cleans the constructors and methods caches.

      Parameters:
      classLoader - the class loader; if null, use this instance class loader
    • getLoader

      public ClassLoader getLoader()
      Gets the class loader used by this introspector.
      Returns:
      the class loader
    • isLoadedBy

      private static boolean isLoadedBy(ClassLoader loader, Class<?> clazz)
      Checks whether a class is loaded through a given class loader or one of its ascendants.
      Parameters:
      loader - the class loader
      clazz - the class to check
      Returns:
      true if clazz was loaded through the loader, false otherwise