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.aspect;
008:
009: import test.FieldAdviceTest;
010: import org.codehaus.aspectwerkz.definition.Pointcut;
011: import org.codehaus.aspectwerkz.definition.Pointcut;
012: import org.codehaus.aspectwerkz.joinpoint.FieldRtti;
013: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
014:
015: /**
016: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
017: * @Aspect perJVM
018: */
019: public class FieldTestAspect {
020: // ============ Pointcuts ============
021:
022: /**
023: * @Expression set(* test.FieldAdviceTest.m_setFieldPreAdvice*)
024: */
025: Pointcut pc1;
026:
027: /**
028: * @Expression set(int test.FieldAdviceTest.m_setFieldPreAdvi*)
029: */
030: Pointcut pc2;
031:
032: /**
033: * @Expression set(* test.FieldAdviceTest.m_setFie*dPostAdviced)
034: */
035: Pointcut pc3;
036:
037: /**
038: * @Expression set(* test.FieldAdviceTest.m_se*FieldPostAdviced)
039: */
040: Pointcut pc4;
041:
042: /**
043: * @Expression set(* test.FieldAdviceTest.m_setFieldPrePostAdviced)
044: */
045: Pointcut pc5;
046:
047: /**
048: * @Expression get(* test.FieldAdviceTest.m_getFieldPreAdvic*)
049: */
050: Pointcut pc6;
051:
052: /**
053: * @Expression get(* test.FieldAdviceTest.m_getFieldPreAdvice*)
054: */
055: Pointcut pc7;
056:
057: /**
058: * @Expression get(* test.FieldAdviceTest.m_getFieldPostAdviced)
059: */
060: Pointcut pc8;
061:
062: /**
063: * @Expression get(* test.FieldAdviceTest.m_getFieldPrePostAdviced)
064: */
065: Pointcut pc9;
066:
067: /**
068: * @Expression set(* test.FieldAdviceTest.s_setStaticFieldPreAdvic*)
069: */
070: Pointcut pc10;
071:
072: /**
073: * @Expression set(* test.FieldAdviceTest.s_setStaticFieldPreAdvice*)
074: */
075: Pointcut pc11;
076:
077: /**
078: * @Expression set(* test.FieldAdviceTest.s_setStaticFieldPostAdviced)
079: */
080: Pointcut pc12;
081:
082: /**
083: * @Expression set(* test.FieldAdviceTest.s_setStaticFieldPrePostAdviced)
084: */
085: Pointcut pc13;
086:
087: /**
088: * @Expression get(* test.FieldAdviceTest.s_getStaticFieldPreAdvice*)
089: */
090: Pointcut pc14;
091:
092: /**
093: * @Expression get(* test.FieldAdviceTest.s_getStaticFieldPreAdvic*)
094: */
095: Pointcut pc15;
096:
097: /**
098: * @Expression get(* test.FieldAdviceTest.s_getStaticFieldPostAdviced)
099: */
100: Pointcut pc16;
101:
102: /**
103: * @Expression get(* test.FieldAdviceTest.s_getStaticFieldPrePostAdviced)
104: */
105: Pointcut pc17;
106:
107: /**
108: * @Expression set(* test.FieldAdviceTest.m_setFieldAroundAdviced)
109: */
110: Pointcut pc18;
111:
112: /**
113: * @Expression set(* test.FieldAdviceTest.s_setStaticFieldAroundAdviced)
114: */
115: Pointcut pc19;
116:
117: /**
118: * @Expression get(* test.FieldAdviceTest.m_getFieldAroundAdviced)
119: */
120: Pointcut pc20;
121:
122: /**
123: * @Expression get(* test.FieldAdviceTest.s_getStaticFieldAroundAdviced)
124: */
125: Pointcut pc21;
126:
127: /**
128: * @Expression set(* test.FieldAdviceTest.m_setFieldAroundAdviced*WithNullAdvice)
129: */
130: Pointcut pc22;
131:
132: /**
133: * @Expression get(* test.FieldAdviceTest.m_getFieldAroundAdvicedWithNullAdvice)
134: */
135: Pointcut pc23;
136:
137: /**
138: * @Expression set(* test.FieldAdviceTest.m_setFieldAroundAdvicedObjectWithAPI)
139: */
140: Pointcut pc24;
141:
142: /**
143: * @Expression set(* test.FieldAdviceTest.m_setFieldAroundAdvicedWithAPI)
144: */
145: Pointcut pc25;
146:
147: /**
148: * @Expression within(test.FieldAdviceTest)
149: */
150: Pointcut filter;
151:
152: // ============ Advices ============
153:
154: /**
155: * @Before filter && (pc2 || pc5 || pc10 || pc13 || pc6 || pc9 || pc14 || pc17)
156: */
157: public void preAdvice1(final JoinPoint joinPoint) throws Throwable {
158: FieldAdviceTest.log("pre1 ");
159: }
160:
161: /**
162: * @Before filter && (pc1 || pc5 || pc11 || pc13 || pc7 || pc9 || pc15 || pc17)
163: */
164: public void preAdvice2(final JoinPoint joinPoint) throws Throwable {
165: FieldAdviceTest.log("pre2 ");
166: }
167:
168: /**
169: * @After filter && (pc4 || pc5 || pc12 || pc13 || pc8 || pc9 || pc16 || pc17)
170: */
171: public void postAdvice1(final JoinPoint joinPoint) throws Throwable {
172: FieldAdviceTest.log("post1 ");
173: }
174:
175: /**
176: * @After filter && (pc3 || pc5 || pc12 || pc13 || pc8 || pc9 || pc16 || pc17)
177: */
178: public void postAdvice2(final JoinPoint joinPoint) throws Throwable {
179: FieldAdviceTest.log("post2 ");
180: }
181:
182: /**
183: * @Around filter && (pc18 || pc19 || pc20 || pc21)
184: */
185: public Object around(final JoinPoint joinPoint) throws Throwable {
186: FieldAdviceTest.log("before ");
187: final Object result = joinPoint.proceed();
188: FieldAdviceTest.log("after ");
189: return result;
190: }
191:
192: /**
193: * @Around filter && (pc22 || pc23)
194: */
195: public Object aroundNullAdvice(final JoinPoint joinPoint)
196: throws Throwable {
197: FieldAdviceTest.log("before ");
198: final Object result = joinPoint.proceed();
199: FieldAdviceTest.log("after ");
200: return null;
201: }
202:
203: /**
204: * @Before get(java.io.PrintStream out) && withincode(* test.FieldAdviceTest.testPublicFieldOutOfWeaverScope())
205: */
206: public void beforePublicFieldOutOfWeaverScope() {
207: FieldAdviceTest.log("adviceOnPublicField ");
208: }
209:
210: //TODO - activate when proceed(args) will be supported
211:
212: // /**
213: // * @Around pc24
214: // */
215: // public Object aroundAdviceAltering(final JoinPoint joinPoint) throws Throwable {
216: // FieldAdviceTest.log("before ");
217: // FieldRtti rtti = (FieldRtti) joinPoint.getRtti();
218: // rtti.setFieldValue(new String("byAdvice"));
219: // joinPoint.proceed();
220: // FieldAdviceTest.log("after ");
221: // return null;
222: // }
223: //
224: // /**
225: // * @Around pc25
226: // */
227: // public Object aroundAdviceAlteringPrimitive(final JoinPoint joinPoint) throws Throwable {
228: // FieldAdviceTest.log("before ");
229: // FieldRtti rtti = (FieldRtti) joinPoint.getRtti();
230: // rtti.setFieldValue(new Integer(3));
231: // joinPoint.proceed();
232: // FieldAdviceTest.log("after ");
233: // return null;
234: // }
235: }
|