com.versionone.util
Class Delegator

java.lang.Object
  extended by com.versionone.util.Delegator

public class Delegator
extends java.lang.Object

Delegator class from the article http://www.onjava.com/pub/a/onjava/2003/05/21/delegates.html?page=1 Class representing a delegate template - also a factory returning the real delegate object


Nested Class Summary
static class Delegator.DelegateInvokeException
          All problems become this type of exception As a runtime we do not impose burdens on the calling code
protected  class Delegator.DelegateProxy
           
 
Field Summary
static Delegator[] EMPTY_ARRAY
           
static java.lang.reflect.Method[] EMPTY_METHOD_ARRAY
           
static java.lang.Object[] EMPTY_OBJECT_ARRAY
           
static Delegator RUNNABLE_DELEGATE
           
 
Constructor Summary
Delegator(java.lang.Class TheInterface)
           
Delegator(java.lang.Class[] params, java.lang.Class retClass)
           
 
Method Summary
 IDelegate build(java.lang.Class target, java.lang.String MethodName)
           
 IDelegate build(java.lang.Object target, java.lang.String MethodName)
           
static java.lang.Runnable buildRunnable(java.lang.Class item, java.lang.String methodName)
          Convenience method to make a runnable delegate
static java.lang.Runnable buildRunnable(java.lang.Object item, java.lang.String methodName)
          Convenience method to make a runnable delegate
protected static java.lang.reflect.Method findMethod(java.lang.Class TheInterface)
          utility code to find the one suitable method in the passed in interface.
protected static java.lang.reflect.Method findSuitableMethod(java.lang.Class targetClass, java.lang.String MethodName, Delegator templ)
          Utility method to locate a proper Method object
 java.lang.Class[] getArguments()
          accessor for argument classes
protected static java.lang.reflect.Method[] getCandidateMethods(java.lang.Class targetClass, java.lang.String MethodName, int nargs)
          utility method to get candidate methods to search
 java.lang.Class getInterface()
           
 java.lang.Class getReturn()
          accessor for return class
protected static boolean isSuitableMethod(java.lang.reflect.Method testMethod, java.lang.Class[] args, java.lang.Class retClass)
          utility method to test suitability
protected static boolean isValidReturn(java.lang.reflect.Method test, java.lang.Class retClass)
          utility method to test return
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_METHOD_ARRAY

public static final java.lang.reflect.Method[] EMPTY_METHOD_ARRAY

EMPTY_OBJECT_ARRAY

public static final java.lang.Object[] EMPTY_OBJECT_ARRAY

EMPTY_ARRAY

public static final Delegator[] EMPTY_ARRAY

RUNNABLE_DELEGATE

public static final Delegator RUNNABLE_DELEGATE
Constructor Detail

Delegator

public Delegator(java.lang.Class[] params,
                 java.lang.Class retClass)
Parameters:
params - non-null array of arguments
retClass - possibly null return class null says do not care

Delegator

public Delegator(java.lang.Class TheInterface)
Parameters:
TheInterface - an non-null interface with EXACTLY one method
Method Detail

buildRunnable

public static java.lang.Runnable buildRunnable(java.lang.Object item,
                                               java.lang.String methodName)
Convenience method to make a runnable delegate

Parameters:
item - non-null target object
methodName - non-null name of a method of type void ()
Returns:
non-null Runnable proxy

buildRunnable

public static java.lang.Runnable buildRunnable(java.lang.Class item,
                                               java.lang.String methodName)
Convenience method to make a runnable delegate

Parameters:
item - non-null target class
methodName - non-null name of a method of type void ()
Returns:
non-null Runnable proxy

getReturn

public java.lang.Class getReturn()
accessor for return class


getArguments

public java.lang.Class[] getArguments()
accessor for argument classes


getInterface

public java.lang.Class getInterface()

build

public IDelegate build(java.lang.Class target,
                       java.lang.String MethodName)
Parameters:
target - non-null class with a bindable static method
MethodName - name of the static method
Returns:
non-null IDelegate if getInterface() is non-null it will be a dynamic prozy implementing that interface

build

public IDelegate build(java.lang.Object target,
                       java.lang.String MethodName)
Parameters:
target - non-null target with a bindable method
MethodName - name of the method
Returns:
non-null IDelegate if getInterface() is non-null it will be a dynamic prozy implementing that interface

isSuitableMethod

protected static boolean isSuitableMethod(java.lang.reflect.Method testMethod,
                                          java.lang.Class[] args,
                                          java.lang.Class retClass)
utility method to test suitability


getCandidateMethods

protected static java.lang.reflect.Method[] getCandidateMethods(java.lang.Class targetClass,
                                                                java.lang.String MethodName,
                                                                int nargs)
utility method to get candidate methods to search


isValidReturn

protected static boolean isValidReturn(java.lang.reflect.Method test,
                                       java.lang.Class retClass)
utility method to test return


findSuitableMethod

protected static java.lang.reflect.Method findSuitableMethod(java.lang.Class targetClass,
                                                             java.lang.String MethodName,
                                                             Delegator templ)
Utility method to locate a proper Method object


findMethod

protected static java.lang.reflect.Method findMethod(java.lang.Class TheInterface)
utility code to find the one suitable method in the passed in interface.