Top Description Inners Fields Constructors Methods
org.apache.commons.jexl2.internal.introspection

pack-priv final Class ClassMap

extends Object
Class Inheritance
Imports
java.lang.reflect.Field, .Method, .Modifier, java.util.Collections, .HashMap, .List, .Map, org.apache.commons.logging.Log

A cache of introspection information for a specific class instance. Keys objects by an agregation 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
MethodKey

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ClassMap.MethodCache

This is the cache to store and look up the method information.

Field Summary

Modifier and TypeField and Description
private final Map<String, Field>
fieldCache

cache of fields.

private final ClassMap.MethodCache
methodCache

cache of methods.

Constructor Summary

AccessConstructor and Description
pack-priv
ClassMap(Class<?>
the class to deconstruct.
aClass
,
Log
the logger.
log
)

Standard constructor.

Method Summary

Modifier and TypeMethod and Description
private static Map<String, Field>

Returns:

the map of fields (may be the empty map, can not be null)
createFieldCache
(Class<?>
the class to introspect
clazz
)

Creates a map of all public fields of a given class.

private static ClassMap.MethodCache

Returns:

a newly allocated & filled up cache
createMethodCache
(Class<?>
the class to cache
classToReflect
,
Log
the Log
log
)

Populate the Map of direct hits.

pack-priv Field

Returns:

A Field object representing the field to invoke or null.
findField
(final Class<?>
the class to introspect
clazz
,
final String
the field name
fname
)

Find a Field using its name.

pack-priv Method

Returns:

A Method object representing the method to invoke or null.
findMethod
(final MethodKey
the method key
key
)

Find a Method using the method name and parameter objects.

pack-priv Method[]

Returns:

the array of methods
get
(final String
the seeked methods name
methodName
)

Gets all the methods with a given name from this map.

pack-priv String[]

Returns:

the array of field names
getFieldNames
()

Gets the field names cached by this map.

pack-priv String[]

Returns:

the array of method names
getMethodNames
()

Gets the methods names cached by this map.

private static void
populateMethodCacheWith(ClassMap.MethodCache
the cache to fill
cache
,
Class<?>
the class to populate the cache from
clazz
,
Log
the Log
log
)

Recurses up class hierarchy to get all super classes.

private static void
populateMethodCacheWithInterface(ClassMap.MethodCache
the cache to fill
cache
,
Class<?>
the interface to populate the cache from
iface
,
Log
the Log
log
)

Recurses up interface hierarchy to get all super interfaces.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fieldCacheback to summary
private final Map<String, Field> fieldCache

cache of fields.

methodCacheback to summary
private final ClassMap.MethodCache methodCache

cache of methods.

Constructor Detail

ClassMapback to summary
pack-priv ClassMap(Class<?> aClass, Log log)

Standard constructor.

Parameters
aClass:Class<?>

the class to deconstruct.

log:Log

the logger.

Method Detail

createFieldCacheback to summary
private static Map<String, Field> createFieldCache(Class<?> clazz)

Creates a map of all public fields of a given class.

Parameters
clazz:Class<?>

the class to introspect

Returns:Map<String, Field>

the map of fields (may be the empty map, can not be null)

createMethodCacheback to summary
private static ClassMap.MethodCache createMethodCache(Class<?> classToReflect, 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
classToReflect:Class<?>

the class to cache

log:Log

the Log

Returns:ClassMap.MethodCache

a newly allocated & filled up cache

findFieldback to summary
pack-priv Field findField(final Class<?> clazz, final String fname)

Find a Field using its name.

The clazz parameter must be this ClassMap key.

Parameters
clazz:Class<?>

the class to introspect

fname:String

the field name

Returns:Field

A Field object representing the field to invoke or null.

findMethodback to summary
pack-priv Method findMethod(final MethodKey key) throws AmbiguousException

Find a Method using the method name and parameter objects.

Parameters
key:MethodKey

the method key

Returns:Method

A Method object representing the method to invoke or null.

Exceptions
AmbiguousException:
When more than one method is a match for the parameters.
getback to summary
pack-priv Method[] get(final String methodName)

Gets all the methods with a given name from this map.

Parameters
methodName:String

the seeked methods name

Returns:Method[]

the array of methods

getFieldNamesback to summary
pack-priv String[] getFieldNames()

Gets the field names cached by this map.

Returns:String[]

the array of field names

getMethodNamesback to summary
pack-priv String[] getMethodNames()

Gets the methods names cached by this map.

Returns:String[]

the array of method names

populateMethodCacheWithback to summary
private static void populateMethodCacheWith(ClassMap.MethodCache cache, Class<?> clazz, Log log)

Recurses up class hierarchy to get all super classes.

Parameters
cache:ClassMap.MethodCache

the cache to fill

clazz:Class<?>

the class to populate the cache from

log:Log

the Log

populateMethodCacheWithInterfaceback to summary
private static void populateMethodCacheWithInterface(ClassMap.MethodCache cache, Class<?> iface, Log log)

Recurses up interface hierarchy to get all super interfaces.

Parameters
cache:ClassMap.MethodCache

the cache to fill

iface:Class<?>

the interface to populate the cache from

log:Log

the Log

org.apache.commons.jexl2.internal.introspection back to summary

pack-priv final Class ClassMap.MethodCache

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.jexl2.internal.introspection.ClassMap.MethodCache

This is the cache to store and look up the method information.

It stores the association between: - a key made of a method name & 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) & foo(Integer,Integer) since in practise, only the latter form will be used through a call. This of course, applies to all 8 primitive types.

