|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.picocontainer.gems.util.DelegateMethod<TARGET_TYPE,RETURN_TYPE>
public class DelegateMethod<TARGET_TYPE,RETURN_TYPE>
The DelegateMethod class has been designed in the hope of providing easier access to methods invoked via reflection. Sample:
//Sample Map HashMap<String, String> testMap = new HashMap<String, String>(); testMap.put("a", "A"); //Create delegate method that calls the 'clear' method for HashMap. DelegateMethod<Map, Void> method = new DelegateMethod<Map, Void>(Map.class, "clear"); //Invokes clear() on the HashMap. method.invoke(testMap);
Good uses of this object are for lazy invocation of a method and integrating reflection with a vistor pattern.
Constructor Summary | |
---|---|
DelegateMethod(Class<?> type,
String methodName,
Class<?>[] paramTypes,
Object... parameters)
Constructs a DelegateMethod object with very specific argument types. |
|
DelegateMethod(Class<TARGET_TYPE> type,
String methodName,
Object... parameters)
Constructs a delegate method object that will invoke method methodName on class type with the parameters specified. |
|
DelegateMethod(Method targetMethod,
Object... parameters)
Constructs a method delegate with an explicit Method object. |
Method Summary | ||
---|---|---|
boolean |
equals(Object obj)
|
|
Class<?> |
getReturnType()
Retrieves the expected return type of the delegate method. |
|
int |
hashCode()
|
|
RETURN_TYPE |
invoke()
Used for invoking static methods on the type passed into the constructor. |
|
|
invoke(V target)
Invokes the method specified in the constructor against the target specified. |
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DelegateMethod(Class<TARGET_TYPE> type, String methodName, Object... parameters) throws NoSuchMethodRuntimeException
Note that this version simply grabs the first method that fits the parameter criteria with the specific name. You may need to be careful if use extensive overloading.
To specify the exact types in the method.
type
- the class of the object that should be invoked.methodName
- the name of the method that will be invoked.parameters
- the parameters to be used.
NoSuchMethodRuntimeException
- if the method is not found or parameters that match cannot be found.public DelegateMethod(Class<?> type, String methodName, Class<?>[] paramTypes, Object... parameters) throws NoSuchMethodRuntimeException
type
- the type of the class to be examined for reflection.methodName
- the name of the method to be invoked.paramTypes
- specific parameter types for the method to be found.parameters
- the parameters for method invocation.
NoSuchMethodRuntimeException
- if the method is not found.public DelegateMethod(Method targetMethod, Object... parameters)
targetMethod
- parameters
- Method Detail |
---|
public RETURN_TYPE invoke() throws IllegalArgumentException, IllegalAccessRuntimeException, InvocationTargetRuntimeException
IllegalArgumentException
- if the method being invoked is not static.
IllegalAccessRuntimeException
- if the method being invoked is not public.
InvocationTargetRuntimeException
- if an exception is thrown within the method being invoked.public <V extends TARGET_TYPE> RETURN_TYPE invoke(V target) throws IllegalAccessRuntimeException, InvocationTargetRuntimeException
V
- a subclass of the type specified by the object declaration.
This allows Map delegates to operate on HashMaps etc.target
- the target object instance to be operated upon. Unless
invoking a static method, this should not be null.
IllegalArgumentException
- if the method being invoked is not static and parameter
target null.
IllegalAccessRuntimeException
- if the method being invoked is not public.
InvocationTargetRuntimeException
- if an exception is thrown within the method being invoked.public String toString()
toString
in class Object
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
public Class<?> getReturnType()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |