gov.sns.tools.reflect
Class Selector

java.lang.Object
  |
  +--gov.sns.tools.reflect.Selector

public class Selector
extends java.lang.Object

Selector is a convenience class that makes much of the Method class easier to use. Unlike Method, a Selector instance is not associated with a particular class. Binding happens upon invocation so the same selector can be used with many classes that do not necessarily share the same interface or superclasses. Also, Selector has convenience methods that allow fewer lines to be invoked. All exceptions are Runtime exceptions thus freeing the developer from having to deal with exceptions during rapid development. This class is intended to be used to handle group actions from a node perspective rather than a channel perspective. It can also be useful in creating powerful GUIs that allow users to script XAL.


Nested Class Summary
 class Selector.AccessException
          Exception thrown when an attempt is made to invoke a method on a target such that the method is inaccessible on that target.
 class Selector.InvocationException
          Exception that wraps an exception thrown during invocation.
 class Selector.MethodNotFoundException
          Exception thrown when no method could be found matching a target to the method name and argument types.
 
Field Summary
protected  java.lang.Class[] _argumentTypes
          name of the method
protected  java.lang.String _methodName
           
 
Constructor Summary
Selector(java.lang.String methodName)
          Constructor for a method that takes no arguments
Selector(java.lang.String methodName, java.lang.Class argumentType)
          Constructor for a method that takes a single argument
Selector(java.lang.String methodName, java.lang.Class[] argumentTypes)
          Constructor for a method that takes multiple arguments
 
Method Summary
 java.lang.Object invoke(java.lang.Object target)
          Invoke a no argument method on the target
 java.lang.Object invoke(java.lang.Object target, java.lang.Object argument)
          Invoke a single argument method on the target.
 java.lang.Object invoke(java.lang.Object target, java.lang.Object[] arguments)
          Invoke a mulit-argument method on the target.
static java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Class[] argumentTypes, java.lang.Object target, java.lang.Object[] arguments)
          Invoke a multi-argument method on the target.
static java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Class argumentType, java.lang.Object target, java.lang.Object argument)
          Invoke a single argument method on the target.
static java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object target)
          Invoke a no argument method on the target.
 boolean invokesOn(java.lang.Object target)
          Test if the target will respond to the selector
 boolean invokesStaticOn(java.lang.Class targetClass)
          Test if the target will respond to the selector
 java.lang.Object invokeStatic(java.lang.Class targetClass)
          Invoke the appropriate static method on the specified class
 java.lang.Object invokeStatic(java.lang.Class targetClass, java.lang.Object argument)
          Invoke the appropriate static method on the specified class
 java.lang.Object invokeStatic(java.lang.Class targetClass, java.lang.Object[] arguments)
          Invoke the appropriate static method on the specified class
static java.lang.Object invokeStaticMethod(java.lang.String methodName, java.lang.Class targetClass)
          Invoke the static method with the specified arguments on the specified target class
static java.lang.Object invokeStaticMethod(java.lang.String methodName, java.lang.Class[] argumentTypes, java.lang.Class targetClass, java.lang.Object[] arguments)
          Invoke the static method with the specified arguments on the specified target class
static java.lang.Object invokeStaticMethod(java.lang.String methodName, java.lang.Class argumentType, java.lang.Class targetClass, java.lang.Object argument)
          Invoke the static method with the specified arguments on the specified target class
 java.lang.reflect.Method methodForClass(java.lang.Class targetClass)
          Return a Method instance that binds the selector to a target class.
 java.lang.reflect.Method methodForObject(java.lang.Object target)
          Return a Method instance that binds the selector to a target object.
 java.lang.String methodName()
          Return the base name of the method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_methodName

protected java.lang.String _methodName

_argumentTypes

protected java.lang.Class[] _argumentTypes
name of the method

Constructor Detail

Selector

public Selector(java.lang.String methodName)
Constructor for a method that takes no arguments


Selector

public Selector(java.lang.String methodName,
                java.lang.Class argumentType)
Constructor for a method that takes a single argument


Selector

public Selector(java.lang.String methodName,
                java.lang.Class[] argumentTypes)
Constructor for a method that takes multiple arguments

Method Detail

methodName

public java.lang.String methodName()
Return the base name of the method


invokesOn

public boolean invokesOn(java.lang.Object target)
Test if the target will respond to the selector


invokesStaticOn

public boolean invokesStaticOn(java.lang.Class targetClass)
Test if the target will respond to the selector


invoke

public java.lang.Object invoke(java.lang.Object target)
                        throws java.lang.IllegalArgumentException,
                               Selector.AccessException,
                               Selector.InvocationException,
                               Selector.MethodNotFoundException
Invoke a no argument method on the target

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invoke

