You can use AspectJ or use Google Guice, which brings your AOP.
An object that has a method annotated using the WaitCursor annotation must be entered using Guice.
You define your annotation
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface WaitCursor {}
You add a MethodInterceptor:
public class WaitCursorInterceptor implements MethodInterceptor { public Object invoke(MethodInvocation invocation) throws Throwable {
And define a module in which you associate an interceptor with any method that has an annotation.
public class WaitCursorModule extends AbstractModule { protected void configure() { bindInterceptor(Matchers.any(), Matchers.annotatedWith(WaitCursor.class), new WaitCursorInterceptor()); } }
You can see more complex use cases for this page.
source share