org.codehaus.plexus.util.introspection

Class ClassMap

public class ClassMap extends Object

A cache of introspection information for a specific class instance. Keys java.lang.Method objects by a concatenation of the method name and the names of classes that make up the parameters.

Version: $Id: ClassMap.java 1756 2005-04-21 16:03:11Z brett $

Author: Jason van Zyl Bob McWhirter Attila Szegedi Geir Magnusson Jr.

Nested Class Summary
static classClassMap.CacheMiss
static classClassMap.MethodInfo
Used for the iterative discovery process for public methods.
Field Summary
Classclazz
Class passed into the constructor used to as the basis for the Method map.
static ClassMap.CacheMissCACHE_MISS
MapmethodCache
Cache of Methods, or CACHE_MISS, keyed by method name and actual arguments used to find it.
MethodMapmethodMap
static ObjectOBJECT
Constructor Summary
ClassMap(Class clazz)
Standard constructor
Method Summary
MethodfindMethod(String name, Object[] params)
Find a Method using the methodKey provided.
static Method[]getAccessibleMethods(Class clazz)
Retrieves public methods for a class.
static intgetAccessibleMethods(Class clazz, ClassMap.MethodInfo[] methodInfos, int upcastCount)
Recursively finds a match for each method, starting with the class, and then searching the superclass and interfaces.
ClassgetCachedClass()
static MethodgetPublicMethod(Method method)
For a given method, retrieves its publicly accessible counterpart.
static MethodgetPublicMethod(Class clazz, String name, Class[] paramTypes)
Looks up the method with specified name and signature in the first public superclass or implemented interface of the class.
StringmakeMethodKey(Method method)
Make a methodKey for the given method using the concatenation of the name and the types of the method parameters.
static StringmakeMethodKey(String method, Object[] params)
voidpopulateMethodCache()
Populate the Map of direct hits.

Field Detail

clazz

private Class clazz
Class passed into the constructor used to as the basis for the Method map.

CACHE_MISS

private static final ClassMap.CacheMiss CACHE_MISS

methodCache

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

methodMap

private MethodMap methodMap

OBJECT

private static final Object OBJECT

Constructor Detail

ClassMap

public ClassMap(Class clazz)
Standard constructor

Method Detail

findMethod

public Method findMethod(String name, Object[] params)
Find a Method using the methodKey provided.

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.

getAccessibleMethods

private static Method[] getAccessibleMethods(Class clazz)
Retrieves public methods for a class. In case the class is not public, retrieves methods with same signature as its public methods from public superclasses and interfaces (if they exist). Basically upcasts every method to the nearest acccessible method.

getAccessibleMethods

private static int getAccessibleMethods(Class clazz, ClassMap.MethodInfo[] methodInfos, int upcastCount)
Recursively finds a match for each method, starting with the class, and then searching the superclass and interfaces.

Parameters: clazz Class to check methodInfos array of methods we are searching to match upcastCount current number of methods we have matched

Returns: count of matched methods

getCachedClass

Class getCachedClass()

Returns: the class object whose methods are cached by this map.

getPublicMethod

public static Method getPublicMethod(Method method)
For a given method, retrieves its publicly accessible counterpart. This method will look for a method with same name and signature declared in a public superclass or implemented interface of this method's declaring class. This counterpart method is publicly callable.

Parameters: method a method whose publicly callable counterpart is requested.

Returns: the publicly callable counterpart method. Note that if the parameter method is itself declared by a public class, this method is an identity function.

getPublicMethod

private static Method getPublicMethod(Class clazz, String name, Class[] paramTypes)
Looks up the method with specified name and signature in the first public superclass or implemented interface of the class.

Parameters: class the class whose method is sought name the name of the method paramTypes the classes of method parameters

makeMethodKey

private String makeMethodKey(Method method)
Make a methodKey for the given method using the concatenation of the name and the types of the method parameters.

makeMethodKey

private static String makeMethodKey(String method, Object[] params)

populateMethodCache

private void populateMethodCache()
Populate the Map of direct hits. These are taken from all the public methods that our class provides.