|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.executor.MethodExecutor
messif.executor.MethodClassExecutor
public class MethodClassExecutor
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. |
|
|
getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch)
Returns the list of classes that this executor recognizes and can execute their associated method. |
|
|
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 |
---|
protected transient java.util.Map<java.lang.Class<?>,java.lang.reflect.Method> registeredMethods
protected final int differentiateByArgNo
Constructor Detail |
---|
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
executionObject
- an instance of the object to execute the operations ondifferentiateByArgNo
- the index of an argument from methodPrototype, which will destinguish the methodsmethodNames
- the name which all the methods must matchmodifiers
- specify or'ed values of Modifier
that the method must have setinheritedMethods
- 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
java.lang.IllegalArgumentException
- if either the method prototype or differentiating argument index is invalid or the executionObject is nullpublic MethodClassExecutor(java.lang.Object executionObject, int differentiateByArgNo, java.lang.String methodNames, java.lang.Class<?>... methodPrototype) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations ondifferentiateByArgNo
- the index of an argument from methodPrototype, which will destinguish the methodsmethodNames
- the name which all the methods must matchmethodPrototype
- list of argument types for the registered methods
java.lang.IllegalArgumentException
- if the differentiating argument index is invalid or the executionObject is nullpublic MethodClassExecutor(java.lang.Object executionObject, java.lang.Class<?> inheritedMethods, java.lang.Class<?>... methodPrototype) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations oninheritedMethods
- 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
java.lang.IllegalArgumentException
- if the method prototype has no arguments or the executionObject is nullpublic MethodClassExecutor(java.lang.Object executionObject, java.lang.Class<?>... methodPrototype) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations onmethodPrototype
- list of argument types for the registered methods
java.lang.IllegalArgumentException
- if the method prototype has no arguments or the executionObject is nullpublic MethodClassExecutor(java.lang.Object executionObject, int differentiateByArgNo, java.lang.Class<?>... methodPrototype) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations ondifferentiateByArgNo
- the index of an argument from methodPrototype, which will destinguish the methodsmethodPrototype
- list of argument types for the registered methods
java.lang.IllegalArgumentException
- if the differentiating argument index is invalid or the executionObject is nullpublic MethodClassExecutor(java.lang.Object executionObject, java.lang.String methodNames, java.lang.Class<?>... methodPrototype) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations onmethodNames
- the name which all the methods must matchmethodPrototype
- list of argument types for the registered methods
java.lang.IllegalArgumentException
- if the method prototype has no arguments or the executionObject is nullMethod Detail |
---|
protected static java.util.Collection<java.lang.reflect.Method> getClassMethods(java.lang.Class<?> readClass, int modifiers, java.lang.Class<?> readSuperclass)
readClass
- the class for which the methods are readmodifiers
- 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
protected java.lang.reflect.Method getMethod(java.lang.Class<?> key, boolean trySuperClasses)
key
- the differentiating class from method prototypetrySuperClasses
- check all superclasses of the key if a direct match was not found
protected java.lang.reflect.Method getMethod(java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
getMethod
in class MethodExecutor
arguments
- the arguments of the execution method we are looking for
java.lang.NoSuchMethodException
- if there was no method for the specified argumentspublic <E> java.util.List<java.lang.Class<? extends E>> getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch, int modifiers)
E
- the super-class of the returned classessubclassesToSearch
- a filter the list to contain only the subclasses of this parametermodifiers
- 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.
public <E> java.util.List<java.lang.Class<? extends E>> getDifferentiatingClasses(java.lang.Class<? extends E> subclassesToSearch)
E
- the super-class of the returned classessubclassesToSearch
- a filter the list to contain only the subclasses of this parameter
protected java.util.Collection<java.lang.reflect.Method> getRegisteredMethods()
getRegisteredMethods
in class MethodExecutor
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |