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.constructor;
9   
10  import org.codehaus.aspectwerkz.Pointcut;
11  import org.codehaus.aspectwerkz.joinpoint.ConstructorSignature;
12  import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
13  
14  /***
15   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
16   * @Aspect perJVM
17   */
18  public class ConstructorTestAspect {
19      // ============ Pointcuts ============
20  
21      /***
22       * @Expression call(test.constructor.TestAroundAdvice.new(..)) && withincode(*
23       *             test.constructor.*.*(..))
24       */
25      Pointcut call1;
26  
27      /***
28       * @Expression call(test.constructor.TestBeforeAdvice.new()) && within(test.constructor.*)
29       */
30      Pointcut call2;
31  
32      /***
33       * @Expression call(test.constructor.TestAfterAdvice.new(String)) && within(test.constructor.*)
34       */
35      Pointcut call3;
36  
37      /***
38       * @Expression call(test.constructor.TestBeforeAfterAdvice.new(String[])) && withincode(*
39       *             test.constructor.*.*(..))
40       */
41      Pointcut call4;
42  
43      /***
44       * @Expression call(test.constructor.TestReturnFalseType.new()) && withincode(*
45       *             test.constructor.*.*(..))
46       */
47      Pointcut call5;
48  
49      /***
50       * @Expression execution(test.constructor.TestAroundAdvice.new(..))
51       */
52      Pointcut execution1;
53  
54      /***
55       * @Expression execution(test.constructor.TestBeforeAdvice.new())
56       */
57      Pointcut execution2;
58  
59      /***
60       * @Expression execution(test.constructor.TestAfterAdvice.new(String))
61       */
62      Pointcut execution3;
63  
64      /***
65       * @Expression execution(test.constructor.TestBeforeAfterAdvice.new(String[]))
66       */
67      Pointcut execution4;
68  
69      /***
70       * @Expression execution(test.constructor.TestReturnFalseType.new())
71       */
72      Pointcut execution5;
73  
74      // ============ Advices ============
75  
76      /***
77       * @Around call1
78       */
79      public Object aroundCall(final JoinPoint joinPoint) throws Throwable {
80          ConstructorAdviceTest.logCall("beforeCall ");
81          final Object result = joinPoint.proceed();
82          ConstructorAdviceTest.logCall("afterCall ");
83          return result;
84      }
85  
86      /***
87       * @Before call2 || call4
88       */
89      public void beforeCall(final JoinPoint joinPoint) throws Throwable {
90          ConstructorAdviceTest.logCall("preCall ");
91      }
92  
93      /***
94       * @After call3 ||call4
95       */
96      public void afterCall(final JoinPoint joinPoint) throws Throwable {
97          ConstructorAdviceTest.logCall("postCall ");
98          ConstructorSignature sig = (ConstructorSignature) joinPoint.getSignature();
99      }
100 
101     /***
102      * @Around call5
103      */
104     public Object aroundCall2(final JoinPoint joinPoint) throws Throwable {
105         return new Integer(0);
106     }
107 
108     /***
109      * @Around execution1
110      */
111     public Object aroundExecution(final JoinPoint joinPoint) throws Throwable {
112         ConstructorAdviceTest.logExecution("beforeExecution ");
113         final Object result = joinPoint.proceed();
114         ConstructorAdviceTest.logExecution("afterExecution ");
115         return result;
116     }
117 
118     /***
119      * @Before execution2 || execution4
120      */
121     public void beforeExecution(final JoinPoint joinPoint) throws Throwable {
122         ConstructorAdviceTest.logExecution("preExecution ");
123     }
124 
125     /***
126      * @After execution3 || execution4
127      */
128     public void afterExecution(final JoinPoint joinPoint) throws Throwable {
129         ConstructorAdviceTest.logExecution("postExecution ");
130     }
131 
132     /***
133      * @Around execution5
134      */
135     public Object aroundExecution2(final JoinPoint joinPoint) throws Throwable {
136         return new Integer(0);
137     }
138 }