final class Reflector
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Member>>> |
classMaps |
private static java.lang.String |
CONSTRUCTOR_METHOD_NAME |
private static java.lang.String |
GET_INSTANCE_METHOD_NAME |
| Constructor and Description |
|---|
Reflector()
Ensure no instances of Reflector are created...this is a utility.
|
| Modifier and Type | Method and Description |
|---|---|
private java.lang.reflect.Method |
_getMethod(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Class<?>... params) |
java.lang.reflect.Constructor<?> |
getConstructor(java.lang.Class<?> targetClass,
java.lang.Class<?>... params)
Return the constructor, checking the cache first and storing in cache if not already there..
|
private java.util.Map<java.lang.String,java.lang.reflect.Member> |
getConstructorMap(java.lang.Class<?> theClass)
Retrieve the cache of constructors for the specified class.
|
java.lang.Object |
getField(java.lang.Object target,
java.lang.String fieldName) |
java.lang.Object |
getField(java.lang.Object target,
java.lang.String fieldName,
boolean breakAccessibility) |
java.lang.reflect.Method |
getMethod(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Class<?>... params)
Return the method, checking the cache first and storing in cache if not already there..
|
private java.util.Map<java.lang.String,java.lang.reflect.Member> |
getMethodMap(java.lang.Class<?> theClass,
java.lang.String methodName)
Retrieve the cache of methods for the specified class and method name.
|
java.lang.Object |
getObjectProperty(java.lang.Object target,
java.lang.String propertyName) |
java.lang.Object |
getSingleton(java.lang.Class<?> theClass,
java.lang.Object... initParams)
Retrieve the singleton instance of a class, given the array of parameters...
|
java.lang.Object |
getStaticField(java.lang.Class<?> targetClass,
java.lang.String fieldName) |
java.lang.Object |
invoke(java.lang.Object target,
java.lang.String methodName,
java.lang.Object... params)
Invoke the specified method on the specified target with the specified params...
|
java.lang.Object |
invokeStatic(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Object... params)
Invoke the specified static method with the specified params...
|
java.lang.Object |
newInstance(java.lang.Class<?> theClass,
java.lang.Object... params)
Create a new instance of a class, given the array of parameters...
|
private static final java.lang.String CONSTRUCTOR_METHOD_NAME
private static final java.lang.String GET_INSTANCE_METHOD_NAME
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Member>>> classMaps
Reflector()
public java.lang.Object newInstance(java.lang.Class<?> theClass,
java.lang.Object... params)
throws ReflectorException
theClass - The class to instantiateparams - The parameters to pass to the constructorReflectorException - In case anything goes wrong here...public java.lang.Object getSingleton(java.lang.Class<?> theClass,
java.lang.Object... initParams)
throws ReflectorException
theClass - The class to retrieve the singleton ofinitParams - The parameters to pass to the constructorReflectorException - In case anything goes wrong here...public java.lang.Object invoke(java.lang.Object target,
java.lang.String methodName,
java.lang.Object... params)
throws ReflectorException
target - The target of the invocationmethodName - The method name to invokeparams - The parameters to pass to the method invocationReflectorException - In case of an error looking up or invoking the method.public java.lang.Object getStaticField(java.lang.Class<?> targetClass,
java.lang.String fieldName)
throws ReflectorException
ReflectorExceptionpublic java.lang.Object getField(java.lang.Object target,
java.lang.String fieldName)
throws ReflectorException
ReflectorExceptionpublic java.lang.Object getField(java.lang.Object target,
java.lang.String fieldName,
boolean breakAccessibility)
throws ReflectorException
ReflectorExceptionpublic java.lang.Object invokeStatic(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Object... params)
throws ReflectorException
targetClass - The target class of the invocationmethodName - The method name to invokeparams - The parameters to pass to the method invocationReflectorException - In case of an error looking up or invoking the method.public java.lang.reflect.Constructor<?> getConstructor(java.lang.Class<?> targetClass,
java.lang.Class<?>... params)
throws ReflectorException
targetClass - The class to get the constructor fromparams - The classes of the parameters which the constructor should match.nullReflectorException - In case we can't retrieve the proper constructor.public java.lang.Object getObjectProperty(java.lang.Object target,
java.lang.String propertyName)
throws ReflectorException
ReflectorExceptionpublic java.lang.reflect.Method getMethod(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Class<?>... params)
throws ReflectorException
targetClass - The class to get the method fromparams - The classes of the parameters which the method should match.nullReflectorException - In case we can't retrieve the proper method.private java.lang.reflect.Method _getMethod(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Class<?>... params)
throws ReflectorException
ReflectorExceptionprivate java.util.Map<java.lang.String,java.lang.reflect.Member> getConstructorMap(java.lang.Class<?> theClass)
throws ReflectorException
theClass - the class to lookup.ReflectorException - in case of a lookup error.private java.util.Map<java.lang.String,java.lang.reflect.Member> getMethodMap(java.lang.Class<?> theClass,
java.lang.String methodName)
theClass - the class to lookup.methodName - The name of the method to lookup.