dsto.dfc.reflection
Class Delegate

java.lang.Object
  extended by dsto.dfc.reflection.Delegate
All Implemented Interfaces:
IDelegate, Runnable

public class Delegate
extends Object
implements IDelegate, Runnable

A delegate to a method in a class instance. Supports semi-lambda-like ability to pre-specify some arguments at creation for appending to the set called with invoke().

Author:
Matthew Phillips

Field Summary
 
Fields inherited from interface dsto.dfc.reflection.IDelegate
EMPTY_ARGS
 
Constructor Summary
Delegate(Object target, String methodName)
           
Delegate(Object target, String methodName, Class... argTypes)
          Create a delegate by giving a name and an argument type list.
Delegate(Object target, String methodName, Class[] argTypes, Object[] args)
          Create an instance, fully specifying method and argument list.
Delegate(Object target, String methodName, Object... args)
           
 
Method Summary
 void invoke(Object... args)
          Call the method pointed to by the delegate with the default parameter set.
 void run()
           
 Object target()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Delegate

public Delegate(Object target,
                String methodName)
         throws IllegalArgumentException
Throws:
IllegalArgumentException

Delegate

public Delegate(Object target,
                String methodName,
                Object... args)
         throws IllegalArgumentException
Throws:
IllegalArgumentException

Delegate

public Delegate(Object target,
                String methodName,
                Class... argTypes)
         throws IllegalArgumentException
Create a delegate by giving a name and an argument type list.

Parameters:
target - The target object.
methodName - The name of the method to call.
argTypes - The argument types of the method.
Throws:
IllegalArgumentException

Delegate

public Delegate(Object target,
                String methodName,
                Class[] argTypes,
                Object[] args)
         throws IllegalArgumentException
Create an instance, fully specifying method and argument list.

Parameters:
target - The target object.
methodName - The name of the method to call.
argTypes - The argument types of the method.
args - Any arguments to pre-specify.
Throws:
IllegalArgumentException
Method Detail

toString

public String toString()
Overrides:
toString in class Object

target

public Object target()

run

public void run()
Specified by:
run in interface Runnable

invoke

public void invoke(Object... args)
            throws InvokeException
Call the method pointed to by the delegate with the default parameter set.

Specified by:
invoke in interface IDelegate
Parameters:
args - The arguments.
Throws:
InvokeException - if a checked exception occurs.


Copyright © 2008 Commonwealth of Australia