KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > callAndExecution > TestAspect


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.definition.Pointcut;
11 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
12
13 /**
14  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
15  */

16 public class TestAspect {
17     // ============ Pointcuts ============
18

19     /**
20      * @Expression call(void test.callAndExecution.CallExecutionTest.privateMethod()) &&
21      * within(test.callAndExecution.*)
22      */

23     Pointcut call1;
24
25     /**
26      * @Expression call(void test.callAndExecution.CallExecutionTest.publicMethod()) &&
27      * within(test.callAndExecution.*)
28      */

29     Pointcut call2;
30
31     /**
32      * @Expression call(void test.callAndExecution.Intf+.called()) &&
33      * within(test.callAndExecution.*)
34      */

35     Pointcut callIntf;
36
37     /**
38      * @Expression call(void test.callAndExecution.Abstract+.called()) &&
39      * within(test.callAndExecution.*)
40      */

41     Pointcut callAbstract;
42
43     /**
44      * @Expression execution(void test.callAndExecution.CallExecutionTest.privateMethod())
45      */

46     Pointcut execution1;
47
48     /**
49      * @Expression execution(void test.callAndExecution.CallExecutionTest.publicMethod())
50      */

51     Pointcut execution2;
52
53     /**
54      * @Expression execution(void test.callAndExecution.Intf+.called())
55      */

56     Pointcut executionIntf;
57
58     /**
59      * @Expression execution(void test.callAndExecution.Abstract+.called())
60      */

61     Pointcut executionAbstract;
62
63     // ============ Advices ============
64

65     /**
66      * @Around call1 || call2 || callIntf || callAbstract
67      */

68     public Object JavaDoc advice1(final JoinPoint joinPoint) throws Throwable JavaDoc {
69         CallExecutionTest.log("call1 ");
70         Object JavaDoc result = joinPoint.proceed();
71         CallExecutionTest.log("call2 ");
72         return result;
73     }
74
75     /**
76      * @Around execution1 || execution2 || executionIntf || executionAbstract
77      */

78     public Object JavaDoc advice2(final JoinPoint joinPoint) throws Throwable JavaDoc {
79         CallExecutionTest.log("execution1 ");
80         Object JavaDoc result = joinPoint.proceed();
81         CallExecutionTest.log("execution2 ");
82         return result;
83     }
84 }
Popular Tags