com.versionone.utils

## Class Delegator

- java.lang.Object
- - com.versionone.utils.Delegator

-     public class Delegator
      extends 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
  Author:
    Steve Lewis smlewis@lordjoe.com

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Delegator[]` | `EMPTY_ARRAY`
    `static Method[]` | `EMPTY_METHOD_ARRAY`
    `static Object[]` | `EMPTY_OBJECT_ARRAY`
    `static Delegator` | `RUNNABLE_DELEGATE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Delegator(Class TheInterface)`
    `Delegator(Class[] params, Class retClass)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `IDelegate` | `build(Class target, String MethodName)`
    `IDelegate` | `build(Object target, String MethodName)`
    `static Runnable` | `buildRunnable(Class item, String methodName)` Convenience method to make a runnable delegate
    `static Runnable` | `buildRunnable(Object item, String methodName)` Convenience method to make a runnable delegate
    `protected static Method` | `findMethod(Class TheInterface)` utility code to find the one suitable method in the passed in interface.
    `protected static Method` | `findSuitableMethod(Class targetClass, String MethodName, Delegator templ)` Utility method to locate a proper Method object
    `Class[]` | `getArguments()` accessor for argument classes
    `protected static Method[]` | `getCandidateMethods(Class targetClass, String MethodName, int nargs)` utility method to get candidate methods to search
    `Class` | `getInterface()`
    `Class` | `getReturn()` accessor for return class
    `protected static boolean` | `isSuitableMethod(Method testMethod, Class[] args, Class retClass)` utility method to test suitability
    `protected static boolean` | `isValidReturn(Method test, 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 Method[] EMPTY_METHOD_ARRAY

    - #### EMPTY_OBJECT_ARRAY

          public static final 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(Class[] params,
                           Class retClass)

      Parameters:
        `params` - non-null array of arguments
        `retClass` - possibly null return class null says do not care

    - #### Delegator

          public Delegator(Class TheInterface)

      Parameters:
        `TheInterface` - an non-null interface with EXACTLY one method

  - ### Method Detail

    - #### buildRunnable

          public static Runnable buildRunnable(Object item,
                                               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 Runnable buildRunnable(Class item,
                                               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 Class getReturn()

      accessor for return class
      Returns:
        class - Class

    - #### getArguments

          public Class[] getArguments()

      accessor for argument classes
      Returns:
        class - Class[]

    - #### getInterface

          public Class getInterface()

    - #### build

          public IDelegate build(Class target,
                                 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 proxy implementing that interface

    - #### build

          public IDelegate build(Object target,
                                 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 proxy implementing that interface

    - #### isSuitableMethod

          protected static boolean isSuitableMethod(Method testMethod,
                                                    Class[] args,
                                                    Class retClass)

      utility method to test suitability
      Parameters:
        `args` - - Class[]
        `retClass` - - Class
        `testMethod` - - Method
      Returns:
        boolean - boolean

    - #### getCandidateMethods

          protected static Method[] getCandidateMethods(Class targetClass,
                                                        String MethodName,
                                                        int nargs)

      utility method to get candidate methods to search
      Parameters:
        `MethodName` - - String
        `nargs` - - int
        `targetClass` - - Class
      Returns:
        Method - Method[]

    - #### isValidReturn

          protected static boolean isValidReturn(Method test,
                                                 Class retClass)

      utility method to test return
      Parameters:
        `retClass` - - Class
        `test` - - Method
      Returns:
        boolean - boolean

    - #### findSuitableMethod

          protected static Method findSuitableMethod(Class targetClass,
                                                     String MethodName,
                                                     Delegator templ)

      Utility method to locate a proper Method object
      Parameters:
        `targetClass` - - Class
        `MethodName` - - String
        `templ` - - Delegator
      Returns:
        Method - Method

    - #### findMethod

          protected static Method findMethod(Class TheInterface)

      utility code to find the one suitable method in the passed in interface.
      Parameters:
        `TheInterface` - - Class
      Returns:
        Method - Method

Copyright © 2021 VersionOne, Inc.. All rights reserved.