public final class ReflectionUtils
extends java.lang.Object
A set of utility methods to make working with Classes and Reflection a little easier.
| Modifier and Type | Class and Description |
|---|---|
static class |
ReflectionUtils.ReflectionUtilsListener
A
SerlvetContextListener to ensure that the ReflectionUtils
cache is intialized and cleanup when the application starts and finishes. |
| Modifier and Type | Method and Description |
|---|---|
static void |
clearCache(java.lang.ClassLoader loader)
Clears the cache for the specified
ClassLoader. |
static void |
initCache(java.lang.ClassLoader loader) |
static java.lang.Class<?> |
lookupClass(java.lang.String className)
Obtain a
Class instance based on the provided
String name. |
static java.lang.reflect.Constructor |
lookupConstructor(java.lang.Class<?> clazz,
java.lang.Class<?>... params)
Returns the
Constructor appropriate to the specified
Class and parameters. |
static java.lang.reflect.Method |
lookupMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... params)
Returns the
Method appropriate to the specified
Class, method name, and parameters. |
static java.lang.Object |
newInstance(java.lang.String className)
Constructs a new object instance based off the
provided class name.
|
public static void clearCache(java.lang.ClassLoader loader)
Clears the cache for the specified ClassLoader.
This method MUST be called when ConfigureListener
.contextDestroyed() is called.
loader - the ClassLoader whose associated cache
should be clearedpublic static void initCache(java.lang.ClassLoader loader)
public static java.lang.reflect.Constructor lookupConstructor(java.lang.Class<?> clazz,
java.lang.Class<?>... params)
Returns the Constructor appropriate to the specified
Class and parameters.
clazz - the Class of interestparams - the parameters for the constructor of the provided Classpublic static java.lang.reflect.Method lookupMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... params)
Returns the Method appropriate to the specified
Class, method name, and parameters.
clazz - the Class of interestmethodName - the name of the methodparams - the parameters for the specified methodpublic static java.lang.Object newInstance(java.lang.String className)
throws java.lang.InstantiationException,
java.lang.IllegalAccessException
Constructs a new object instance based off the provided class name.
className - the class of the object to instantiatejava.lang.InstantiationException - if the class cannot be instantiatedjava.lang.IllegalAccessException - if there is a security violationpublic static java.lang.Class<?> lookupClass(java.lang.String className)
Obtain a Class instance based on the provided
String name.
className - the class to look upClass corresponding to classNameCopyright ? 2002-2006 Sun Microsystems, Inc. All Rights Reserved.