Class MethodInvokerUtils
java.lang.Object
org.springframework.classify.util.MethodInvokerUtils
Utility methods to create
MethodInvoker
instances.- Since:
- 1.1
- Author:
- Lucas Ward, Artem Bilan
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MethodInvoker
getMethodInvokerByAnnotation
(Class<? extends Annotation> annotationType, Object target) CreateMethodInvoker
for the method with the provided annotation on the provided object.static MethodInvoker
getMethodInvokerByAnnotation
(Class<? extends Annotation> annotationType, Object target, Class<?>... expectedParamTypes) Create a MethodInvoker from the delegate based on the annotationType.static MethodInvoker
getMethodInvokerByName
(Object object, String methodName, boolean paramsRequired, Class<?>... paramTypes) Create aMethodInvoker
using the provided method name to search.static MethodInvoker
getMethodInvokerForInterface
(Class<?> cls, String methodName, Object object, Class<?>... paramTypes) Create aMethodInvoker
using the provided interface, and method name from that interface.static <C,
T> MethodInvoker Create aMethodInvoker
for the delegate from a single public method.static String
getParamTypesString
(Class<?>... paramTypes) Create a String representation of the array of parameter types.
-
Constructor Details
-
MethodInvokerUtils
public MethodInvokerUtils()
-
-
Method Details
-
getMethodInvokerByName
public static MethodInvoker getMethodInvokerByName(Object object, String methodName, boolean paramsRequired, Class<?>... paramTypes) Create aMethodInvoker
using the provided method name to search.- Parameters:
object
- to be invokedmethodName
- of the method to be invokedparamsRequired
- boolean indicating whether the parameters are required, if false, a no args version of the method will be searched for.paramTypes
- - parameter types of the method to search for.- Returns:
- MethodInvoker if the method is found, null if it is not.
-
getParamTypesString
Create a String representation of the array of parameter types.- Parameters:
paramTypes
- the types of parameters- Returns:
- the paramTypes as String representation
-
getMethodInvokerForInterface
public static MethodInvoker getMethodInvokerForInterface(Class<?> cls, String methodName, Object object, Class<?>... paramTypes) Create aMethodInvoker
using the provided interface, and method name from that interface.- Parameters:
cls
- the interface to search for the method namedmethodName
- of the method to be invokedobject
- to be invokedparamTypes
- - parameter types of the method to search for.- Returns:
- MethodInvoker if the method is found, null if it is not.
-
getMethodInvokerByAnnotation
public static MethodInvoker getMethodInvokerByAnnotation(Class<? extends Annotation> annotationType, Object target, Class<?>... expectedParamTypes) Create a MethodInvoker from the delegate based on the annotationType. Ensure that the annotated method has a valid set of parameters.- Parameters:
annotationType
- the annotation to scan fortarget
- the target objectexpectedParamTypes
- the expected parameter types for the method- Returns:
- a MethodInvoker
-
getMethodInvokerByAnnotation
public static MethodInvoker getMethodInvokerByAnnotation(Class<? extends Annotation> annotationType, Object target) CreateMethodInvoker
for the method with the provided annotation on the provided object. Annotations that cannot be applied to methods (i.e. that aren't annotated with an element type of METHOD) will cause an exception to be thrown.- Parameters:
annotationType
- to be searched fortarget
- to be invoked- Returns:
- MethodInvoker for the provided annotation, null if none is found.
-
getMethodInvokerForSingleArgument
Create aMethodInvoker
for the delegate from a single public method.- Type Parameters:
T
- the tC
- the C- Parameters:
target
- an object to search for an appropriate method- Returns:
- a MethodInvoker that calls a method on the delegate
-