001: /**************************************************************************************
002: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.optimizations;
008:
009: import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
010: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
011: import org.codehaus.aspectwerkz.joinpoint.Rtti;
012: import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
013: import org.codehaus.aspectwerkz.definition.Pointcut;
014:
015: /**
016: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
017: */
018: public class OptimizeAspect {
019:
020: //------------- advice with no args
021:
022: /** @Before execution(* test.optimizations.OptimizeTest$OptimizeNothing.before())
023: * || execution(* test.optimizations.OptimizeTest$OptimizeNothing.beforeAround())*/
024: public void beforeNothing() {
025: OptimizeTest.log("before");
026: }
027:
028: /** @Around execution(* test.optimizations.OptimizeTest$OptimizeNothing.around())
029: * || execution(* test.optimizations.OptimizeTest$OptimizeNothing.beforeAround()) */
030: public Object aroundNothing() {
031: OptimizeTest.log("around");
032: return null;// a crapy around aspect!
033: }
034:
035: /** @Before execution(* test.optimizations.OptimizeTest$OptimizeNothing.before(int)) && args(i) */
036: public void beforeNothing(int i) {
037: OptimizeTest.log("before" + i);
038: }
039:
040: /** @Around execution(* test.optimizations.OptimizeTest$OptimizeNothing.around(int)) && args(i) */
041: public Object aroundNothing(int i) {
042: OptimizeTest.log("around" + i);
043: return null;
044: }
045:
046: //------------- advice with StaticJoinPoint
047:
048: /** @Before execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.before())
049: * || execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.beforeAround())*/
050: public void beforeStaticJoinPoint(StaticJoinPoint sjp) {
051: OptimizeTest.log("beforeSJP-" + sjp.getSignature().getName());
052: }
053:
054: /** @Around execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.around())
055: * || execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.beforeAround()) */
056: public Object aroundStaticJoinPoint(StaticJoinPoint sjp)
057: throws Throwable {
058: OptimizeTest.log("aroundSJP-" + sjp.getSignature().getName());
059: return sjp.proceed();
060: }
061:
062: /** @Before execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.before(int)) && args(i) */
063: public void beforeStaticJoinPoint(StaticJoinPoint sjp, int i) {
064: OptimizeTest.log("beforeSJP" + i);
065: }
066:
067: /** @Around execution(* test.optimizations.OptimizeTest$OptimizeStaticJoinPoint.around(int)) && args(i) */
068: public Object aroundStaticJoinPoint(int i, StaticJoinPoint sjp)
069: throws Throwable {
070: OptimizeTest.log("aroundSJP" + i);
071: return sjp.proceed();
072: }
073:
074: //------------- advice with JoinPoint, will make use of a runtime check for target
075:
076: /** @Expression withincode(* test.optimizations.OptimizeTest.testJoinPoint(..)) && target(test.optimizations.OptimizeTest$OptimizeJoinPoint) */
077: Pointcut pc_in;
078:
079: /** @Before (call(* test.optimizations.OptimizeTest$IOptimize.before())
080: * || call(* test.optimizations.OptimizeTest$IOptimize.beforeAround())
081: * ) && pc_in
082: */
083: public void beforeJoinPoint(JoinPoint jp) {
084: OptimizeTest.log("beforeJP-" + jp.getSignature().getName()
085: + "-" + jp.getCallee().toString() + "-"
086: + jp.getCaller().toString());
087: }
088:
089: /** @Around (call(* test.optimizations.OptimizeTest$IOptimize.around())
090: * || call(* test.optimizations.OptimizeTest$IOptimize.beforeAround())
091: * ) && pc_in
092: */
093: public Object aroundJoinPoint(JoinPoint jp) throws Throwable {
094: OptimizeTest.log("aroundJP-" + jp.getSignature().getName()
095: + "-" + jp.getCallee().toString() + "-"
096: + jp.getCaller().toString());
097: return jp.proceed();
098: }
099:
100: /** @Before call(* test.optimizations.OptimizeTest$IOptimize.before(int)) && args(i) && pc_in */
101: public void beforeJoinPoint(JoinPoint jp, int i) {
102: OptimizeTest.log("beforeJP" + i);
103: }
104:
105: /** @Around call(* test.optimizations.OptimizeTest$IOptimize.around(int)) && args(i) && pc_in */
106: public Object aroundJoinPoint(int i, JoinPoint jp) throws Throwable {
107: OptimizeTest.log("aroundJP" + i);
108: return jp.proceed();
109: }
110:
111: //------------- advice with Rtti
112:
113: /**
114: * @Before execution(* test.optimizations.OptimizeTest$OptimizeRtti.before())
115: * || execution(* test.optimizations.OptimizeTest$OptimizeRtti.beforeAround())
116: */
117: public void beforeRtti(JoinPoint jp) {
118: OptimizeTest.log("beforeRTTI-" + jp.getRtti().getName()
119: + jp.getRtti().getThis() + jp.getRtti().getTarget());
120: }
121:
122: /**
123: * @Around execution(* test.optimizations.OptimizeTest$OptimizeRtti.around())
124: * || execution(* test.optimizations.OptimizeTest$OptimizeRtti.beforeAround())
125: */
126: public Object aroundRtti(JoinPoint jp) throws Throwable {
127: OptimizeTest.log("aroundRTTI-" + jp.getRtti().getName()
128: + jp.getRtti().getThis() + jp.getRtti().getTarget());
129: return jp.proceed();
130: }
131:
132: /**
133: * @Before execution(* test.optimizations.OptimizeTest$OptimizeRtti.before(int))
134: */
135: public void beforeRttiInt(JoinPoint jp) {
136: OptimizeTest.log("beforeRTTI-" + jp.getRtti().getName()
137: + jp.getRtti().getThis() + jp.getRtti().getTarget());
138: Integer param = (Integer) ((MethodRtti) jp.getRtti())
139: .getParameterValues()[0];
140: //TODO ...
141: }
142:
143: /**
144: * @Around execution(* test.optimizations.OptimizeTest$OptimizeRtti.around(int))
145: */
146: public Object aroundRtti(StaticJoinPoint sjp, JoinPoint jp /* note: silly but possible...*/)
147: throws Throwable {
148: OptimizeTest.log("aroundRTTI-" /*TODO*/);
149: return sjp.proceed();
150: }
151: }
|