Interface MethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>
-
- Type Parameters:
ARGUMENT_COMMON_ROOT_TYPE- The method argument common root type (i.e. a common superclass or common interface) for the argument-type that we're performing pattern matching on.
If there isn't a common root type, then you can specifyObjectinsteadExample: Within a single class we have placed a set methods that can handle
OrderEvent's, such asOrderCreated, OrderShipped, OrderAccepted, etc.
In this caseOrderEventwill be ourARGUMENT_ROOT_TYPEas it forms the root of the type hierarchy.
- All Known Implementing Classes:
SingleArgumentAnnotatedMethodPatternMatcher
public interface MethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>Strategy interface that determines the mechanics of which methods are candidates for matching, what type a given method supports and how the method is invoked
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidinvokeMethod(Method methodToInvoke, Object argument, Object invokeMethodOn, Class<?> resolvedInvokeMethodWithArgumentOfType)This method is responsible for calling themethodToInvokeon theinvokeMethodOnObjectobject using the right parameters based on thewithObject.
For simple cases the argument will only be thewithObject, where it for other cases may involve extracting the real object to pass onto themethodToInvokefrom within thewithObject(e.g.booleanisInvokableMethod(Method candidateMethod)Determines if a candidateMethod is a candidate for being invoked byPatternMatchingMethodInvokerClass<?>resolveInvocationArgumentTypeFromMethodDefinition(Method method)Returns the (single) type this method can be invoked with.Class<?>resolveInvocationArgumentTypeFromObject(Object argument)Resolves which type should be used for looking up matching invokable methods
In simple cases this will be the same type as theargument's, but for enveloped types (such as Messages that encapsulate a payload) we may want to match methods against the message' payload type instead of the message type
-
-
-
Method Detail
-
isInvokableMethod
boolean isInvokableMethod(Method candidateMethod)
Determines if a candidateMethod is a candidate for being invoked byPatternMatchingMethodInvoker- Parameters:
candidateMethod- the candidate method to test for invocation- Returns:
- true if the candidateMethod is invokable, otherwise false
-
resolveInvocationArgumentTypeFromMethodDefinition
Class<?> resolveInvocationArgumentTypeFromMethodDefinition(Method method)
Returns the (single) type this method can be invoked with. This method MUST return the type supported OR throw aRuntimeExceptionin case the method doesn't allow resolving a type- Parameters:
method- the method to resolve the invokeWithObject type (requirement the method has passed theisInvokableMethod(Method)test)- Returns:
- The type supported
-
resolveInvocationArgumentTypeFromObject
Class<?> resolveInvocationArgumentTypeFromObject(Object argument)
Resolves which type should be used for looking up matching invokable methods
In simple cases this will be the same type as theargument's, but for enveloped types (such as Messages that encapsulate a payload) we may want to match methods against the message' payload type instead of the message type- Parameters:
argument- the argument instance- Returns:
- the type that should be used for looking up matching invokable methods
-
invokeMethod
void invokeMethod(Method methodToInvoke, Object argument, Object invokeMethodOn, Class<?> resolvedInvokeMethodWithArgumentOfType) throws Exception
This method is responsible for calling themethodToInvokeon theinvokeMethodOnObjectobject using the right parameters based on thewithObject.
For simple cases the argument will only be thewithObject, where it for other cases may involve extracting the real object to pass onto themethodToInvokefrom within thewithObject(e.g. in case of a wrapped type, such as a message object that contains the real payload to supply to themethodToInvoke)- Parameters:
methodToInvoke- the method that must be reflectively invoked. You can assume that the method is Acessible alreadyargument- The argument instance passed toPatternMatchingMethodInvoker.invoke(Object)/PatternMatchingMethodInvoker.invoke(Object, NoMatchingMethodsHandler)and which was used in the call toresolveInvocationArgumentTypeFromObject(Object)
In simple cases this will be the same type as theargument's, but for enveloped types (such as Messages that encapsulate a payload) we may want to match methods against the message' payload type instead of the message type.invokeMethodOn- the object that themethodToInvokemust be invoked on (the target object of theMethod.invoke(Object, Object...))resolvedInvokeMethodWithArgumentOfType- The resolved withObjectType (as resolved byresolveInvocationArgumentTypeFromObject(Object))- Throws:
Exception- Feel free to throw any Reflection exceptions, etc.
ThePatternMatchingMethodInvokerwill ensure to either unwrap the real cause or wrap any checked exceptions in a Runtime exception.
-
-