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.callAndExecution;
9
10 import org.codehaus.aspectwerkz.Pointcut;
11 import org.codehaus.aspectwerkz.CrossCuttingInfo;
12 import org.codehaus.aspectwerkz.DeploymentModel;
13 import org.codehaus.aspectwerkz.annotation.AspectAnnotationProxy;
14 import org.codehaus.aspectwerkz.annotation.Annotations;
15 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
16
17 /***
18 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
19 *
20 * @Aspect perThread
21 */
22 public class TestAspect {
23
24 public TestAspect(CrossCuttingInfo info) {
25 System.out.println("TEST say: " + ((AspectAnnotationProxy)Annotations.getAnnotation("Aspect", getClass())).getName());
26 System.out.println("TEST say: " + (info.getDeploymentModel() == DeploymentModel.PER_THREAD));
27 System.out.println("TEST say: " + (info.getDeploymentModel() == DeploymentModel.PER_JVM));
28 }
29
30
31
32 /***
33 * @Expression call(void test.callAndExecution.CallExecutionTest.privateMethod()) &&
34 * within(test.callAndExecution.*)
35 */
36 Pointcut call1;
37
38 /***
39 * @Expression call(void test.callAndExecution.CallExecutionTest.publicMethod()) &&
40 * within(test.callAndExecution.*)
41 */
42 Pointcut call2;
43
44 /***
45 * @Expression call(void test.callAndExecution.Intf+.called()) &&
46 * within(test.callAndExecution.*)
47 */
48 Pointcut callIntf;
49
50 /***
51 * @Expression call(void test.callAndExecution.Abstract+.called()) &&
52 * within(test.callAndExecution.*)
53 */
54 Pointcut callAbstract;
55
56 /***
57 * @Expression execution(void test.callAndExecution.CallExecutionTest.privateMethod())
58 */
59 Pointcut execution1;
60
61 /***
62 * @Expression execution(void test.callAndExecution.CallExecutionTest.publicMethod())
63 */
64 Pointcut execution2;
65
66 /***
67 * @Expression execution(void test.callAndExecution.Intf+.called())
68 */
69 Pointcut executionIntf;
70
71 /***
72 * @Expression execution(void test.callAndExecution.Abstract+.called())
73 */
74 Pointcut executionAbstract;
75
76
77
78 /***
79 * @Around call1 || call2 || callIntf || callAbstract
80 */
81 public Object advice1(final JoinPoint joinPoint) throws Throwable {
82 CallExecutionTest.log("call1 ");
83 Object result = joinPoint.proceed();
84 CallExecutionTest.log("call2 ");
85 return result;
86 }
87
88 /***
89 * @Around execution1 || execution2 || executionIntf || executionAbstract
90 */
91 public Object advice2(final JoinPoint joinPoint) throws Throwable {
92 CallExecutionTest.log("execution1 ");
93 Object result = joinPoint.proceed();
94 CallExecutionTest.log("execution2 ");
95 return result;
96 }
97 }