KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > optimizations > OptimizeAspect


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.optimizations;
9
10 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
11 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
12 import org.codehaus.aspectwerkz.joinpoint.Rtti;
13 import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
14 import org.codehaus.aspectwerkz.definition.Pointcut;
15
16 /**
17  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
18  */

19 public class OptimizeAspect {
20
21     //------------- advice with no args
22

23     /** @Before execution(* test.optimizations.OptimizeTest$OptimizeNothing.before())
24      * || execution(* test.optimizations.OptimizeTest$OptimizeNothing.beforeAround())*/

25     public void beforeNothing() {
26         OptimizeTest.log("before");
27     }
28     /** @Around execution(* test.optimizations.OptimizeTest$OptimizeNothing.around())
29      * || execution(* test.optimizations.OptimizeTest$OptimizeNothing.beforeAround()) */

30     public Object JavaDoc aroundNothing() {
31         OptimizeTest.log("around");
32         return null;// a crapy around aspect!
33
}
34     /** @Before execution(* test.optimizations.OptimizeTest$OptimizeNothing.before(int)) && args(i) */
35     public void beforeNothing(int i) {
36         OptimizeTest.log("before"+i);
37     }
38     /** @Around execution(* test.optimizations.OptimizeTest$OptimizeNothing.around(int)) && args(i) */
39     public Object JavaDoc aroundNothing(int i) {
40         OptimizeTest.log("around"+i);
41         return null;
42     }
43
44
45     //------------- advice with StaticJoinPoint
46

47     /** @Before execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.before())
48      * || execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.beforeAround())*/

49     public void beforeStaticJoinPoint(StaticJoinPoint sjp) {
50         OptimizeTest.log("beforeSJP-" + sjp.getSignature().getName());
51     }
52     /** @Around execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.around())
53      * || execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.beforeAround()) */

54     public Object JavaDoc aroundStaticJoinPoint(StaticJoinPoint sjp) throws Throwable JavaDoc {
55         OptimizeTest.log("aroundSJP-" + sjp.getSignature().getName());
56         return sjp.proceed();
57     }
58     /** @Before execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.before(int)) && args(i) */
59     public void beforeStaticJoinPoint(StaticJoinPoint sjp, int i) {
60         OptimizeTest.log("beforeSJP"+i);
61     }
62     /** @Around execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.around(int)) && args(i) */
63     public Object JavaDoc aroundStaticJoinPoint(int i, StaticJoinPoint sjp) throws Throwable JavaDoc {
64         OptimizeTest.log("aroundSJP"+i);
65         return sjp.proceed();
66     }
67
68     //------------- advice with JoinPoint, will make use of a runtime check for target
69

70     /** @Expression withincode(* test.optimizations.OptimizeTest.testJoinPoint(..)) && target(test.optimizations.OptimizeTest$OptimizeJoinPoint) */
71     Pointcut pc_in;
72
73     /** @Before (call(* test.optimizations.OptimizeTest$IOptimize.before())
74      * || call(* test.optimizations.OptimizeTest$IOptimize.beforeAround())
75      * ) && pc_in
76      */

77     public void beforeJoinPoint(JoinPoint jp) {
78         OptimizeTest.log("beforeJP-" + jp.getSignature().getName() + "-" + jp.getCallee().toString() + "-" + jp.getCaller().toString());
79     }
80     /** @Around (call(* test.optimizations.OptimizeTest$IOptimize.around())
81      * || call(* test.optimizations.OptimizeTest$IOptimize.beforeAround())
82      * ) && pc_in
83      */

84     public Object JavaDoc aroundJoinPoint(JoinPoint jp) throws Throwable JavaDoc {
85         OptimizeTest.log("aroundJP-" + jp.getSignature().getName() + "-" + jp.getCallee().toString() + "-" + jp.getCaller().toString());
86         return jp.proceed();
87     }
88     /** @Before call(* test.optimizations.OptimizeTest$IOptimize.before(int)) && args(i) && pc_in */
89     public void beforeJoinPoint(JoinPoint jp, int i) {
90         OptimizeTest.log("beforeJP"+i);
91     }
92     /** @Around call(* test.optimizations.OptimizeTest$IOptimize.around(int)) && args(i) && pc_in */
93     public Object JavaDoc aroundJoinPoint(int i, JoinPoint jp) throws Throwable JavaDoc {
94         OptimizeTest.log("aroundJP"+i);
95         return jp.proceed();
96     }
97
98     //------------- advice with Rtti
99

100     /**
101      * @Before execution(* test.optimizations.OptimizeTest$OptimizeRtti.before())
102      * || execution(* test.optimizations.OptimizeTest$OptimizeRtti.beforeAround())
103      */

104     public void beforeRtti(JoinPoint jp) {
105         OptimizeTest.log("beforeRTTI-" + jp.getRtti().getName() + jp.getRtti().getThis() + jp.getRtti().getTarget());
106     }
107
108     /**
109      * @Around execution(* test.optimizations.OptimizeTest$OptimizeRtti.around())
110      * || execution(* test.optimizations.OptimizeTest$OptimizeRtti.beforeAround())
111      */

112     public Object JavaDoc aroundRtti(JoinPoint jp) throws Throwable JavaDoc {
113         OptimizeTest.log("aroundRTTI-" + jp.getRtti().getName() + jp.getRtti().getThis() + jp.getRtti().getTarget());
114         return jp.proceed();
115     }
116
117     /**
118      * @Before execution(* test.optimizations.OptimizeTest$OptimizeRtti.before(int))
119      */

120     public void beforeRttiInt(JoinPoint jp) {
121         OptimizeTest.log("beforeRTTI-" + jp.getRtti().getName() + jp.getRtti().getThis() + jp.getRtti().getTarget());
122         Integer JavaDoc param = (Integer JavaDoc) ((MethodRtti) jp.getRtti()).getParameterValues()[0];
123         //TODO ...
124
}
125
126     /**
127      * @Around execution(* test.optimizations.OptimizeTest$OptimizeRtti.around(int))
128      */

129     public Object JavaDoc aroundRtti(StaticJoinPoint sjp, JoinPoint jp /* note: silly but possible...*/) throws Throwable JavaDoc {
130         OptimizeTest.log("aroundRTTI-" /*TODO*/);
131         return sjp.proceed();
132     }
133 }
134
Popular Tags