<cflow-stack name="ShowOnlyWhen123Before"> <called expr="void POJO->method1()"/> <called expr="void POJO->method2()"/> <called expr="void POJO->method3()"/> </cflow-stack>
This first cflow-stack declares that method1, method2, and method3 should be in the call stack in that order. The next
<cflow-stack name="ShowOnlyWhenConstructorAnd3"> <called expr="POJO->new(int)"/> <called expr="void POJO->method3()"/> </cflow-stack>Says that the POJO constructor with an int parameter and method3 must be in the call stack in that order
<bind pointcut="execution(void POJO->method4())" cflow="(ShowOnlyWhen123Before OR ShowOnlyWhenConstructorAnd3)"> <interceptor class="SimpleInterceptor"/> </bind>This says to trigger the SimpleInterceptor on the execution of method4, but only when it is called within the context of method1, method2, and method3 OR contructor and method3. When you run the driver you will see this in action. Look at how Driver.java invokes on POJO methods, then example the output of the program.
The next example is for recursive methods. The example cflow-stack says that two calls to the recursive method must be in the call stack, but no more
<cflow-stack name="showSecondRecursiveCall"> <called expr="void POJO->recursive(int)"/> <called expr="void POJO->recursive(int)"/> <not-called expr="void POJO->recursive(int)"/> </cflow-stack> <bind pointcut="execution(void POJO->recursive(int))" cflow="showSecondRecursiveCall"> <interceptor class="SimpleInterceptor"/> </bind>
Combined with the execution binding, the SimpleInterceptor will only be triggered on the second call to the recursive method.
To compile and run (for further detail, refer to our Compiling and Running Examples Guide):
$ ant run.aopc
It will javac the files and then run the AOPC precompiler to manipulate the bytecode, then finally run the example. The output should be similar to this:
_run.aopc: [java] --- pojo.method4(); --- [java] method4 [java] --- pojo.method3(); --- [java] method3 [java] method4 [java] --- pojo.method2(); --- [java] method2 [java] method3 [java] method4 [java] --- pojo.method1(); --- [java] method1 [java] method2 [java] method3 [java] <<< Entering SimpleInterceptor for: public void POJO.method4() [java] method4 [java] >>> Leaving SimpleInterceptor [java] --- pojo.recursive(); --- [java] recursive: 1 [java] <<< Entering SimpleInterceptor for: public void POJO.recursive(int) [java] recursive: 2 [java] recursive: 3 [java] >>> Leaving SimpleInterceptor [java] --- new POJO(int); --- [java] method3 [java] <<< Entering SimpleInterceptor for: public void POJO.method4() [java] method4 [java] >>> Leaving SimpleInterceptor