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.annotation;
9   
10  import org.codehaus.aspectwerkz.Pointcut;
11  import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
12  
13  /***
14   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
15   * @Aspect perJVM
16   */
17  public class TestAspect {
18      // ============ Pointcuts ============
19  
20      /***
21       * @Expression call(@AnnotationPrivateMethod * test.annotation.*.*(..)) &&
22       *             within(test.annotation.*)
23       */
24      Pointcut call_privateMethod;
25  
26      /***
27       * @Expression execution(@AnnotationPrivateMethod * test.annotation.*.*(..))
28       */
29      Pointcut execution_privateMethod;
30  
31      /***
32       * @Expression call(@AnnotationProtectedMethod * test.annotation.*.*(..)) &&
33       *             within(test.annotation.*)
34       */
35      Pointcut call_protectedMethod;
36  
37      /***
38       * @Expression execution(@AnnotationProtectedMethod * test.annotation.*.*(..))
39       */
40      Pointcut execution_protectedMethod;
41  
42      /***
43       * @Expression call(@AnnotationPackagePrivateMethod * test.annotation.*.*(..)) &&
44       *             within(test.annotation.*)
45       */
46      Pointcut call_packagePrivateMethod;
47  
48      /***
49       * @Expression execution(@AnnotationPackagePrivateMethod * test.annotation.*.*(..))
50       */
51      Pointcut execution_packagePrivateMethod;
52  
53      /***
54       * @Expression call(@AnnotationPublicMethod * test.annotation.*.*(..)) &&
55       *             within(test.annotation.*)
56       */
57      Pointcut call_publicMethod;
58  
59      /***
60       * @Expression execution(@AnnotationPublicMethod * test.annotation.*.*(..))
61       */
62      Pointcut execution_publicMethod;
63  
64      /***
65       * @Expression execution(@AnnotationPublicMethod2 * test.annotation.*.*(..))
66       */
67      Pointcut execution_publicMethod2;
68  
69      /***
70       * @Expression get(@AnnotationPrivateField * test.annotation.*.*)
71       */
72      Pointcut get_privateField;
73  
74      /***
75       * @Expression set(@AnnotationPrivateField * test.annotation.*.*)
76       */
77      Pointcut set_privateField;
78  
79      /***
80       * @Expression get(@AnnotationProtectedField * test.annotation.*.*)
81       */
82      Pointcut get_protectedField;
83  
84      /***
85       * @Expression set(@AnnotationProtectedField * test.annotation.*.*)
86       */
87      Pointcut set_protectedField;
88  
89      /***
90       * @Expression get(@AnnotationPackagePrivateField * test.annotation.*.*)
91       */
92      Pointcut get_packagePrivateField;
93  
94      /***
95       * @Expression set(@AnnotationPackagePrivateField * test.annotation.*.*)
96       */
97      Pointcut set_packagePrivateField;
98  
99      /***
100      * @Expression get(@AnnotationPublicField * test.annotation.*.*)
101      */
102     Pointcut get_publicField;
103 
104     /***
105      * @Expression set(@AnnotationPublicField * test.annotation.*.*)
106      */
107     Pointcut set_publicField;
108 
109     // ============ Advices ============
110 
111     /***
112      * @Around call_privateMethod || call_protectedMethod || call_packagePrivateMethod ||
113      *         call_publicMethod
114      */
115     public Object advice_CALL(final JoinPoint joinPoint) throws Throwable {
116         AnnotationTest.log("call ");
117         Object result = joinPoint.proceed();
118         AnnotationTest.log("call ");
119         return result;
120     }
121 
122     /***
123      * @Around execution_privateMethod || execution_protectedMethod ||
124      *         execution_packagePrivateMethod || execution_publicMethod
125      */
126     public Object advice_EXECUTION(final JoinPoint joinPoint) throws Throwable {
127         AnnotationTest.log("execution ");
128         Object result = joinPoint.proceed();
129         AnnotationTest.log("execution ");
130         return result;
131     }
132 
133     /***
134      * @Around execution_publicMethod2
135      */
136     public Object advice_EXECUTION2(final JoinPoint joinPoint) throws Throwable {
137         AnnotationTest.log("execution2 ");
138         Object result = joinPoint.proceed();
139         AnnotationTest.log("execution2 ");
140         return result;
141     }
142 
143     /***
144      * @Around set_privateField || set_protectedField || set_packagePrivateField || set_publicField
145      */
146     public Object advice_SET(final JoinPoint joinPoint) throws Throwable {
147         AnnotationTest.log("set ");
148         Object result = joinPoint.proceed();
149         AnnotationTest.log("set ");
150         return result;
151     }
152 
153     /***
154      * @Around get_privateField || get_protectedField || get_packagePrivateField || get_publicField
155      */
156     public Object advice_GET(final JoinPoint joinPoint) throws Throwable {
157         AnnotationTest.log("get ");
158         Object result = joinPoint.proceed();
159         AnnotationTest.log("get ");
160         return result;
161     }
162 }