|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.plexus.util.reflection.Reflector
public final class Reflector
Utility class used to instantiate an object using reflection. This utility hides many of the gory details needed to do this.
Field Summary | |
---|---|
private java.util.HashMap |
classMaps
|
private static java.lang.String |
CONSTRUCTOR_METHOD_NAME
|
private static java.lang.String |
GET_INSTANCE_METHOD_NAME
|
Constructor Summary | |
---|---|
Reflector()
Ensure no instances of Reflector are created...this is a utility. |
Method Summary | |
---|---|
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 |
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 |
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... |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String CONSTRUCTOR_METHOD_NAME
private static final java.lang.String GET_INSTANCE_METHOD_NAME
private java.util.HashMap classMaps
Constructor Detail |
---|
public Reflector()
Method Detail |
---|
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 constructor
ReflectorException
- 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 constructor
ReflectorException
- 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 invocation
ReflectorException
- 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
ReflectorException
public java.lang.Object getField(java.lang.Object target, java.lang.String fieldName) throws ReflectorException
ReflectorException
public java.lang.Object getField(java.lang.Object target, java.lang.String fieldName, boolean breakAccessibility) throws ReflectorException
ReflectorException
public 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 invocation
ReflectorException
- 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.
ReflectorException
- In case we can't retrieve the proper constructor.public java.lang.Object getObjectProperty(java.lang.Object target, java.lang.String propertyName) throws ReflectorException
ReflectorException
public 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.
ReflectorException
- 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
ReflectorException
private java.util.Map getConstructorMap(java.lang.Class theClass) throws ReflectorException
theClass
- the class to lookup.
ReflectorException
- in case of a lookup error.private java.util.Map getMethodMap(java.lang.Class theClass, java.lang.String methodName) throws ReflectorException
theClass
- the class to lookup.methodName
- The name of the method to lookup.
ReflectorException
- in case of a lookup error.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |