1 /***************************************************************************************
2 * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package test.aspect;
9
10 import test.Loggable;
11 import org.codehaus.aspectwerkz.definition.Pointcut;
12 import org.codehaus.aspectwerkz.definition.Pointcut;
13 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
14
15 /***
16 * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17 * @Aspect perJVM
18 */
19 public class CFlowTestAspect {
20
21
22 /***
23 * @Expression cflow(call(* test.CFlowTest.step1()) AND within(test.CFlowTest))
24 */
25 Pointcut pc1;
26
27 /***
28 * @Expression cflow(call(* test.CFlowTest.step1_A()) AND within(test.CFlowTest))
29 */
30 Pointcut pc1_A;
31
32 /***
33 * @Expression cflow(call(* test.CFlowTest.step1_B()) AND within(test.CFlowTest))
34 */
35 Pointcut pc1_B;
36
37 /***
38 * @Expression execution(* test.CFlowTest.step2())
39 */
40 Pointcut pc2;
41
42 /***
43 * @Expression execution(* test.CFlowTest.step2_B())
44 */
45 Pointcut pc2_B;
46
47
48
49 /***
50 * @Around pc2 AND pc1
51 */
52 public Object execute(final JoinPoint joinPoint) throws Throwable {
53 ((Loggable) joinPoint.getTarget()).log("advice-before ");
54 final Object result = joinPoint.proceed();
55 ((Loggable) joinPoint.getTarget()).log("advice-after ");
56 return result;
57 }
58
59 /***
60 * @Around pc2_B AND pc1_B AND pc1_A
61 */
62 public Object execute2(final JoinPoint joinPoint) throws Throwable {
63 ((Loggable) joinPoint.getTarget()).log("advice-before2 ");
64 final Object result = joinPoint.proceed();
65 ((Loggable) joinPoint.getTarget()).log("advice-after2 ");
66 return result;
67 }
68
69 /***
70 * @Around execution(* test.CFlowTest.step2Anonymous()) AND cflow(call(*
71 * test.CFlowTest.step1Anonymous()) AND within(test.CFlowTest))
72 */
73 public Object executeAnonymous(final JoinPoint joinPoint) throws Throwable {
74 ((Loggable) joinPoint.getTarget()).log("advice-beforeAnonymous ");
75 final Object result = joinPoint.proceed();
76 ((Loggable) joinPoint.getTarget()).log("advice-afterAnonymous ");
77 return result;
78 }
79
80 /***
81 * FIXME: this expression leads to match all at cflow early filtering.
82 * <p/>
83 * X@Around execution(* test.CFlowTest.step2_C()) AND !cflow(call(* test.CFlowTest.step1_C()) AND
84 * within(test.CFlowTest))
85 */
86 public Object executeC(final JoinPoint joinPoint) throws Throwable {
87 ((Loggable) joinPoint.getTarget()).log("advice-beforeC ");
88 final Object result = joinPoint.proceed();
89 ((Loggable) joinPoint.getTarget()).log("advice-afterC ");
90 return result;
91 }
92
93 /***
94 * @After execution(* test.CFlowTest.cflowOnMyself()) && cflow(execution(* test.CFlowTest.cflowOnMyself()))
95 */
96 public void afterMySelf(JoinPoint joinPoint) {
97 ((Loggable) joinPoint.getTarget()).log("advice-cflowOnMyself ");
98 }
99 }