Field Summary

Modifier and TypeField and Description
private static final Method
CACHE_MISS

The cache miss marker method.

private final MethodMap
methodMap

Map of methods that are searchable according to method parameters to find a match.

private final Map<MethodKey, Method>
methods

The method cache.

private static final int
PRIMITIVE_SIZE

The initial size of the primitive conversion map.

private static final Map<Class<?>, Class<?>>
PRIMITIVE_TYPES

The primitive type to class conversion map.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static Method

Returns:

itself as a method
cacheMiss
()

A method that returns itself used as a marker for cache miss, allows the underlying cache map to be strongly typed.

pack-priv Method

Returns:

A Method object representing the method to invoke or null.
get
(final MethodKey
the method key
methodKey
)

Find a Method using the method name and parameter objects.

pack-priv Method[]

Returns:

the array of methods (null or non-empty)
get
(final String
the seeked methods name
methodName
)

Gets all the methods with a given name from this map.

pack-priv String[]

Returns:

the array of method name
names
()

Gets all the method names from this map.

pack-priv static Class<?>

Returns:

the equivalent object class
primitiveClass
(Class<?>
a may-be primitive type class
parm
)

Converts a primitive type to its corresponding class.

pack-priv void
put(Method
the method to add
method
)

Adds a method to the map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CACHE_MISSback to summary
private static final Method CACHE_MISS

The cache miss marker method.

methodMapback to summary
private final MethodMap methodMap

Map of methods that are searchable according to method parameters to find a match.

methodsback to summary
private final Map<MethodKey, Method> methods

The method cache.

Cache of Methods, or CACHE_MISS, keyed by method name and actual arguments used to find it.

PRIMITIVE_SIZEback to summary
private static final int PRIMITIVE_SIZE

The initial size of the primitive conversion map.

PRIMITIVE_TYPESback to summary
private static final Map<Class<?>, Class<?>> PRIMITIVE_TYPES

The primitive type to class conversion map.

Constructor Detail

MethodCacheback to summary
pack-priv MethodCache()

Method Detail

cacheMissback to summary
public static Method cacheMiss()

A method that returns itself used as a marker for cache miss, allows the underlying cache map to be strongly typed.

Returns:Method

itself as a method

getback to summary
pack-priv Method get(final MethodKey methodKey) throws AmbiguousException

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:MethodKey

the method key

Returns:Method

A Method object representing the method to invoke or null.

Exceptions
AmbiguousException:
When more than one method is a match for the parameters.
getback to summary
pack-priv Method[] get(final String methodName)

Gets all the methods with a given name from this map.

Parameters
methodName:String

the seeked methods name

Returns:Method[]

the array of methods (null or non-empty)

namesback to summary
pack-priv String[] names()

Gets all the method names from this map.

Returns:String[]

the array of method name

primitiveClassback to summary
pack-priv static Class<?> primitiveClass(Class<?> parm)

Converts a primitive type to its corresponding class.

If the argument type is primitive then we want to convert our primitive type signature to the corresponding Object type so introspection for methods with primitive types will work correctly.

Parameters
parm:Class<?>

a may-be primitive type class

Returns:Class<?>

the equivalent object class

putback to summary
pack-priv void put(Method method)

Adds a method to the map.

Parameters
method:Method

the method to add