Usage: Specify "targetClass"/"targetMethod" or "targetObject"/"targetMethod", optionally specify arguments, prepare the invoker. Afterwards, you may invoke the method any number of times, obtaining the invocation result.
prepare, invoke
| Modifier and Type | Field and Description |
|---|---|
| private Object[] | |
| private static final Object[] | |
| private Method | methodObject
The method we will call. |
| private String | |
| protected Class | |
| private String | |
| private Object |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Method | Returns: a matching method, ornull if noneFind a matching method with the specified name for the specified arguments. |
| public Object[] | |
| public Method | Returns: the prepared Method object (nevernull)Return the prepared Method object that will be invoked. |
| public Class | |
| public String | |
| public Object | |
| public static int | Returns: the accumulated weight for all argumentsthe parameter types to match paramTypes, Object[] the arguments to match args)Algorithm that judges the match between the declared parameter types of a candidate method and a specific list of arguments that this method is supposed to be invoked with. |
| public Object | Returns: the object (possibly null) returned by the method invocation, ornull if the method has a void return typeInvoke the specified method. |
| public boolean | isPrepared()
Return whether this invoker has been prepared already,
i.e. whether it allows access to |
| public void | |
| protected Class | Returns: the resolved Classthe class name to resolve className)Resolve the given class name into a Class. |
| public void | |
| public void | setStaticMethod(String staticMethod)
Set a fully qualified static method name to invoke, e.g. "example.MyExampleClass.myExampleMethod". |
| public void | |
| public void | |
| public void |
| arguments | back to summary |
|---|---|
| private Object[] arguments
| |
| EMPTY_ARGUMENTS | back to summary |
|---|---|
| private static final Object[] EMPTY_ARGUMENTS | |
| methodObject | back to summary |
|---|---|
| private Method methodObject The method we will call. | |
| staticMethod | back to summary |
|---|---|
| private String staticMethod
| |
| targetClass | back to summary |
|---|---|
| protected Class<?> targetClass
| |
| targetMethod | back to summary |
|---|---|
| private String targetMethod
| |
| targetObject | back to summary |
|---|---|
| private Object targetObject
| |
| MethodInvoker | back to summary |
|---|---|
| public MethodInvoker() | |
| findMatchingMethod | back to summary |
|---|---|
| protected Method findMatchingMethod() Find a matching method with the specified name for the specified arguments.
| |
| getArguments | back to summary |
|---|---|
| public Object[] getArguments() Return the arguments for the method invocation. | |
| getPreparedMethod | back to summary |
|---|---|
| public Method getPreparedMethod() throws IllegalStateException Return the prepared Method object that will be invoked. Can for example be used to determine the return type.
| |
| getTargetClass | back to summary |
|---|---|
| public Class Return the target class on which to call the target method.
| |
| getTargetMethod | back to summary |
|---|---|
| public String getTargetMethod() Return the name of the method to be invoked.
| |
| getTargetObject | back to summary |
|---|---|
| public Object getTargetObject() Return the target object on which to call the target method.
| |
| getTypeDifferenceWeight | back to summary |
|---|---|
| public static int getTypeDifferenceWeight(Class<?>[] paramTypes, Object[] args) Algorithm that judges the match between the declared parameter types of a candidate method and a specific list of arguments that this method is supposed to be invoked with. Determines a weight that represents the class hierarchy difference between types and arguments. A direct match, i.e. type Integer → arg of class Integer, does not increase the result - all direct matches means weight 0. A match between type Object and arg of class Integer would increase the weight by 2, due to the superclass 2 steps up in the hierarchy (i.e. Object) being the last one that still matches the required type Object. Type Number and class Integer would increase the weight by 1 accordingly, due to the superclass 1 step up the hierarchy (i.e. Number) still matching the required type Number. Therefore, with an arg of type Integer, a constructor (Integer) would be preferred to a constructor (Number) which would in turn be preferred to a constructor (Object). All argument weights get accumulated. Note This is the algorithm used by MethodInvoker itself and also the algorithm used for constructor and factory method selection in Spring's bean container (in case of lenient constructor resolution which is the default for regular bean definitions). | |
| invoke | back to summary |
|---|---|
| public Object invoke() throws InvocationTargetException, IllegalAccessException Invoke the specified method. The invoker needs to have been prepared before.
| |
| isPrepared | back to summary |
|---|---|
| public boolean isPrepared() Return whether this invoker has been prepared already,
i.e. whether it allows access to | |
| prepare | back to summary |
|---|---|
| public void prepare() throws ClassNotFoundException, NoSuchMethodException Prepare the specified method. The method can be invoked any number of times afterwards.
| |
| resolveClassName | back to summary |
|---|---|
| protected Class Resolve the given class name into a Class. The default implementations uses
| |
| setArguments | back to summary |
|---|---|
| public void setArguments(Object... arguments) Set arguments for the method invocation. If this property is not set, or the Object array is of length 0, a method with no arguments is assumed. | |
| setStaticMethod | back to summary |
|---|---|
| public void setStaticMethod(String staticMethod) Set a fully qualified static method name to invoke, e.g. "example.MyExampleClass.myExampleMethod". This is a convenient alternative to specifying targetClass and targetMethod.
| |
| setTargetClass | back to summary |
|---|---|
| public void setTargetClass(Class<?> targetClass) Set the target class on which to call the target method. Only necessary when the target method is static; else, a target object needs to be specified anyway.
| |
| setTargetMethod | back to summary |
|---|---|
| public void setTargetMethod(String targetMethod) Set the name of the method to be invoked. Refers to either a static method or a non-static method, depending on a target object being set.
| |
| setTargetObject | back to summary |
|---|---|
| public void setTargetObject(Object targetObject) Set the target object on which to call the target method. Only necessary when the target method is not static; else, a target class is sufficient.
| |