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