Class Introspector
java.lang.Object
org.apache.commons.jexl3.internal.introspection.Introspector
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A Constructor get cache-miss. -
Field Summary
FieldsModifier and TypeFieldDescriptionHolds the method maps for the classes we know about, keyed by Class.Holds the set of classes we have introspected.private final Map<MethodKey,
Constructor<?>> Holds the map of classes ctors we know about as well as unknown ones.private static final Constructor<?>
The cache-miss marker for the constructors map.private ClassLoader
The class loader used to solve constructors if needed.private final ReadWriteLock
The read/write lock.private final org.apache.commons.logging.Log
the logger.private final JexlPermissions
The permissions. -
Constructor Summary
ConstructorsConstructorDescriptionIntrospector
(org.apache.commons.logging.Log log, ClassLoader cloader) Create the introspector.Introspector
(org.apache.commons.logging.Log log, ClassLoader cloader, JexlPermissions perms) Create the introspector. -
Method Summary
Modifier and TypeMethodDescriptionClass<?>
getClassByName
(String className) Gets a class by name through this introspector class loader.Constructor<?>
getConstructor
(Class<?> c, MethodKey key) Gets the constructor defined by theMethodKey
.Constructor<?>
getConstructor
(MethodKey key) Gets the constructor defined by theMethodKey
.Gets the field named bykey
for the classc
.String[]
getFieldNames
(Class<?> c) Gets the array of accessible field names known for a given class.Gets the class loader used by this introspector.private ClassMap
Gets the ClassMap for a given class.Gets a method defined by a class, a name and a set of parameters.Gets the method defined by theMethodKey
for the classc
.String[]
getMethodNames
(Class<?> c) Gets the array of accessible methods names known for a given class.Method[]
getMethods
(Class<?> c, String methodName) Gets the array of accessible method known for a given class.private static boolean
isLoadedBy
(ClassLoader loader, Class<?> clazz) Checks whether a class is loaded through a given class loader or one of its ascendants.void
setLoader
(ClassLoader classLoader) Sets the class loader used to solve constructors.
-
Field Details
-
CTOR_MISS
The cache-miss marker for the constructors map. -
logger
private final org.apache.commons.logging.Log loggerthe logger. -
loader
The class loader used to solve constructors if needed. -
permissions
The permissions. -
lock
The read/write lock. -
classMethodMaps
Holds the method maps for the classes we know about, keyed by Class. -
constructorsMap
Holds the map of classes ctors we know about as well as unknown ones. -
constructibleClasses
Holds the set of classes we have introspected.
-
-
Constructor Details
-
Introspector
Create the introspector.- Parameters:
log
- the logger to usecloader
- the class loader
-
Introspector
Create the introspector.- Parameters:
log
- the logger to usecloader
- the class loaderperms
- the permissions
-
-
Method Details
-
getClassByName
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
Gets a method defined by a class, a name and a set of parameters.- Parameters:
c
- the classname
- the method nameparams
- the method parameters- Returns:
- the desired method object
- Throws:
MethodKey.AmbiguousException
- if no unambiguous method could be found through introspection
-
getMethod
Gets the method defined by theMethodKey
for the classc
.- Parameters:
c
- Class in which the method search is taking placekey
- 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
Gets the field named bykey
for the classc
.- Parameters:
c
- Class in which the field search is taking placekey
- Name of the field being searched for- Returns:
- the desired field or null if it does not exist or is not accessible
-
getFieldNames
Gets the array of accessible field names known for a given class.- Parameters:
c
- the class- Returns:
- the class field names
-
getMethodNames
Gets the array of accessible methods names known for a given class.- Parameters:
c
- the class- Returns:
- the class method names
-
getMethods
Gets the array of accessible method known for a given class.- Parameters:
c
- the classmethodName
- the method name- Returns:
- the array of methods (null or not empty)
-
getConstructor
Gets the constructor defined by theMethodKey
.- 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
Gets the constructor defined by theMethodKey
.- Parameters:
c
- the class we want to instantiatekey
- Key of the constructor being searched for- Returns:
- The desired constructor object or null if no unambiguous constructor could be found through introspection.
-
getMap
Gets the ClassMap for a given class.- Parameters:
c
- the class- Returns:
- the class map
-
setLoader
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
Gets the class loader used by this introspector.- Returns:
- the class loader
-
isLoadedBy
Checks whether a class is loaded through a given class loader or one of its ascendants.- Parameters:
loader
- the class loaderclazz
- the class to check- Returns:
- true if clazz was loaded through the loader, false otherwise
-