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.Pointcut;
12 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
13
14 /***
15 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
16 * @Aspect perJVM
17 */
18 public class CFlowTestAspect {
19
20
21 /***
22 * @Expression cflow(call(* test.CFlowTest.step1()) AND within(test.CFlowTest))
23 */
24 Pointcut pc1;
25
26 /***
27 * @Expression cflow(call(* test.CFlowTest.step1_A()) AND within(test.CFlowTest))
28 */
29 Pointcut pc1_A;
30
31 /***
32 * @Expression cflow(call(* test.CFlowTest.step1_B()) AND within(test.CFlowTest))
33 */
34 Pointcut pc1_B;
35
36 /***
37 * @Expression execution(* test.CFlowTest.step2())
38 */
39 Pointcut pc2;
40
41 /***
42 * @Expression execution(* test.CFlowTest.step2_B())
43 */
44 Pointcut pc2_B;
45
46
47
48 /***
49 * @Around pc2 AND pc1
50 */
51 public Object execute(final JoinPoint joinPoint) throws Throwable {
52 ((Loggable) joinPoint.getTarget()).log("advice-before ");
53 final Object result = joinPoint.proceed();
54 ((Loggable) joinPoint.getTarget()).log("advice-after ");
55 return result;
56 }
57
58 /***
59 * @Around pc2_B AND pc1_B AND pc1_A
60 */
61 public Object execute2(final JoinPoint joinPoint) throws Throwable {
62 ((Loggable) joinPoint.getTarget()).log("advice-before2 ");
63 final Object result = joinPoint.proceed();
64 ((Loggable) joinPoint.getTarget()).log("advice-after2 ");
65 return result;
66 }
67
68 /***
69 * @Around execution(* test.CFlowTest.step2Anonymous()) AND cflow(call(*
70 * test.CFlowTest.step1Anonymous()) AND within(test.CFlowTest))
71 */
72 public Object executeAnonymous(final JoinPoint joinPoint) throws Throwable {
73 ((Loggable) joinPoint.getTarget()).log("advice-beforeAnonymous ");
74 final Object result = joinPoint.proceed();
75 ((Loggable) joinPoint.getTarget()).log("advice-afterAnonymous ");
76 return result;
77 }
78
79 /***
80 * FIXME: this expression leads to match all at cflow early filtering.
81 *
82 * X@Around execution(* test.CFlowTest.step2_C()) AND !cflow(call(* test.CFlowTest.step1_C()) AND
83 * within(test.CFlowTest))
84 */
85 public Object executeC(final JoinPoint joinPoint) throws Throwable {
86 ((Loggable) joinPoint.getTarget()).log("advice-beforeC ");
87 final Object result = joinPoint.proceed();
88 ((Loggable) joinPoint.getTarget()).log("advice-afterC ");
89 return result;
90 }
91 }