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