|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sptci.ReflectionUtility
public final class ReflectionUtility
A utility class to handle common reflection tasks.
Copyright 2006 Sans Pareil Technologies, Inc.
| Nested Class Summary | |
|---|---|
private static class |
ReflectionUtility.MethodEntry
A holder object to store a combination of a method name and parameter array. |
| Field Summary | |
|---|---|
private static Map<Class,Map<ReflectionUtility.MethodEntry,Constructor>> |
constructors
A map used to cache classes and their constructors for efficiency. |
private static Map<Class,Map<String,Field>> |
fields
A map used to cache classes and their fields for efficiency. |
private static Map<Class,Map<ReflectionUtility.MethodEntry,Method>> |
methods
A map used to cache classes and their methods for efficiency. |
| Constructor Summary | |
|---|---|
private |
ReflectionUtility()
Default constructor. |
| Method Summary | |
|---|---|
static Method |
fetchAccessor(String property,
Class cls)
Fetches the accessor method for the specified property in the specified class. |
static Method |
fetchAccessor(String property,
Object object)
Fetches the accessor method for the specified property in the specified object. |
static Constructor |
fetchConstructor(Class cls,
Class... parameterTypes)
Return the Constructor instance for the specified
class. |
static Constructor |
fetchConstructor(String cls,
Class... parameterTypes)
Return the Constructor instance for the specified
class. |
static Field |
fetchField(String name,
Class cls)
Return the Field instance with the specified name
from the Class specified. |
static Field |
fetchField(String name,
Object object)
Return the Field instance with the specified name
from the object. |
static Map<String,Field> |
fetchFields(Class cls)
Return the declared fields for the specified Class. |
static Map<String,Field> |
fetchFields(Object object)
Return the declared fields for the specified object. |
static Method |
fetchMethod(Class cls,
String name,
Class... parameters)
Fetch the Method defined in the specified class with
the specified name that accepts the specified
parameters. |
static Method |
fetchMethod(Field field,
String name,
Class... parameters)
Fetch the Method defined in the specified field with
the specified name that accepts the specified
parameters. |
static Method |
fetchMethod(Object object,
String name,
Class... parameters)
Fetch the Method defined in the specified object with
the specified name that accepts the specified
parameters. |
static Method |
fetchMutator(String property,
Class cls)
Fetches the mutator method for the specified property in the specified class. |
static Method |
fetchMutator(String property,
Object object)
Fetches the mutator method for the specified property in the specified object. |
static Object |
fetchObject(String name,
Object object)
Return the Object instance represented by the
specified name from object. |
static Map<String,Object> |
fetchObjects(Object object)
Return the Object instances representing the declared
fields for the specified object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final Map<Class,Map<String,Field>> fields
private static final Map<Class,Map<ReflectionUtility.MethodEntry,Method>> methods
private static final Map<Class,Map<ReflectionUtility.MethodEntry,Constructor>> constructors
| Constructor Detail |
|---|
private ReflectionUtility()
| Method Detail |
|---|
public static final Constructor fetchConstructor(String cls,
Class... parameterTypes)
throws ClassNotFoundException,
NoSuchMethodException
Constructor instance for the specified
class.
cls - The fully qualified name of the class.parameterTypes - The class type(s) of the constructor parameter(s).
ClassNotFoundException - If the specified class could not be located.
NoSuchMethodException - If the specified constructor method could
not be found.
public static final Constructor fetchConstructor(Class cls,
Class... parameterTypes)
throws NoSuchMethodException
Constructor instance for the specified
class.
cls - The class whose constructor is to be fetched.parameterTypes - The class type(s) of the constructor parameter(s).
NoSuchMethodException - If the specified constructor method could
not be found.
public static final Field fetchField(String name,
Object object)
throws NoSuchFieldException
Field instance with the specified name
from the object. Sets the field accessible if
it is not accessible.
name - The name of the field to look up.object - The object from which the field is to be retrieved.
NoSuchFieldException - If no field with the specified name
exists in object.fetchField( String, Class )
public static final Field fetchField(String name,
Class cls)
throws NoSuchFieldException
Field instance with the specified name
from the Class specified. Sets the field accessible if
it is not accessible.
name - The name of the field to look up.cls - The class from which the field is to be retrieved.
NoSuchFieldException - If no field with the specified name
exists in object.
public static final Object fetchObject(String name,
Object object)
throws NoSuchFieldException,
IllegalAccessException
Object instance represented by the
specified name from object.
name - The name of the object to fetch.object - The object from which the field is to be retrieved.
NoSuchFieldException - If no field with the specified name
exists in object.
IllegalAccessException - If the field cannot be accessed
due to custom security policies.fetchField(java.lang.String, java.lang.Object)public static final Map<String,Field> fetchFields(Object object)
object.
object - The object whose declared fields are to be
retrieved.
key and
the field as valuefetchFields( Class )public static final Map<String,Field> fetchFields(Class cls)
Class.
cls - The class whose declared fields are to be
retrieved.
key and
the field as value
public static final Map<String,Object> fetchObjects(Object object)
throws IllegalAccessException
Object instances representing the declared
fields for the specified object.
object - The object for which objects for the declared fields
are to be retrieved.
key and
the object as value
IllegalAccessException - If a custom security policy prevents
access to the fields.fetchFields(java.lang.Object)
public static final Method fetchMethod(Field field,
String name,
Class... parameters)
Method defined in the specified field with
the specified name that accepts the specified
parameters. Please note that this method does not throw a
NoSuchMethodException, but returns null
instead.
field - The field whose method is to be retrieved.name - The name of the method to retrieve.parameters - The parameters accepted by the method.fetchMethod( Class, String, Class[] )
public static final Method fetchMethod(Object object,
String name,
Class... parameters)
Method defined in the specified object with
the specified name that accepts the specified
parameters. Please note that this method does not throw a
NoSuchMethodException, but returns null
instead.
object - The object whose method is to be retrieved.name - The name of the method to retrieve.parameters - The parameters accepted by the method.fetchMethod( Class, String, Class[] )
public static final Method fetchMethod(Class cls,
String name,
Class... parameters)
Method defined in the specified class with
the specified name that accepts the specified
parameters. Please note that this method does not throw a
NoSuchMethodException, but returns null
instead.
cls - The cls whose method is to be retrieved.name - The name of the method to retrieve.parameters - The parameters accepted by the method.
null
if no such method could be found.
public static final Method fetchAccessor(String property,
Object object)
throws IntrospectionException
property - The property whose accessor is to be fetched.object - The object to which the property belongs.
IntrospectionException - If errors are encountered while
introspecting the specified class.fetchAccessor( String, Class )
public static final Method fetchAccessor(String property,
Class cls)
throws IntrospectionException
property - The property whose accessor is to be fetched.cls - The class to which the property belongs.
IntrospectionException - If errors are encountered while
introspecting the specified class.
public static final Method fetchMutator(String property,
Object object)
throws IntrospectionException
property - The property whose mutator is to be fetched.object - The object to which the property belongs.
IntrospectionException - If errors are encountered while
introspecting the specified class.fetchMutator( String, Class )
public static final Method fetchMutator(String property,
Class cls)
throws IntrospectionException
property - The property whose mutator is to be fetched.cls - The class to which the property belongs.
IntrospectionException - If errors are encountered while
introspecting the specified class.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||