Class SingleArgumentAnnotatedMethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>
- java.lang.Object
-
- dk.cloudcreate.essentials.shared.reflection.invocation.SingleArgumentAnnotatedMethodPatternMatcher<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.
public class SingleArgumentAnnotatedMethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE> extends Object
A strategy that matches methods annotated withmatchOnMethodsAnnotatedWithand have a single method argument that is the same type or a sub-type of theARGUMENT_COMMON_ROOT_TYPE
Example using parameterized types:
Example using non-parameterized types:var patternMatchingInvoker = new PatternMatchingMethodInvoker<>(invokeMethodsOn, new SingleArgumentAnnotatedMethodPatternMatcher<>(EventHandler.class, new GenericType<Event<OrderId>>() {}), InvocationStrategy.InvokeMostSpecificTypeMatched);var patternMatchingInvoker = new PatternMatchingMethodInvoker<>(invokeMethodsOn, new SingleArgumentAnnotatedMethodPatternMatcher<>(EventHandler.class, OrderEvent.class, InvocationStrategy.InvokeMostSpecificTypeMatched);
-
-
Constructor Summary
Constructors Constructor Description SingleArgumentAnnotatedMethodPatternMatcher(Class<? extends Annotation> matchOnMethodsAnnotatedWith, GenericType<ARGUMENT_COMMON_ROOT_TYPE> argumentCommonRootType)Create a new strategy that matches methods annotated withmatchOnMethodsAnnotatedWithand have a single method argument that is the same type or a sub-type of theARGUMENT_COMMON_ROOT_TYPESingleArgumentAnnotatedMethodPatternMatcher(Class<? extends Annotation> matchOnMethodsAnnotatedWith, Class<ARGUMENT_COMMON_ROOT_TYPE> argumentCommonRootType)Create a new strategy that matches methods annotated withmatchOnMethodsAnnotatedWithand have a single method argument that is the same type or a sub-type of theARGUMENT_COMMON_ROOT_TYPE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinvokeMethod(Method methodToInvoke, Object argument, Object invokeMethodOn, Class<?> resolvedInvokeMethodWithArgumentOfType)booleanisInvokableMethod(Method candidateMethod)Class<?>resolveInvocationArgumentTypeFromMethodDefinition(Method method)Class<?>resolveInvocationArgumentTypeFromObject(Object argument)
-
-
-
Constructor Detail
-
SingleArgumentAnnotatedMethodPatternMatcher
public SingleArgumentAnnotatedMethodPatternMatcher(Class<? extends Annotation> matchOnMethodsAnnotatedWith, Class<ARGUMENT_COMMON_ROOT_TYPE> argumentCommonRootType)
Create a new strategy that matches methods annotated withmatchOnMethodsAnnotatedWithand have a single method argument that is the same type or a sub-type of theARGUMENT_COMMON_ROOT_TYPE- Parameters:
matchOnMethodsAnnotatedWith- the annotation that invokable methods are annotated withargumentCommonRootType- the base type for the single method argument
-
SingleArgumentAnnotatedMethodPatternMatcher
public SingleArgumentAnnotatedMethodPatternMatcher(Class<? extends Annotation> matchOnMethodsAnnotatedWith, GenericType<ARGUMENT_COMMON_ROOT_TYPE> argumentCommonRootType)
Create a new strategy that matches methods annotated withmatchOnMethodsAnnotatedWithand have a single method argument that is the same type or a sub-type of theARGUMENT_COMMON_ROOT_TYPE- Parameters:
matchOnMethodsAnnotatedWith- the annotation that invokable methods are annotated withargumentCommonRootType- the base type for the single method argument
-
-
Method Detail
-
isInvokableMethod
public boolean isInvokableMethod(Method candidateMethod)
-
resolveInvocationArgumentTypeFromMethodDefinition
public Class<?> resolveInvocationArgumentTypeFromMethodDefinition(Method method)
-
resolveInvocationArgumentTypeFromObject
public Class<?> resolveInvocationArgumentTypeFromObject(Object argument)
-
-