import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.pointcut.DynamicCFlow; import org.jboss.aop.DynamicCFlowDef; @DynamicCFlowDef public class SimpleDynamicCFlow implements DynamicCFlow { public static boolean runit = false; public boolean shouldExecute(Invocation invocation) { return runit; } }
This is exactly the same as in the XML example. The only difference is that we declare the dynamic cflow class by annotating it with @DynamicCFlowDef.
@InterceptorDef @Bind (pointcut="execution(void POJO->method1())", cflow="SimpleDynamicCFlow") public class SimpleInterceptor implements Interceptor { ... }
$ antIt will javac the files and then run the AOPC precompiler to manipulate the bytecode, then finally run the example. The output should read as follows:
run: [java] --- pojo.method4(); --- [java] method1 [java] --- turn on cflow --- [java] <<< Entering SimpleInterceptor for: public void POJO.method1() [java] method1 [java] >>> Leaving SimpleInterceptor