public java.lang.Object invoke(java.lang.Object target,
                               java.lang.Object argument)
                        throws java.lang.IllegalArgumentException,
                               Selector.AccessException,
                               Selector.InvocationException,
                               Selector.MethodNotFoundException
Invoke a single argument method on the target. The single argument should not be an array. If you need a single argument that is an array, you should use the multi-argument invoke method to avoid ambiguity.

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invoke

public java.lang.Object invoke(java.lang.Object target,
                               java.lang.Object[] arguments)
                        throws java.lang.IllegalArgumentException,
                               Selector.AccessException,
                               Selector.InvocationException,
                               Selector.MethodNotFoundException
Invoke a mulit-argument method on the target.

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeStatic

public java.lang.Object invokeStatic(java.lang.Class targetClass)
                              throws java.lang.IllegalArgumentException,
                                     Selector.AccessException,
                                     Selector.InvocationException,
                                     Selector.MethodNotFoundException
Invoke the appropriate static method on the specified class

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeStatic

public java.lang.Object invokeStatic(java.lang.Class targetClass,
                                     java.lang.Object argument)
                              throws java.lang.IllegalArgumentException,
                                     Selector.AccessException,
                                     Selector.InvocationException,
                                     Selector.MethodNotFoundException
Invoke the appropriate static method on the specified class

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeStatic

public java.lang.Object invokeStatic(java.lang.Class targetClass,
                                     java.lang.Object[] arguments)
                              throws java.lang.IllegalArgumentException,
                                     Selector.AccessException,
                                     Selector.InvocationException,
                                     Selector.MethodNotFoundException
Invoke the appropriate static method on the specified class

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeMethod

public static java.lang.Object invokeMethod(java.lang.String methodName,
                                            java.lang.Object target)
                                     throws java.lang.IllegalArgumentException,
                                            Selector.AccessException,
                                            Selector.InvocationException,
                                            Selector.MethodNotFoundException
Invoke a no argument method on the target. This is a convenience static method that creates an internal Selector on the fly.

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeMethod

public static java.lang.Object invokeMethod(java.lang.String methodName,
                                            java.lang.Class argumentType,
                                            java.lang.Object target,
                                            java.lang.Object argument)
                                     throws java.lang.IllegalArgumentException,
                                            Selector.AccessException,
                                            Selector.InvocationException,
                                            Selector.MethodNotFoundException
Invoke a single argument method on the target. This is a convenience static method that creates an internal Selector on the fly.

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeMethod

public static java.lang.Object invokeMethod(java.lang.String methodName,
                                            java.lang.Class[] argumentTypes,
                                            java.lang.Object target,
                                            java.lang.Object[] arguments)
                                     throws java.lang.IllegalArgumentException,
                                            Selector.AccessException,
                                            Selector.InvocationException,
                                            Selector.MethodNotFoundException
Invoke a multi-argument method on the target. This is a convenience static method that creates an internal Selector on the fly.

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeStaticMethod

public static java.lang.Object invokeStaticMethod(java.lang.String methodName,
                                                  java.lang.Class[] argumentTypes,
                                                  java.lang.Class targetClass,
                                                  java.lang.Object[] arguments)
                                           throws java.lang.IllegalArgumentException,
                                                  Selector.AccessException,
                                                  Selector.InvocationException,
                                                  Selector.MethodNotFoundException
Invoke the static method with the specified arguments on the specified target class

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeStaticMethod

public static java.lang.Object invokeStaticMethod(java.lang.String methodName,
                                                  java.lang.Class argumentType,
                                                  java.lang.Class targetClass,
                                                  java.lang.Object argument)
                                           throws java.lang.IllegalArgumentException,
                                                  Selector.AccessException,
                                                  Selector.InvocationException,
                                                  Selector.MethodNotFoundException
Invoke the static method with the specified arguments on the specified target class

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

invokeStaticMethod

public static java.lang.Object invokeStaticMethod(java.lang.String methodName,
                                                  java.lang.Class targetClass)
                                           throws java.lang.IllegalArgumentException,
                                                  Selector.AccessException,
                                                  Selector.InvocationException,
                                                  Selector.MethodNotFoundException
Invoke the static method with the specified arguments on the specified target class

java.lang.IllegalArgumentException
Selector.AccessException
Selector.InvocationException
Selector.MethodNotFoundException

methodForClass

public java.lang.reflect.Method methodForClass(java.lang.Class targetClass)
                                        throws Selector.MethodNotFoundException,
                                               java.lang.SecurityException
Return a Method instance that binds the selector to a target class.

Selector.MethodNotFoundException
java.lang.SecurityException

methodForObject

public java.lang.reflect.Method methodForObject(java.lang.Object target)
                                         throws Selector.MethodNotFoundException,
                                                java.lang.SecurityException
Return a Method instance that binds the selector to a target object.

Selector.MethodNotFoundException
java.lang.SecurityException