messif.executor
Class MethodClassExecutor

java.lang.Object
  extended by messif.executor.MethodExecutor
      extended by messif.executor.MethodClassExecutor

public class MethodClassExecutor
extends MethodExecutor

This class allows to execute a methods on a specified object. First, methods must be registered. This is done through constructor, where also an instance of the target object must be provided. The second parameter specify the required argument types that the method must have. One argument is specified as a super class of the actual parameter (this argument class is then used to distinguish between the executed methods), the other arguments must be either of the same class as the method's one or its subclasses. This item is marked by the third constructor argument. Then the method execute method can be called. This method invokes the method of the instance (provided in constructor), which is appropriate for the provided arguments. Method backgroundExecute can be called to invoke the method in a new thread. A returned thread can be used for wait calls to test, whether the execution has finished and also to retrieve the data.


Nested Class Summary
 
Nested classes/interfaces inherited from class messif.executor.MethodExecutor
MethodExecutor.ExecutableMethod
 
Field Summary
protected  int differentiateByArgNo
          Index of the argument in the method prototype, which is used to distinguish between the methods
protected  java.util.Map<java.lang.Class<?>,java.lang.reflect.Method> registeredMethods
          The table of found operation methods
 
Fields inherited from class messif.executor.MethodExecutor
executionObject
 
Constructor Summary
MethodClassExecutor(java.lang.Object executionObject, java.lang.Class<?>... methodPrototype)
          Create new instance of MethodExecutor and search for operation methods.
MethodClassExecutor(java.lang.Object executionObject, java.lang.Class<?> inheritedMethods, java.lang.Class<?>... methodPrototype)
          Create new instance of MethodExecutor and search for operation methods.
MethodClassExecutor(java.lang.Object executionObject, int differentiateByArgNo, java.lang.Class<?>... methodPrototype)
          Create new instance of MethodExecutor and search for operation methods.
MethodClassExecutor(java.lang.Object executionObject, int differentiateByArgNo, java.lang.String methodNames, java.lang.Class<?>... methodPrototype)
          Create new instance of MethodClassExecutor and search for operation methods Public methods from the whole object's hierarchy are executed.
MethodClassExecutor(java.lang.Object executionObject, int differentiateByArgNo, java.lang.String methodNames, int modifiers, java.lang.Class<?> inheritedMethods, java.lang.Class<?>... methodPrototype)
          Create new instance of MethodClassExecutor and search for operation methods
MethodClassExecutor(java.lang.Object executionObject, java.lang.String methodNames, java.lang.Class<?>... methodPrototype)
          Create new instance of MethodExecutor and search for operation methods.
 
Method Summary
protected static java.util.Collection<java.lang.reflect.Method> getClassMethods(java.lang.Class<?> readClass, int modifiers, java.lang.Class<?> readSuperclass)
          Returns all methods from the specified class that have the modifiers.
<E> java.util.List<java.lang.Class<? extends E>>
getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch)
          Returns the list of classes that this executor recognizes and can execute their associated method.
<E> java.util.List<java.lang.Class<? extends E>>
getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch, int modifiers)
          Returns the list of classes that this executor recognizes and can execute their associated method.
protected  java.lang.reflect.Method getMethod(java.lang.Class<?> key, boolean trySuperClasses)
          Returns the stored method according to the the specified class.
protected  java.lang.reflect.Method getMethod(java.lang.Object[] arguments)
          Returns a proper execution method for provided arguments.
protected  java.util.Collection<java.lang.reflect.Method> getRegisteredMethods()
          Returns the list of classes that this executor recognizes and can execute their associated method.
 
Methods inherited from class messif.executor.MethodExecutor
backgroundExecute, backgroundExecute, backgroundExecute, execute, execute, printUsage, printUsage, printUsage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registeredMethods

protected transient java.util.Map<java.lang.Class<?>,java.lang.reflect.Method> registeredMethods
The table of found operation methods


differentiateByArgNo

protected final int differentiateByArgNo
Index of the argument in the method prototype, which is used to distinguish between the methods

Constructor Detail

MethodClassExecutor

public MethodClassExecutor(java.lang.Object executionObject,
                           int differentiateByArgNo,
                           java.lang.String methodNames,
                           int modifiers,
                           java.lang.Class<?> inheritedMethods,
                           java.lang.Class<?>... methodPrototype)
                    throws java.lang.IllegalArgumentException
Create new instance of MethodClassExecutor and search for operation methods

Parameters:
executionObject - an instance of the object to execute the operations on
differentiateByArgNo - the index of an argument from methodPrototype, which will destinguish the methods
methodNames - the name which all the methods must match
modifiers - specify or'ed values of Modifier that the method must have set
inheritedMethods - if null only methods declared in the executionObject are loaded. Otherwise, methods from all superclasses up to class inheritedMethods exclusive are loaded.
methodPrototype - list of argument types for the registered methods
Throws:
java.lang.IllegalArgumentException - if either the method prototype or differentiating argument index is invalid or the executionObject is null

MethodClassExecutor

public MethodClassExecutor(java.lang.Object executionObject,
                           int differentiateByArgNo,
                           java.lang.String methodNames,
                           java.lang.Class<?>... methodPrototype)
                    throws java.lang.IllegalArgumentException
Create new instance of MethodClassExecutor and search for operation methods Public methods from the whole object's hierarchy are executed.

Parameters:
executionObject - an instance of the object to execute the operations on
differentiateByArgNo - the index of an argument from methodPrototype, which will destinguish the methods
methodNames - the name which all the methods must match
methodPrototype - list of argument types for the registered methods
Throws:
java.lang.IllegalArgumentException - if the differentiating argument index is invalid or the executionObject is null

