KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > withincode > WithincodeStaticinitializationAspect


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.withincode;
9
10 import java.lang.reflect.Field JavaDoc;
11 import java.lang.reflect.Modifier JavaDoc;
12
13 import org.codehaus.aspectwerkz.definition.Pointcut;
14 import org.codehaus.aspectwerkz.joinpoint.EnclosingStaticJoinPoint;
15 import org.codehaus.aspectwerkz.joinpoint.FieldRtti;
16 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
17 import org.codehaus.aspectwerkz.joinpoint.Rtti;
18 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
19
20 import test.handler.HandlerTestBeforeException;
21
22
23 /**
24  * Withincode(clinit) aspect.
25  *
26  * @author <a HREF="mailto:the_mindstorm@evolva.ro">Alex Popescu</a>
27  *
28  * @Aspect("perClass")
29  */

30 public class WithincodeStaticinitializationAspect {
31     /**
32      * @Expression withincode(staticinitialization(test.withincode.Target))
33      */

34     Pointcut withincodeTarget;
35     
36     /**
37      * @Expression withincode(staticinitialization(@WithincodeClinit))
38      */

39     Pointcut withincodeClinit;
40     
41     /**
42      * @Expression withincode(staticinitialization(@WithincodeClinit test.withincode.*))
43      */

44     Pointcut withincodeClinitPattern;
45     
46     /**
47      * @Expression set(test.withincode.Target$CtorCallTarget test.withincode.Target.s_field)
48      */

49     Pointcut set;
50     
51     /**
52      * @Expression get(test.withincode.Target$CtorCallTarget test.withincode.Target.s_field)
53      */

54     Pointcut get;
55     
56     /**
57      * @Expression set || get
58      */

59     Pointcut getset;
60     
61     /**
62      * @Expression call(test.withincode.Target$CtorCallTarget.new())
63      */

64     Pointcut ctorCall;
65     
66     /**
67      * @Expression call(void test.withincode.Target.staticMethod())
68      */

69     Pointcut methodCall;
70
71     /**
72      * @Before ctorCall && withincode(staticinitialization(test.withincode.Target))
73      */

74     public void beforeCtorCall() {
75         WithincodeClinitTest.addMessage("beforeCtorCall");
76     }
77
78     /**
79      * @Before ctorCall && withincodeClinit
80      */

81     public void beforeWithincodeClinitCtorCall() {
82         WithincodeClinitTest.addMessage("beforeWithincodeClinitCtorCall");
83     }
84     
85     /**
86      * @Before ctorCall && withincodeClinitPattern
87      */

88     public void beforeWithincodeClinitPatternCtorCall() {
89         WithincodeClinitTest.addMessage("beforeWithincodeClinitPatternCtorCall");
90     }
91     
92     /**
93      * @After ctorCall && withincodeClinitPattern
94      */

95     public void afterWithincodeClinitPatternCtorCall() {
96         WithincodeClinitTest.addMessage("afterWithincodeClinitPatternCtorCall");
97     }
98     
99     /**
100      * @After ctorCall && withincodeClinit
101      */

102     public void afterWithincodeClinitCtorCall() {
103         WithincodeClinitTest.addMessage("afterWithincodeClinitCtorCall");
104     }
105
106     /**
107      * @After ctorCall && withincode(staticinitialization(test.withincode.Target))
108      */

109     public void afterCtorCall() {
110         WithincodeClinitTest.addMessage("afterCtorCall");
111     }
112         
113     /**
114      * @AfterReturning ctorCall && withincode(staticinitialization(test.withincode.Target))
115      */

116     public void afterReturningCtorCall() {
117         WithincodeClinitTest.addMessage("afterReturningCtorCall");
118     }
119     
120     /**
121      * @Before getset && withincode(staticinitialization(test.withincode.Target))
122      */

123     public void beforeGetSet() {
124         WithincodeClinitTest.addMessage("beforeGetSet");
125     }
126     
127     /**
128      * @After getset && withincode(staticinitialization(test.withincode.Target))
129      */

130     public void afterGetSet() {
131         WithincodeClinitTest.addMessage("afterGetSet");
132     }
133     
134     
135     /**
136      * @AfterReturning getset && withincode(staticinitialization(test.withincode.Target))
137      */

138     public void afterReturningGetSet() {
139         WithincodeClinitTest.addMessage("afterReturningGetSet");
140     }
141     
142     /**
143      * @Before methodCall && withincode(staticinitialization(test.withincode.Target))
144      */

145     public void beforeMethodCall() {
146         WithincodeClinitTest.addMessage("beforeMethodCall");
147     }
148     
149     /**
150      * @AfterFinally methodCall && withincode(staticinitialization(test.withincode.Target))
151      */

152     public void afterFinallyMethodCall() {
153         WithincodeClinitTest.addMessage("afterFinallyMethodCall");
154     }
155     
156     /**
157      * @AfterReturning methodCall && withincode(staticinitialization(test.withincode.Target))
158      */

159     public void afterReturningMethodCall() {
160         // should neven occur
161
WithincodeClinitTest.addMessage("afterReturningMethodCall");
162     }
163     
164     /**
165      * @AfterThrowing methodCall && withincode(staticinitialization(test.withincode.Target))
166      */

167     public void afterThrowingMethodCall() {
168         WithincodeClinitTest.addMessage("afterThrowingMethodCall");
169     }
170     
171     /**
172      * @AfterThrowing(type="test.handler.HandlerTestBeforeException", pointcut="methodCall && withincode(staticinitialization(test.withincode.Target))")
173      */

174     public void afterThrowingTypeMethodCall() {
175         WithincodeClinitTest.addMessage("afterThrowingTypeMethodCall");
176     }
177     
178     /**
179      * @Before handler(test.handler.HandlerTestBeforeException) && withincode(staticinitialization(test.withincode.Target))
180      */

181     public void beforeHandler() {
182         WithincodeClinitTest.addMessage("beforeHandler");
183     }
184     
185     // SJP
186
/**
187      * @Before ctorCall && withincodeTarget
188      */

189     public void beforeCtorCall(StaticJoinPoint sjp) {
190         WithincodeClinitTest.addSJP(sjp);
191     }
192
193     /**
194      * @Around ctorCall && withincodeTarget
195      */

196     public Object JavaDoc aroundCtorCall(StaticJoinPoint sjp) throws Throwable JavaDoc {
197         WithincodeClinitTest.addSJP(sjp);
198         return sjp.proceed();
199     }
200     
201     /**
202      * @After ctorCall && withincodeTarget
203      */

204     public void afterCtorCall(StaticJoinPoint sjp) {
205         WithincodeClinitTest.addSJP(sjp);
206     }
207     
208     /**
209      * @AfterReturning ctorCall && withincodeTarget
210      */

211     public void afterReturningCtorCall(StaticJoinPoint sjp) {
212         WithincodeClinitTest.addSJP(sjp);
213     }
214     
215     /**
216      * @Before getset && withincodeTarget
217      */

218     public void beforeGetSet(StaticJoinPoint sjp) {
219         WithincodeClinitTest.addSJP(sjp);
220     }
221     
222     /**
223      * @Around getset && withincodeTarget
224      */

225     public Object JavaDoc aroundGetSet(StaticJoinPoint sjp) throws Throwable JavaDoc {
226         WithincodeClinitTest.addSJP(sjp);
227         return sjp.proceed();
228     }
229     
230     /**
231      * @After getset && withincodeTarget
232      */

233     public void afterGetSet(StaticJoinPoint sjp) {
234         WithincodeClinitTest.addSJP(sjp);
235     }
236     
237     /**
238      * @AfterReturning getset && withincodeTarget
239      */

240     public void afterReturningGetSet(StaticJoinPoint sjp) {
241         WithincodeClinitTest.addSJP(sjp);
242     }
243     
244     /**
245      * @Before methodCall && withincodeTarget
246      */

247     public void beforeMethodCall(StaticJoinPoint sjp) {
248         WithincodeClinitTest.addSJP(sjp);
249     }
250     
251     /**
252      * @Around methodCall && withincodeTarget
253      */

254     public Object JavaDoc aroundMethodCall(StaticJoinPoint sjp) throws Throwable JavaDoc {
255         WithincodeClinitTest.addSJP(sjp);
256         return sjp.proceed();
257     }
258
259     /**
260      * @AfterThrowing(type="test.handler.HandlerTestBeforeException", pointcut="methodCall && withincodeTarget")
261      */

262     public void afterThrowingTypeMethodCall(StaticJoinPoint sjp) {
263         WithincodeClinitTest.addSJP(sjp);
264     }
265
266     /**
267      * @AfterThrowing methodCall && withincodeTarget
268      */

269     public void afterThrowingMethodCall(StaticJoinPoint sjp) {
270         WithincodeClinitTest.addSJP(sjp);
271     }
272     
273     /**
274      * @AfterFinally methodCall && withincodeTarget
275      */

276     public void afterFinallyMethodCall(StaticJoinPoint sjp) {
277         WithincodeClinitTest.addSJP(sjp);
278     }
279     
280     /**
281      * @Before handler(test.handler.HandlerTestBeforeException) && withincodeTarget
282      */

283     public void beforeHandler(StaticJoinPoint sjp) {
284         WithincodeClinitTest.addSJP(sjp);
285     }
286     
287     /**
288      * @Before handler(test.handler.HandlerTestBeforeException) && withincodeTarget && args(htbe)
289      */

290     public void beforeArgsHandler(StaticJoinPoint sjp, HandlerTestBeforeException htbe) {
291         WithincodeClinitTest.addSJP(sjp);
292     }
293
294     // JoinPoints
295
/**
296      * @Before ctorCall && withincodeTarget
297      */

298     public void beforeCtorCall(JoinPoint sjp) {
299         WithincodeClinitTest.addJP(sjp);
300     }
301
302     /**
303      * @Around ctorCall && withincodeTarget
304      */

305     public Object JavaDoc aroundCtorCall(JoinPoint sjp) throws Throwable JavaDoc {
306         WithincodeClinitTest.addJP(sjp);
307         return sjp.proceed();
308     }
309     
310     /**
311      * @After ctorCall && withincodeTarget
312      */

313     public void afterCtorCall(JoinPoint sjp) {
314         WithincodeClinitTest.addJP(sjp);
315     }
316     
317     /**
318      * @AfterReturning ctorCall && withincodeTarget
319      */

320     public void afterReturningCtorCall(JoinPoint sjp) {
321         WithincodeClinitTest.addJP(sjp);
322     }
323     
324     /**
325      * @Before getset && withincodeTarget
326      */

327     public void beforeGetSet(JoinPoint sjp) {
328         WithincodeClinitTest.addJP(sjp);
329     }
330     
331     /**
332      * @Around getset && withincodeTarget
333      */

334     public Object JavaDoc aroundGetSet(JoinPoint sjp) throws Throwable JavaDoc {
335         WithincodeClinitTest.addJP(sjp);
336         return sjp.proceed();
337     }
338     
339     /**
340      * @After getset && withincodeTarget
341      */

342     public void afterGetSet(JoinPoint sjp) {
343         WithincodeClinitTest.addJP(sjp);
344     }
345     
346     /**
347      * @AfterReturning getset && withincodeTarget
348      */

349     public void afterReturningGetSet(JoinPoint sjp) {
350         WithincodeClinitTest.addJP(sjp);
351     }
352     
353     /**
354      * @Before methodCall && withincodeTarget
355      */

356     public void beforeMethodCall(JoinPoint sjp) {
357         WithincodeClinitTest.addJP(sjp);
358     }
359     
360     /**
361      * @Around methodCall && withincodeTarget
362      */

363     public Object JavaDoc aroundMethodCall(JoinPoint sjp) throws Throwable JavaDoc {
364         WithincodeClinitTest.addJP(sjp);
365         return sjp.proceed();
366     }
367
368     /**
369      * @AfterThrowing(type="test.handler.HandlerTestBeforeException", pointcut="methodCall && withincodeTarget")
370      */

371     public void afterThrowingTypeMethodCall(JoinPoint sjp) {
372         WithincodeClinitTest.addJP(sjp);
373     }
374
375     /**
376      * @AfterThrowing methodCall && withincodeTarget
377      */

378     public void afterThrowingMethodCall(JoinPoint sjp) {
379         WithincodeClinitTest.addJP(sjp);
380     }
381     
382     /**
383      * @AfterFinally methodCall && withincodeTarget
384      */

385     public void afterFinallyMethodCall(JoinPoint sjp) {
386         WithincodeClinitTest.addJP(sjp);
387     }
388     
389     /**
390      * @Before handler(test.handler.HandlerTestBeforeException) && withincodeTarget
391      */

392     public void beforeHandler(JoinPoint sjp) {
393         WithincodeClinitTest.addJP(sjp);
394     }
395     
396     /**
397      * @Before handler(test.handler.HandlerTestBeforeException) && withincodeTarget && args(htbe)
398      */

399     public void beforeArgsHandler(JoinPoint sjp, HandlerTestBeforeException htbe) {
400         WithincodeClinitTest.addJP(sjp);
401     }
402     
403 }
404
Popular Tags