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