public class IntrospectorBase
extends java.lang.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 Hastable where Method objects are keyed by a concatenation of the method name and the names of classes that make up the parameters. For example, a method with the following signature: public void method(String a, StringBuffer b) would be mapped by the key: "method" + "java.lang.String" + "java.lang.StringBuffer" This mapping is performed for all the methods in a class and stored.
Modifier and Type | Class and Description |
---|---|
private static class |
IntrospectorBase.CacheMiss
A Constructor get cache-miss.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class<?>,ClassMap> |
classMethodMaps
Holds the method maps for the classes we know about, keyed by Class.
|
private java.util.Map<java.lang.String,java.lang.Class<?>> |
constructibleClasses
Holds the set of classes we have introspected.
|
private java.util.Map<MethodKey,java.lang.reflect.Constructor<?>> |
constructorsMap
Holds the map of classes ctors we know about as well as unknown ones.
|
private static java.lang.reflect.Constructor<?> |
CTOR_MISS
The cache-miss marker for the constructors map.
|
private java.lang.ClassLoader |
loader
The class loader used to solve constructors if needed.
|
protected org.apache.commons.logging.Log |
rlog
the logger.
|
Constructor and Description |
---|
IntrospectorBase(org.apache.commons.logging.Log log)
Create the introspector.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Class<?> |
getClassByName(java.lang.String className)
Gets a class by name through this introspector class loader.
|
java.lang.reflect.Constructor<?> |
getConstructor(java.lang.Class<?> c,
MethodKey key)
Gets the constructor defined by the
MethodKey . |
java.lang.reflect.Constructor<?> |
getConstructor(MethodKey key)
Gets the constructor defined by the
MethodKey . |
java.lang.reflect.Field |
getField(java.lang.Class<?> c,
java.lang.String key)
Gets the field named by
key for the class c . |
java.lang.String[] |
getFieldNames(java.lang.Class<?> c)
Gets the array of accessible field names known for a given class.
|
private ClassMap |
getMap(java.lang.Class<?> c)
Gets the ClassMap for a given class.
|
java.lang.reflect.Method |
getMethod(java.lang.Class<?> c,
MethodKey key)
Gets the method defined by the
MethodKey for the class c . |
java.lang.String[] |
getMethodNames(java.lang.Class<?> c)
Gets the array of accessible methods names known for a given class.
|
java.lang.reflect.Method[] |
getMethods(java.lang.Class<?> c,
java.lang.String methodName)
Gets the array of accessible method known for a given class.
|
private static boolean |
isLoadedBy(java.lang.ClassLoader loader,
java.lang.Class<?> clazz)
Checks whether a class is loaded through a given class loader or one of its ascendants.
|
void |
setLoader(java.lang.ClassLoader cloader)
Sets the class loader used to solve constructors.
|
protected final org.apache.commons.logging.Log rlog
private final java.util.Map<java.lang.Class<?>,ClassMap> classMethodMaps
private java.lang.ClassLoader loader
private final java.util.Map<MethodKey,java.lang.reflect.Constructor<?>> constructorsMap
private final java.util.Map<java.lang.String,java.lang.Class<?>> constructibleClasses
private static final java.lang.reflect.Constructor<?> CTOR_MISS
public IntrospectorBase(org.apache.commons.logging.Log log)
log
- the logger to usepublic java.lang.Class<?> getClassByName(java.lang.String className)
className
- the class namepublic java.lang.reflect.Method getMethod(java.lang.Class<?> c, MethodKey key)
MethodKey
for the class c
.c
- Class in which the method search is taking placekey
- Key of the method being searched forMethodKey.AmbiguousException
- if no unambiguous method could be found through introspectionpublic java.lang.reflect.Field getField(java.lang.Class<?> c, java.lang.String key)
key
for the class c
.c
- Class in which the field search is taking placekey
- Name of the field being searched forpublic java.lang.String[] getFieldNames(java.lang.Class<?> c)
c
- the classpublic java.lang.String[] getMethodNames(java.lang.Class<?> c)
c
- the classpublic java.lang.reflect.Method[] getMethods(java.lang.Class<?> c, java.lang.String methodName)
c
- the classmethodName
- the method namepublic void setLoader(java.lang.ClassLoader cloader)
Also cleans the constructors and methods caches.
cloader
- the class loader; if null, use this instance class loaderprivate static boolean isLoadedBy(java.lang.ClassLoader loader, java.lang.Class<?> clazz)
loader
- the class loaderclazz
- the class to checkpublic java.lang.reflect.Constructor<?> getConstructor(MethodKey key)
MethodKey
.key
- Key of the constructor being searched forpublic java.lang.reflect.Constructor<?> getConstructor(java.lang.Class<?> c, MethodKey key)
MethodKey
.c
- the class we want to instantiatekey
- Key of the constructor being searched forprivate ClassMap getMap(java.lang.Class<?> c)
c
- the class