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.staticinitialization;
008:
009: import org.codehaus.aspectwerkz.definition.Pointcut;
010: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
011: import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
012:
013: /**
014: * Aspect on staticinitialization pointcut.
015: *
016: * @author <a href="mailto:the_mindstorm@evolva.ro">Alex Popescu</a>
017: *
018: * @Aspect("perClass")
019: */
020: public class StaticInitializationAspect {
021: /**
022: * @Expression staticinitialization(test.staticinitialization.ClinitTarget)
023: */
024: Pointcut staticInitialization;
025:
026: /**
027: * @Expression staticinitialization(@StaticInitializationService)
028: */
029: Pointcut staticServiceInitialization;
030:
031: /**
032: * @Expression staticinitialization(@StaticInitializationService test.staticinitialization.*)
033: */
034: Pointcut staticPatternInitialization;
035:
036: /**
037: * @Before staticInitialization
038: */
039: public void beforeStaticInitializer() {
040: StaticInitializationTest.s_messages
041: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[0]);
042: }
043:
044: /**
045: * @Before staticServiceInitialization
046: */
047: public void beforeStaticServiceInitialization() {
048: StaticInitializationTest.s_messages
049: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[0]);
050: }
051:
052: /**
053: * @Before staticPatternInitialization
054: */
055: public void beforeStaticPatternInitialization() {
056: StaticInitializationTest.s_messages
057: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[0]);
058: }
059:
060: /**
061: * @Before staticInitialization
062: */
063: public void beforeStaticInitialization(StaticJoinPoint sjp) {
064: StaticInitializationTest.s_staticJoinPoints.add(sjp);
065: }
066:
067: /**
068: * @Before staticServiceInitialization
069: */
070: public void beforeStaticServiceInitialization(StaticJoinPoint sjp) {
071: StaticInitializationTest.s_staticJoinPoints.add(sjp);
072: }
073:
074: /**
075: * @Before staticPatternInitialization
076: */
077: public void beforeStaticPatternInitialization(StaticJoinPoint sjp) {
078: StaticInitializationTest.s_staticJoinPoints.add(sjp);
079: }
080:
081: /**
082: * @Before staticInitialization
083: */
084: public void beforeStaticInitialization(JoinPoint jp) {
085: StaticInitializationTest.s_joinPoints.add(jp);
086: }
087:
088: /**
089: * @Before staticServiceInitialization
090: */
091: public void beforeStaticServiceInitialization(JoinPoint jp) {
092: StaticInitializationTest.s_joinPoints.add(jp);
093: }
094:
095: /**
096: * @Before staticPatternInitialization
097: */
098: public void beforeStaticPatternInitialization(JoinPoint jp) {
099: StaticInitializationTest.s_joinPoints.add(jp);
100: }
101:
102: /**
103: * @Around staticInitialization
104: */
105: public Object aroundStaticInitialization(StaticJoinPoint sjp)
106: throws Throwable {
107: StaticInitializationTest.s_messages
108: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[1]);
109: StaticInitializationTest.s_staticJoinPoints.add(sjp);
110:
111: return sjp.proceed();
112: }
113:
114: /**
115: * @Around staticServiceInitialization
116: */
117: public Object aroundStaticServiceInitialization(StaticJoinPoint sjp)
118: throws Throwable {
119: StaticInitializationTest.s_messages
120: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[1]);
121: StaticInitializationTest.s_staticJoinPoints.add(sjp);
122:
123: return sjp.proceed();
124: }
125:
126: /**
127: * @Around staticPatternInitialization
128: */
129: public Object aroundStaticPatternInitialization(StaticJoinPoint sjp)
130: throws Throwable {
131: StaticInitializationTest.s_messages
132: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[1]);
133: StaticInitializationTest.s_staticJoinPoints.add(sjp);
134:
135: return sjp.proceed();
136: }
137:
138: /**
139: * @Around staticInitialization
140: */
141: public Object aroundStaticInitialization(JoinPoint jp)
142: throws Throwable {
143: StaticInitializationTest.s_messages
144: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[2]);
145: StaticInitializationTest.s_joinPoints.add(jp);
146:
147: return jp.proceed();
148: }
149:
150: /**
151: * @Around staticServiceInitialization
152: */
153: public Object aroundStaticServiceInitialization(JoinPoint jp)
154: throws Throwable {
155: StaticInitializationTest.s_messages
156: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[2]);
157: StaticInitializationTest.s_joinPoints.add(jp);
158:
159: return jp.proceed();
160: }
161:
162: /**
163: * @Around staticPatternInitialization
164: */
165: public Object aroundStaticPatternInitialization(JoinPoint jp)
166: throws Throwable {
167: StaticInitializationTest.s_messages
168: .add(StaticInitializationTest.BEFORE_EXPECTED_MESSAGES[2]);
169: StaticInitializationTest.s_joinPoints.add(jp);
170:
171: return jp.proceed();
172: }
173:
174: /**
175: * @AfterReturning staticInitialization
176: */
177: public void afterReturningStaticInitializer() {
178: StaticInitializationTest.s_messages
179: .add(StaticInitializationTest.AFTER_EXPECTED_MESSAGES[0]);
180: }
181:
182: /**
183: * @AfterReturning staticServiceInitialization
184: */
185: public void afterReturningServiceInitializer() {
186: StaticInitializationTest.s_messages
187: .add(StaticInitializationTest.AFTER_EXPECTED_MESSAGES[0]);
188: }
189:
190: /**
191: * @AfterReturning staticPatternInitialization
192: */
193: public void afterReturningPatternInitializer() {
194: StaticInitializationTest.s_messages
195: .add(StaticInitializationTest.AFTER_EXPECTED_MESSAGES[0]);
196: }
197:
198: /**
199: * @AfterReturning staticInitialization
200: */
201: public void afterReturningStaticInitializer(StaticJoinPoint sjp) {
202: StaticInitializationTest.s_staticJoinPoints.add(sjp);
203: }
204:
205: /**
206: * @AfterReturning staticServiceInitialization
207: */
208: public void afterReturningServiceInitializer(StaticJoinPoint sjp) {
209: StaticInitializationTest.s_staticJoinPoints.add(sjp);
210: }
211:
212: /**
213: * @AfterReturning staticPatternInitialization
214: */
215: public void afterReturningPatternInitializer(StaticJoinPoint sjp) {
216: StaticInitializationTest.s_staticJoinPoints.add(sjp);
217: }
218:
219: /**
220: * @AfterReturning staticInitialization
221: */
222: public void afterReturningStaticInitializer(JoinPoint jp) {
223: StaticInitializationTest.s_joinPoints.add(jp);
224: }
225:
226: /**
227: * @AfterReturning staticServiceInitialization
228: */
229: public void afterReturningServiceInitializer(JoinPoint jp) {
230: StaticInitializationTest.s_joinPoints.add(jp);
231: }
232:
233: /**
234: * @AfterReturning staticPatternInitialization
235: */
236: public void afterReturningPatternInitializer(JoinPoint jp) {
237: StaticInitializationTest.s_joinPoints.add(jp);
238: }
239:
240: /**
241: * @After staticInitialization
242: */
243: public void afterStaticInitializer() {
244: StaticInitializationTest.s_messages
245: .add(StaticInitializationTest.AFTER_EXPECTED_MESSAGES[1]);
246: }
247:
248: /**
249: * @After staticServiceInitialization
250: */
251: public void afterServiceInitializer() {
252: StaticInitializationTest.s_messages
253: .add(StaticInitializationTest.AFTER_EXPECTED_MESSAGES[1]);
254: }
255:
256: /**
257: * @After staticPatternInitialization
258: */
259: public void afterPatternInitializer() {
260: StaticInitializationTest.s_messages
261: .add(StaticInitializationTest.AFTER_EXPECTED_MESSAGES[1]);
262: }
263:
264: /**
265: * @After staticInitialization
266: */
267: public void afterStaticInitializer(StaticJoinPoint sjp) {
268: StaticInitializationTest.s_staticJoinPoints.add(sjp);
269: }
270:
271: /**
272: * @After staticServiceInitialization
273: */
274: public void afterServiceInitializer(StaticJoinPoint sjp) {
275: StaticInitializationTest.s_staticJoinPoints.add(sjp);
276: }
277:
278: /**
279: * @After staticPatternInitialization
280: */
281: public void afterPatternInitializer(StaticJoinPoint sjp) {
282: StaticInitializationTest.s_staticJoinPoints.add(sjp);
283: }
284:
285: /**
286: * @After staticInitialization
287: */
288: public void afterStaticInitializer(JoinPoint jp) {
289: StaticInitializationTest.s_joinPoints.add(jp);
290: }
291:
292: /**
293: * @After staticServiceInitialization
294: */
295: public void afterServiceInitializer(JoinPoint jp) {
296: StaticInitializationTest.s_joinPoints.add(jp);
297: }
298:
299: /**
300: * @After staticPatternInitialization
301: */
302: public void afterPatternInitializer(JoinPoint jp) {
303: StaticInitializationTest.s_joinPoints.add(jp);
304: }
305: }
|