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 |
---|---|
private static class |
ReflectionUtils.MetaData
MetaData contains lookup methods for
Constructor s and
Method s of a particular Class. |
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
LOGGER |
private static java.util.Map<java.lang.ClassLoader,java.util.concurrent.ConcurrentMap<java.lang.String,ReflectionUtils.MetaData>> |
REFLECTION_CACHE
Cache
|
Modifier | Constructor and Description |
---|---|
private |
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
clearCache(java.lang.ClassLoader loader)
Clears the cache for the specified
ClassLoader . |
private static ReflectionUtils.MetaData |
getMetaData(java.lang.ClassLoader loader,
java.lang.Class<?> clazz)
Return the
MetaData for the specified Class. |
private static ReflectionUtils.MetaData |
getMetaData(java.lang.ClassLoader loader,
java.lang.String className)
Return the
MetaData for the specified className. |
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.reflect.Method |
lookupReadMethod(java.lang.String className,
java.lang.String propertyName) |
static java.lang.reflect.Method |
lookupWriteMethod(java.lang.String className,
java.lang.String propertyName) |
static java.lang.Object |
newInstance(java.lang.String className)
Constructs a new object instance based off the
provided class name.
|
private static final java.util.logging.Logger LOGGER
private static final java.util.Map<java.lang.ClassLoader,java.util.concurrent.ConcurrentMap<java.lang.String,ReflectionUtils.MetaData>> REFLECTION_CACHE
Cache
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 className
public static java.lang.reflect.Method lookupWriteMethod(java.lang.String className, java.lang.String propertyName)
className
- the fully qualified class namepropertyName
- a JavaBeans property namenull
if the property doesn't exist or is readonly.public static java.lang.reflect.Method lookupReadMethod(java.lang.String className, java.lang.String propertyName)
className
- the fully qualified class namepropertyName
- a JavaBeans property namenull
if the property doesn't exist or can't be read.private static ReflectionUtils.MetaData getMetaData(java.lang.ClassLoader loader, java.lang.Class<?> clazz)
Return the MetaData
for the specified Class.
This will check the cache associated with the specified
ClassLoader
. If there is no cache hit, then a new
MetaData
instance will be created and stored.
loader
- ClassLoader
clazz
- the Class of interestMetaData
object for the specified Classprivate static ReflectionUtils.MetaData getMetaData(java.lang.ClassLoader loader, java.lang.String className)
Return the MetaData
for the specified className.
This will check the cache associated with the specified
ClassLoader
. If there is no cache hit, then a new
MetaData
instance will be created and stored.
loader
- ClassLoader
className
- the class of interestMetaData
object for the specified ClassCopyright © 2002-2013 Oracle America, Inc. All Rights Reserved.