public final class Reflector extends Object
Constructor and Description |
---|
Reflector()
Ensure no instances of Reflector are created...this is a utility.
|
Modifier and Type | Method and Description |
---|---|
<T> Constructor<T> |
getConstructor(Class<T> targetClass,
Class[] params)
Return the constructor, checking the cache first and storing in cache if not already there..
|
Object |
getField(Object target,
String fieldName) |
Object |
getField(Object target,
String fieldName,
boolean breakAccessibility) |
Method |
getMethod(Class targetClass,
String methodName,
Class[] params)
Return the method, checking the cache first and storing in cache if not already there..
|
Object |
getObjectProperty(Object target,
String propertyName) |
<T> T |
getSingleton(Class<T> theClass,
Object[] initParams)
Retrieve the singleton instance of a class, given the array of parameters...
|
Object |
getStaticField(Class targetClass,
String fieldName) |
Object |
invoke(Object target,
String methodName,
Object[] params)
Invoke the specified method on the specified target with the specified params...
|
Object |
invokeStatic(Class targetClass,
String methodName,
Object[] params)
Invoke the specified static method with the specified params...
|
<T> T |
newInstance(Class<T> theClass,
Object[] params)
Create a new instance of a class, given the array of parameters...
|
public Reflector()
public <T> T newInstance(Class<T> theClass, Object[] params) throws ReflectorException
T
- the typetheClass
- The class to instantiateparams
- The parameters to pass to the constructorReflectorException
- In case anything goes wrong here...public <T> T getSingleton(Class<T> theClass, Object[] initParams) throws ReflectorException
T
- the typetheClass
- The class to retrieve the singleton ofinitParams
- The parameters to pass to the constructorReflectorException
- In case anything goes wrong here...public Object invoke(Object target, String methodName, 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 Object getStaticField(Class targetClass, String fieldName) throws ReflectorException
ReflectorException
public Object getField(Object target, String fieldName) throws ReflectorException
ReflectorException
public Object getField(Object target, String fieldName, boolean breakAccessibility) throws ReflectorException
ReflectorException
public Object invokeStatic(Class targetClass, String methodName, 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 <T> Constructor<T> getConstructor(Class<T> targetClass, Class[] params) throws ReflectorException
T
- the typetargetClass
- The class to get the constructor fromparams
- The classes of the parameters which the constructor should match.ReflectorException
- In case we can't retrieve the proper constructor.public Object getObjectProperty(Object target, String propertyName) throws ReflectorException
ReflectorException
public Method getMethod(Class targetClass, String methodName, Class[] params) throws ReflectorException
targetClass
- The class to get the method fromparams
- The classes of the parameters which the method should match.methodName
- the method nameReflectorException
- In case we can't retrieve the proper method.Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.