MethodClassExecutor

public MethodClassExecutor(java.lang.Object executionObject,
                           java.lang.Class<?> inheritedMethods,
                           java.lang.Class<?>... methodPrototype)
                    throws java.lang.IllegalArgumentException
Create new instance of MethodExecutor and search for operation methods. The first argument is selected as the differentiator. Public methods from the whole object's hierarchy are executed.

Parameters:
executionObject - an instance of the object to execute the operations on
inheritedMethods - if null only methods declared in the executionObject are loaded. Otherwise, methods from all superclasses up to class inheritedMethods exclusive are loaded.
methodPrototype - list of argument types for the registered methods
Throws:
java.lang.IllegalArgumentException - if the method prototype has no arguments or the executionObject is null

MethodClassExecutor

public MethodClassExecutor(java.lang.Object executionObject,
                           java.lang.Class<?>... methodPrototype)
                    throws java.lang.IllegalArgumentException
Create new instance of MethodExecutor and search for operation methods. The first argument is selected as the differentiator. Public methods from the whole object's hierarchy are executed.

Parameters:
executionObject - an instance of the object to execute the operations on
methodPrototype - list of argument types for the registered methods
Throws:
java.lang.IllegalArgumentException - if the method prototype has no arguments or the executionObject is null

MethodClassExecutor

public MethodClassExecutor(java.lang.Object executionObject,
                           int differentiateByArgNo,
                           java.lang.Class<?>... methodPrototype)
                    throws java.lang.IllegalArgumentException
Create new instance of MethodExecutor and search for operation methods. The first argument is selected as the differentiator. Public methods from the whole object's hierarchy are executed.

Parameters:
executionObject - an instance of the object to execute the operations on
differentiateByArgNo - the index of an argument from methodPrototype, which will destinguish the methods
methodPrototype - list of argument types for the registered methods
Throws:
java.lang.IllegalArgumentException - if the differentiating argument index is invalid or the executionObject is null

MethodClassExecutor

public MethodClassExecutor(java.lang.Object executionObject,
                           java.lang.String methodNames,
                           java.lang.Class<?>... methodPrototype)
                    throws java.lang.IllegalArgumentException
Create new instance of MethodExecutor and search for operation methods. The first argument is selected as the differentiator. Public methods from the whole object's hierarchy are executed.

Parameters:
executionObject - an instance of the object to execute the operations on
methodNames - the name which all the methods must match
methodPrototype - list of argument types for the registered methods
Throws:
java.lang.IllegalArgumentException - if the method prototype has no arguments or the executionObject is null
Method Detail

getClassMethods

protected static java.util.Collection<java.lang.reflect.Method> getClassMethods(java.lang.Class<?> readClass,
                                                                                int modifiers,
                                                                                java.lang.Class<?> readSuperclass)
Returns all methods from the specified class that have the modifiers.

Parameters:
readClass - the class for which the methods are read
modifiers - or'ed together (see Modifier for their list). All set modifiers must be present for a specific method except for the access modifiers. For example, value Modifier.PROTECTED | Modifier.PUBLIC | Modifier.TRANSIENT | Modifier.FINAL matches all final transient methods that are either public or protected.
readSuperclass - methods from all subclasses (up to readSuperclass) are also returned, otherwise, only methods declared in the readClass are checked
Returns:
all methods from the specified class that have the modifiers

getMethod

protected java.lang.reflect.Method getMethod(java.lang.Class<?> key,
                                             boolean trySuperClasses)
Returns the stored method according to the the specified class.

Parameters:
key - the differentiating class from method prototype
trySuperClasses - check all superclasses of the key if a direct match was not found
Returns:
the stored method according to the the specified class

getMethod

protected java.lang.reflect.Method getMethod(java.lang.Object[] arguments)
                                      throws java.lang.NoSuchMethodException
Returns a proper execution method for provided arguments. The key for the search is the class of the differentiateByArgNo-th object from the arguments parameter.

Specified by:
getMethod in class MethodExecutor
Parameters:
arguments - the arguments of the execution method we are looking for
Returns:
proper execution method for provided arguments
Throws:
java.lang.NoSuchMethodException - if there was no method for the specified arguments

getDifferentiatingClasses

public <E> java.util.List<java.lang.Class<? extends E>> getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch,
                                                                                  int modifiers)
Returns the list of classes that this executor recognizes and can execute their associated method. This method is typically used to return the list of supported arguments. Only the specified subclasses are returned.

Type Parameters:
E - the super-class of the returned classes
Parameters:
subclassesToSearch - a filter the list to contain only the subclasses of this parameter
modifiers - or'ed together (see Modifier for their list). All set modifiers must be present for a specific method except for the access modifiers. For example, value Modifier.PROTECTED | Modifier.PUBLIC | Modifier.TRANSIENT | Modifier.FINAL matches all final transient methods that are either public or protected.
Returns:
the list of classes that this executor recognizes

getDifferentiatingClasses

public <E> java.util.List<java.lang.Class<? extends E>> getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch)
Returns the list of classes that this executor recognizes and can execute their associated method. This method is typically used to return the list of supported arguments. Only the specified subclasses that have public method are returned.

Type Parameters:
E - the super-class of the returned classes
Parameters:
subclassesToSearch - a filter the list to contain only the subclasses of this parameter
Returns:
the list of classes that this executor recognizes

getRegisteredMethods

protected java.util.Collection<java.lang.reflect.Method> getRegisteredMethods()
Returns the list of classes that this executor recognizes and can execute their associated method. This method is typically used to return the list of supported arguments.

Specified by:
getRegisteredMethods in class MethodExecutor
Returns:
the list of classes that this executor recognizes