public class Callback
extends java.lang.Object
java.lang.reflect
.
Accessors are provided to store and retrieve data but otherwise this data is not modified an any way.
The current design provides the ability to define a static method call
or a call to a specific instance which must be specified in advance. There
is no support for the dynamic instantiation of this class. In other
words, if an instance method call is needed, the caller must construct
the Callback
object with the target instance object or
the setTargetInstance(java.lang.Object)
method must be called after construction or
before the instance reference is needed. Since the Callback
object itself does not handle the invocation, but rather only stores the
data needed to do such an invocation, one may also obtain the instance
reference via some other means.
There is no direct storage of parameter or return type information. This
is the responsibility of the caller in the case where the class and
method names are used instead of a java.lang.reflect.Method
object. Since the Method
object does store this information,
if this value is not null
, the parameter and return type
information can be indirectly accessed.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
className
Stores the fully qualified class name of the target class object.
|
private java.lang.reflect.Method |
method
Stores the
java.lang.reflect.Method which can be used
to invoke the target method in the correct class. |
private java.lang.String |
methodName
Stores the method name to invoke on the target class.
|
private java.lang.Object |
targetInstance
Stores the reference to the instance of the target object on which to
invoke the method.
|
Constructor and Description |
---|
Callback(java.lang.Object instance,
java.lang.reflect.Method method)
Constructs a
Callback instance using an instance of
java.lang.reflect.Method . |
Callback(java.lang.Object instance,
java.lang.String className,
java.lang.String methodName)
Constructs a
Callback instance using Strings representing
the class and method names for the target. |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getClassName()
Returns the class name of the target object.
|
java.lang.reflect.Method |
getMethod()
Returns the
java.lang.reflect.Method which can be used to
invoke the associated method. |
java.lang.String |
getMethodName()
Returns the method name to be called in the target object.
|
java.lang.Object |
getTargetInstance()
Returns the reference to the target object.
|
void |
setClassName(java.lang.String className)
Sets the class name of the target object.
|
void |
setMethod(java.lang.reflect.Method method)
Sets the
java.lang.reflect.Method which can be used to
invoke the associated method. |
void |
setMethodName(java.lang.String methodName)
Sets the method name to be called in the target object.
|
void |
setTargetInstance(java.lang.Object instance)
Sets the reference to the target object on which to invoke the
associated method.
|
private java.lang.Object targetInstance
null
in the case where a
static method call is required.private java.lang.String className
null
if this Callback
instance
was constructed with a java.lang.reflect.Method
object.private java.lang.String methodName
null
if this Callback
instance was
constructed with a java.lang.reflect.Method
object.private java.lang.reflect.Method method
java.lang.reflect.Method
which can be used
to invoke the target method in the correct class. This may be
null
if this Callback
instance was
constructed with the class and method name strings, however usually a
Method
reference would be cached here when it is first
dynamically found.public Callback(java.lang.Object instance, java.lang.String className, java.lang.String methodName)
Callback
instance using Strings representing
the class and method names for the target.instance
- Object reference to the target object if the method call is
non-static. This should be null
for a static
method call.className
- Fully qualified (including package) name of the target class.methodName
- Name of the method to call. This should be null
to
specify a constructor.public Callback(java.lang.Object instance, java.lang.reflect.Method method)
Callback
instance using an instance of
java.lang.reflect.Method
.instance
- Object reference to the target object if the method call is
non-static. This should be null
for a static
method call.method
- Uniquely represents the method to be called using the
Reflection features of Java.public java.lang.Object getTargetInstance()
null
if the method call is static.public void setTargetInstance(java.lang.Object instance)
null
if the method
call is static.instance
- The target object on which to invoke the associated method or
null
if the method call is static.public java.lang.String getClassName()
public void setClassName(java.lang.String className)
className
- The class name.public java.lang.String getMethodName()
null
or empty string represent
a constructor.public void setMethodName(java.lang.String methodName)
methodName
- The method name. null
or empty string represent
a constructor.public java.lang.reflect.Method getMethod()
java.lang.reflect.Method
which can be used to
invoke the associated method. May be null
if the
Callback
is only constructed using strings.public void setMethod(java.lang.reflect.Method method)
java.lang.reflect.Method
which can be used to
invoke the associated method. May be null
if the
Callback
is only constructed using strings.method
- Method object.