|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectCallback
Generic class to facilate use of callbacks
Also provides a static helper function to get an object of Method that can be passed to the constructor of this class
Example:
To get a Method object for the method public foo(String str) in class Test:
String[] paramTypes = {"java.lang.String"};
Method method = Callback.getMethod("foo", this, paramTypes);
Callback cb = new Callback(method, this, "fooTest");
The above code snippet assumes that it is written inside class Test, hence the use of this.
The method must have public visibility.
| Constructor Summary | |
Callback(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object[] params)
Initializes member variables |
|
| Method Summary | |
static java.lang.reflect.Method |
getMethod(java.lang.String methodName,
java.lang.Object obj,
java.lang.String[] parameterTypes)
Helper function to get a Method object which is needed to pass to the constructor of this class |
void |
invoke()
Invokes the callback |
void |
setParams(java.lang.Object[] params)
Sets the params to be passed to the method when it is invoked |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Callback(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object[] params)
method - The method to be invokedobj - The object on which the method is to be invokedparams - An array of objects to be passed to the method as parameters when it is invoked.
Can be null if no parameters are to be passed| Method Detail |
public void setParams(java.lang.Object[] params)
params - The params to be passed to the method when it is invoked
public void invoke()
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException - Thrown by invoke method in class Method
java.lang.reflect.InvocationTargetException - Thrown by invoke method in class Method, if the underlying method throws an exception
public static java.lang.reflect.Method getMethod(java.lang.String methodName,
java.lang.Object obj,
java.lang.String[] parameterTypes)
throws java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.SecurityException
methodName - The name of the method that we want a Method object forobj - The object that owns the methodparameterTypes - Array of strings of parameter type names. Can be null if there are no parameter types
java.lang.ClassNotFoundException - This exception is thrown by Class.forName if the given class name does not exist
java.lang.NoSuchMethodException - Thrown by Class.getMethod if a matching method is not found
java.lang.SecurityException - Thrown by Class.getMethod if access to the information is denied
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||