Package xal.tools.reflect
Class Selector
java.lang.Object
xal.tools.reflect.Selector
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.
- Author:
- tap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Exception thrown when an attempt is made to invoke a method on a target such that the method is inaccessible on that target.static class
Exception that wraps an exception thrown during invocation.static class
Exception thrown when no method could be found matching a target to the method name and argument types. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInvoke a no argument method on the targetInvoke a single argument method on the target.Invoke a multi-argument method on the target.static Object
invokeMethod
(String methodName, Class<?>[] argumentTypes, Object target, Object[] arguments) Invoke a multi-argument method on the target.static Object
invokeMethod
(String methodName, Class<?> argumentType, Object target, Object argument) Invoke a single argument method on the target.static Object
invokeMethod
(String methodName, Object target) Invoke a no argument method on the target.boolean
Test if the target will respond to the selector<T> boolean
invokesStaticOn
(Class<T> targetClass) Test if the target will respond to the selector<T> Object
invokeStatic
(Class<T> targetClass) Invoke the appropriate static method on the specified class<T> Object
invokeStatic
(Class<T> targetClass, Object argument) Invoke the appropriate static method on the specified class<T> Object
invokeStatic
(Class<T> targetClass, Object[] arguments) Invoke the appropriate static method on the specified classstatic <T> Object
invokeStaticMethod
(String methodName, Class<?>[] argumentTypes, Class<T> targetClass, Object[] arguments) Invoke the static method with the specified arguments on the specified target classstatic <T> Object
invokeStaticMethod
(String methodName, Class<?> argumentType, Class<T> targetClass, Object argument) Invoke the static method with the specified arguments on the specified target classstatic <T> Object
invokeStaticMethod
(String methodName, Class<T> targetClass) Invoke the static method with the specified arguments on the specified target class<T> Method
methodForClass
(Class<T> targetClass) Return a Method instance that binds the selector to a target class.methodForObject
(Object target) Return a Method instance that binds the selector to a target object.Return the base name of the method
-
Field Details
-
methodName
name of the method -
argumentTypes
argument classes
-
-
Constructor Details
-
Selector
Constructor for a method that takes multiple arguments
-
-
Method Details
-
methodName
Return the base name of the method -
invokesOn
Test if the target will respond to the selector -
invokesStaticOn
Test if the target will respond to the selector -
invoke
public Object invoke(Object target) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke a no argument method on the target -
invoke
public Object invoke(Object target, Object argument) throws 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. -
invoke
public Object invoke(Object target, Object[] arguments) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke a multi-argument method on the target. -
invokeStatic
public <T> Object invokeStatic(Class<T> targetClass) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke the appropriate static method on the specified class -
invokeStatic
public <T> Object invokeStatic(Class<T> targetClass, Object argument) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke the appropriate static method on the specified class -
invokeStatic
public <T> Object invokeStatic(Class<T> targetClass, Object[] arguments) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke the appropriate static method on the specified class -
invokeMethod
public static Object invokeMethod(String methodName, Object target) throws 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. -
invokeMethod
public static Object invokeMethod(String methodName, Class<?> argumentType, Object target, Object argument) throws 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. -
invokeMethod
public static Object invokeMethod(String methodName, Class<?>[] argumentTypes, Object target, Object[] arguments) throws 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. -
invokeStaticMethod
public static <T> Object invokeStaticMethod(String methodName, Class<?>[] argumentTypes, Class<T> targetClass, Object[] arguments) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke the static method with the specified arguments on the specified target class -
invokeStaticMethod
public static <T> Object invokeStaticMethod(String methodName, Class<?> argumentType, Class<T> targetClass, Object argument) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke the static method with the specified arguments on the specified target class -
invokeStaticMethod
public static <T> Object invokeStaticMethod(String methodName, Class<T> targetClass) throws IllegalArgumentException, Selector.AccessException, Selector.InvocationException, Selector.MethodNotFoundException Invoke the static method with the specified arguments on the specified target class -
methodForClass
public <T> Method methodForClass(Class<T> targetClass) throws Selector.MethodNotFoundException, SecurityException Return a Method instance that binds the selector to a target class. -
methodForObject
public Method methodForObject(Object target) throws Selector.MethodNotFoundException, SecurityException Return a Method instance that binds the selector to a target object.
-