Package enterprises.iwakura.sigewine.aop
Class MethodWrapper<T extends Annotation>
java.lang.Object
enterprises.iwakura.sigewine.aop.MethodWrapper<T>
- Type Parameters:
T- The type of the annotation that this wrapper handles
A wrapper for methods that are annotated with a specific annotation.
This class provides a way to handle method invocations before and after they are executed,
allowing for custom behavior based on the annotation.
-
Constructor Summary
ConstructorsConstructorDescriptionMethodWrapper(Class<T> annotationClass) Constructor that initializes the wrapper with the specified annotation class. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidafterInvocation(Object target, Method method, Object[] args, T annotation, Optional<Object> optionalResult, Optional<Throwable> optionalThrowable, Object proxy) Method to be called after the annotated method is invoked.protected abstract voidMethod to be called before the annotated method is invoked.getAnnotatedMethods(Object target) Gets all methods that are affected by this method wrapper.
-
Constructor Details
-
MethodWrapper
Constructor that initializes the wrapper with the specified annotation class.- Parameters:
annotationClass- The class of the annotation that this wrapper handles
-
-
Method Details
-
beforeInvocation
protected abstract void beforeInvocation(Object target, Method method, Object[] args, T annotation, Object proxy) Method to be called before the annotated method is invoked.- Parameters:
target- The target object on which the method is invokedmethod- The method that is being invokedargs- The arguments passed to the methodannotation- The annotation instance that is present on the methodproxy- The proxy object that is used to invoke the method
-
afterInvocation
protected abstract void afterInvocation(Object target, Method method, Object[] args, T annotation, Optional<Object> optionalResult, Optional<Throwable> optionalThrowable, Object proxy) Method to be called after the annotated method is invoked. This is called regardless of whether the method throws an exception or not.- Parameters:
target- The target object on which the method was invokedmethod- Method that was invokedargs- Arguments passed to the methodannotation- The annotation instance that is present on the methodoptionalResult- Optional result of the method invocation, if anyoptionalThrowable- Optional throwable that was thrown during the method invocation, if anyproxy- The proxy object that was used to invoke the method
-
getAnnotatedMethods
Gets all methods that are affected by this method wrapper.- Parameters:
target- The target object to get the methods from- Returns:
- A map of method names to annotations
-