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.constructor;
008:
009: import org.codehaus.aspectwerkz.definition.Pointcut;
010: import org.codehaus.aspectwerkz.definition.Pointcut;
011: import org.codehaus.aspectwerkz.joinpoint.ConstructorSignature;
012: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
013:
014: /**
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: * @Aspect perJVM
017: */
018: public class ConstructorTestAspect {
019: // ============ Pointcuts ============
020:
021: /**
022: * @Expression call(test.constructor.TestAroundAdvice.new(..)) && withincode(*
023: * test.constructor.*.*(..))
024: */
025: Pointcut call1;
026:
027: /**
028: * @Expression call(test.constructor.TestBeforeAdvice.new()) && within(test.constructor.*)
029: */
030: Pointcut call2;
031:
032: /**
033: * @Expression call(test.constructor.TestAfterAdvice.new(String)) && within(test.constructor.*)
034: */
035: Pointcut call3;
036:
037: /**
038: * @Expression call(test.constructor.TestBeforeAfterAdvice.new(String[])) && withincode(*
039: * test.constructor.*.*(..))
040: */
041: Pointcut call4;
042:
043: /**
044: * @Expression call(test.constructor.TestReturnFalseType.new()) && withincode(*
045: * test.constructor.*.*(..))
046: */
047: Pointcut call5;
048:
049: /**
050: * @Expression execution(test.constructor.TestAroundAdvice.new(..))
051: */
052: Pointcut execution1;
053:
054: /**
055: * @Expression execution(test.constructor.TestBeforeAdvice.new())
056: */
057: Pointcut execution2;
058:
059: /**
060: * @Expression execution(test.constructor.TestAfterAdvice.new(String))
061: */
062: Pointcut execution3;
063:
064: /**
065: * @Expression execution(test.constructor.TestBeforeAfterAdvice.new(String[]))
066: */
067: Pointcut execution4;
068:
069: /**
070: * @Expression execution(test.constructor.TestReturnFalseType.new())
071: */
072: Pointcut execution5;
073:
074: // ============ Advices ============
075:
076: /**
077: * @Around call1
078: */
079: public Object aroundCall(final JoinPoint joinPoint)
080: throws Throwable {
081: ConstructorAdviceTest.logCall("beforeCall ");
082: final Object result = joinPoint.proceed();
083: ConstructorAdviceTest.logCall("afterCall ");
084: return result;
085: }
086:
087: /**
088: * @Before call2 || call4
089: */
090: public void beforeCall(final JoinPoint joinPoint) throws Throwable {
091: ConstructorAdviceTest.logCall("preCall ");
092: }
093:
094: /**
095: * @After call3 ||call4
096: */
097: public void afterCall(final JoinPoint joinPoint) throws Throwable {
098: ConstructorAdviceTest.logCall("postCall ");
099: ConstructorSignature sig = (ConstructorSignature) joinPoint
100: .getSignature();
101: }
102:
103: /**
104: * @Around call5 AND ! withincode(* test.constructor.*.testExecutionReturnFalseType(..))
105: */
106: public Object aroundCall2(final JoinPoint joinPoint)
107: throws Throwable {
108: return new Integer(0);
109: }
110:
111: /**
112: * @Around execution1
113: */
114: public Object aroundExecution(final JoinPoint joinPoint)
115: throws Throwable {
116: ConstructorAdviceTest.logExecution("beforeExecution ");
117: final Object result = joinPoint.proceed();
118: ConstructorAdviceTest.logExecution("afterExecution ");
119: return result;
120: }
121:
122: /**
123: * @Before execution2 || execution4
124: */
125: public void beforeExecution(final JoinPoint joinPoint)
126: throws Throwable {
127: ConstructorAdviceTest.logExecution("preExecution ");
128: }
129:
130: /**
131: * @After execution3 || execution4
132: */
133: public void afterExecution(final JoinPoint joinPoint)
134: throws Throwable {
135: ConstructorAdviceTest.logExecution("postExecution ");
136: }
137:
138: /**
139: * @Around execution5
140: */
141: public Object aroundExecution2(final JoinPoint joinPoint)
142: throws Throwable {
143: //TODO - to check - is that ok - ctor exe does not return new instance (too late, it is exec.)
144: ((TestReturnFalseType) joinPoint.getTarget()).m_updatedByAdvice = true;
145: return new Integer(0);//ignored
146: }
147: }
|