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