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.StaticMethodAdviceTest;
11  import org.codehaus.aspectwerkz.definition.Pointcut;
12  import org.codehaus.aspectwerkz.definition.Pointcut;
13  import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
14  import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
15  import org.codehaus.aspectwerkz.joinpoint.Rtti;
16  
17  /***
18   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
19   * @Aspect perJVM
20   */
21  public class StaticMethodTestAspect {
22      // ============ Pointcuts ============
23  
24      /***
25       * @Expression call(* test.StaticMethodAdviceTest.get*(..)) && within(test.StaticMethodAdviceTest)
26       */
27      Pointcut static_pc1;
28  
29      /***
30       * @Expression execution(* test.StaticMethodAdviceTest.*Param*(..))
31       */
32      Pointcut static_pc2;
33  
34      /***
35       * @Expression call(void test.StaticMethodAdviceTest.methodAdvicedMethod(..)) && within(test.StaticMethodAdviceTest)
36       */
37      Pointcut static_pc4;
38  
39      /***
40       * @Expression execution(* test.StaticMethodAdviceTest.methodAdvicedMethod(..))
41       */
42      Pointcut static_pc5;
43  
44      /***
45       * @Expression call(* test.StaticMethodAdviceTest.methodAdvicedMethodNewThread(..)) && within(test.StaticMethodAdviceTest)
46       */
47      Pointcut static_pc6;
48  
49      /***
50       * @Expression execution(* test.StaticMethodAdviceTest.multipleMethodAdvicedMethod(..))
51       */
52      Pointcut static_pc7;
53  
54      /***
55       * @Expression call(* test.StaticMethodAdviceTest.multipleChainedMethodAdvicedMethod(..)) && within(test.StaticMethodAdviceTest)
56       */
57      Pointcut static_pc8;
58  
59      /***
60       * @Expression execution(* test.StaticMethodAdviceTest.joinPointMetaData(..))
61       */
62      Pointcut static_pc9;
63  
64      /***
65       * @Expression call(void test.StaticMethodAdviceTest.multiplePointcutsMethod(..)) && within(test.StaticMethodAdviceTest)
66       */
67      Pointcut static_pc10;
68  
69      /***
70       * @Expression execution(void test.StaticMethodAdviceTest.multiplePointcutsMethod(..))
71       */
72      Pointcut static_pc11;
73  
74      /***
75       * @Expression call(* test.StaticMethodAdviceTest.takesArrayAsArgument(String[])) && within(test.StaticMethodAdviceTest)
76       */
77      Pointcut static_pc12;
78  
79      /***
80       * @Expression execution(long test.StaticMethodAdviceTest.getPrimitiveAndNullFromAdvice())
81       */
82      Pointcut static_pc13;
83  
84      // ============ Advices ============
85  
86      /***
87       * @Before static_pc1 || static_pc2 || static_pc5 || static_pc8 || static_pc12
88       */
89      public void before(final JoinPoint joinPoint) throws Throwable {
90      }
91  
92      /***
93       * @AfterFinally static_pc1 || static_pc2 || static_pc5 || static_pc8 || static_pc12
94       */
95      public void afterFinally(final JoinPoint joinPoint) throws Throwable {
96      }
97  
98      /***
99       * @Around static_pc1 || static_pc2 || static_pc5 || static_pc8 || static_pc12
100      */
101     public Object advice1(final JoinPoint joinPoint) throws Throwable {
102         return joinPoint.proceed();
103     }
104 
105     /***
106      * @Around static_pc4 || static_pc7 || static_pc8 || static_pc10
107      */
108     public Object advice2(final JoinPoint joinPoint) throws Throwable {
109         StaticMethodAdviceTest.log("before1 ");
110         final Object result = joinPoint.proceed();
111         StaticMethodAdviceTest.log("after1 ");
112         return result;
113     }
114 
115     /***
116      * @Around static_pc7 || static_pc8 || static_pc11
117      */
118     public Object advice3(final JoinPoint joinPoint) throws Throwable {
119         StaticMethodAdviceTest.log("before2 ");
120         final Object result = joinPoint.proceed();
121         StaticMethodAdviceTest.log("after2 ");
122         return result;
123     }
124 
125     /***
126      * @Around static_pc9
127      */
128     public Object advice4(final JoinPoint joinPoint) throws Throwable {
129         final Object result = joinPoint.proceed();
130         MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
131         String metadata = joinPoint.getCalleeClass().getName()
132                           + mrtti.getMethod().getName()
133                           + mrtti.getParameterValues()[0]
134                           + mrtti.getParameterTypes()[0].getName()
135                           + mrtti.getReturnType().getName()
136                           + mrtti.getReturnValue();
137         return metadata;
138     }
139 
140     /***
141      * @Around static_pc6
142      */
143     public Object advice5(final JoinPoint joinPoint) throws Throwable {
144         StaticMethodAdviceTest.log("before ");
145         final Object result = joinPoint.proceed();
146         StaticMethodAdviceTest.log("after ");
147         return result;
148     }
149 
150     /***
151      * @Around static_pc13
152      */
153     public Object advice7(final JoinPoint joinPoint) throws Throwable {
154         return null;
155     }
156 }