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.CallerSideAdviceTest;
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 CallerSideTestAspect {
20
21
22 /***
23 * @Expression call(String test.CallerSideTestHelper.invokeMemberMethodPre()) &&
24 * within(test.CallerSideAdviceTest)
25 */
26 Pointcut pc1;
27
28 /***
29 * @Expression call(String test.CallerSideTestHelper.invokeMemberMethodPost()) &&
30 * within(test.CallerSideAdviceTest)
31 */
32 Pointcut pc2;
33
34 /***
35 * @Expression call(String test.CallerSideTestHelper.invokeMemberMethodPrePost()) &&
36 * withincode(* test.CallerSideAdviceTest.test*(..))
37 */
38 Pointcut pc3;
39
40 /***
41 * @Expression call(String test.CallerSideTestHelper.invokeStaticMethodPre()) &&
42 * within(test.CallerSideAdviceTest)
43 */
44 Pointcut pc4;
45
46 /***
47 * @Expression call(String test.CallerSideTestHelper.invokeStaticMethodPost()) &&
48 * within(test.CallerSideAdviceTest)
49 */
50 Pointcut pc5;
51
52 /***
53 * @Expression call(String test.CallerSideTestHelper.invokeStaticMethodPrePost()) &&
54 * withincode(* test.CallerSideAdviceTest.test*(..))
55 */
56 Pointcut pc6;
57
58 /***
59 * @Expression call(* test.CallerSideTestHelper.invokeMemberMethodAround*(..)) &&
60 * within(test.CallerSideAdviceTest)
61 */
62 Pointcut pc7;
63
64 /***
65 * @Expression call(* test.CallerSideTestHelper.invokeStaticMethodAround*()) && withincode(*
66 * test.CallerSideAdviceTest.test*(..))
67 */
68 Pointcut pc8;
69
70
71
72 /***
73 * @Before pc1 || pc3 || pc4 || pc6
74 */
75 public void preAdvice1(final JoinPoint joinPoint) throws Throwable {
76 CallerSideAdviceTest.log("pre1 ");
77 }
78
79 /***
80 * @Before pc1 || pc3 || pc4 || pc6
81 */
82 public void preAdvice2(final JoinPoint joinPoint) throws Throwable {
83 CallerSideAdviceTest.log("pre2 ");
84 }
85
86 /***
87 * @After pc2 || pc3 || pc5 || pc6
88 */
89 public void postAdvice1(final JoinPoint joinPoint) throws Throwable {
90 CallerSideAdviceTest.log("post1 ");
91 }
92
93 /***
94 * @After pc2 || pc3 || pc5 || pc6
95 */
96 public void postAdvice2(final JoinPoint joinPoint) throws Throwable {
97 CallerSideAdviceTest.log("post2 ");
98 }
99
100 /***
101 * @Around pc8 || pc7
102 */
103 public Object around(final JoinPoint joinPoint) throws Throwable {
104 CallerSideAdviceTest.log("before ");
105 Object result = joinPoint.proceed();
106 CallerSideAdviceTest.log("after ");
107 return result;
108 }
109 }