Class ClassMap
java.lang.Object
org.apache.commons.jexl3.internal.introspection.ClassMap
A cache of introspection information for a specific class instance.
Keys objects by an aggregation of the method name and the classes
that make up the parameters.
Originally taken from the Velocity tree so we can be self-sufficient.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThis is the cache to store and look up the method information.Keep track of all methods with the same name; this is not modified after creation.(package private) static final Method
The cache miss marker method.private static final ClassMap
Singleton for permissions non-allowed classes.Cache of fields. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ClassMap()
Empty map.(package private)
ClassMap
(Class<?> aClass, JexlPermissions permissions, org.apache.commons.logging.Log log) Standard constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic Method
A method that returns itself used as a marker for cache miss, allows the underlying cache map to be strongly typed.private static void
create
(ClassMap cache, JexlPermissions permissions, Class<?> clazz, org.apache.commons.logging.Log log) Populate the Map of direct hits.(package private) static ClassMap
empty()
(package private) Field
Find a Field using its name.(package private) String[]
Gets the field names cached by this map.(package private) Method
Find a Method using the method name and parameter objects.(package private) String[]
Gets the methods names cached by this map.(package private) Method[]
getMethods
(String methodName) Gets all the methods with a given name from this map.private static void
populateWithClass
(ClassMap cache, JexlPermissions permissions, Class<?> clazz, org.apache.commons.logging.Log log) Recurses up class hierarchy to get all super classes.private static void
populateWithInterface
(ClassMap cache, JexlPermissions permissions, Class<?> iface, org.apache.commons.logging.Log log) Recurses up interface hierarchy to get all super interfaces.
-
Field Details
-
CACHE_MISS
The cache miss marker method. -
byKey
This is the cache to store and look up the method information.It stores the association between: - a key made of a method name and an array of argument types. - a method.
Since the invocation of the associated method is dynamic, there is no need (nor way) to differentiate between foo(int,int) and foo(Integer,Integer) since in practice only the latter form will be used through a call. This of course, applies to all 8 primitive types.
Uses ConcurrentMap since 3.0, marginally faster than 2.1 under contention. -
byName
Keep track of all methods with the same name; this is not modified after creation. -
fieldCache
Cache of fields. -
EMPTY
Singleton for permissions non-allowed classes.
-
-
Constructor Details
-
ClassMap
private ClassMap()Empty map. -
ClassMap
ClassMap(Class<?> aClass, JexlPermissions permissions, org.apache.commons.logging.Log log) Standard constructor.- Parameters:
aClass
- the class to deconstruct.permissions
- the permissions to apply during introspectionlog
- the logger.
-
-
Method Details
-
cacheMiss
A method that returns itself used as a marker for cache miss, allows the underlying cache map to be strongly typed.- Returns:
- itself as a method
-
empty
- Returns:
- the empty classmap instance
-
getField
Find a Field using its name.- Parameters:
fname
- the field name- Returns:
- A Field object representing the field to invoke or null.
-
getFieldNames
String[] getFieldNames()Gets the field names cached by this map.- Returns:
- the array of field names
-
getMethodNames
String[] getMethodNames()Gets the methods names cached by this map.- Returns:
- the array of method names
-
getMethods
Gets all the methods with a given name from this map.- Parameters:
methodName
- the seeked methods name- Returns:
- the array of methods (null or non-empty)
-
getMethod
Find a Method using the method name and parameter objects.Look in the methodMap for an entry. If found, it'll either be a CACHE_MISS, in which case we simply give up, or it'll be a Method, in which case, we return it.
If nothing is found, then we must actually go and introspect the method from the MethodMap.
- Parameters:
methodKey
- the method key- Returns:
- A Method object representing the method to invoke or null.
- Throws:
MethodKey.AmbiguousException
- When more than one method is a match for the parameters.
-
create
private static void create(ClassMap cache, JexlPermissions permissions, Class<?> clazz, org.apache.commons.logging.Log log) Populate the Map of direct hits. These are taken from all the public methods that our class, its parents and their implemented interfaces provide.- Parameters:
cache
- the ClassMap instance we createpermissions
- the permissions to apply during introspectionclazz
- the class to cachelog
- the Log
-
populateWithInterface
private static void populateWithInterface(ClassMap cache, JexlPermissions permissions, Class<?> iface, org.apache.commons.logging.Log log) Recurses up interface hierarchy to get all super interfaces.- Parameters:
cache
- the cache to fillpermissions
- the permissions to apply during introspectioniface
- the interface to populate the cache fromlog
- the Log
-
populateWithClass
private static void populateWithClass(ClassMap cache, JexlPermissions permissions, Class<?> clazz, org.apache.commons.logging.Log log) Recurses up class hierarchy to get all super classes.- Parameters:
cache
- the cache to fillpermissions
- the permissions to apply during introspectionclazz
- the class to populate the cache fromlog
- the Log
-