KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > modifier > 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.modifier;
9
10 import org.codehaus.aspectwerkz.definition.Pointcut;
11 import org.codehaus.aspectwerkz.definition.Pointcut;
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 TestAspect {
19     // ============ Pointcuts ============
20

21     /**
22      * @Expression call(private * test.modifier.*.*Method(..)) && within(test.modifier.*)
23      */

24     Pointcut call_privateMethod;
25
26     /**
27      * @Expression call(protected * test.modifier.*.*Method(..)) && within(test.modifier.*)
28      */

29     Pointcut call_protectedMethod;
30
31     /**
32      * @Expression call(public * test.modifier.*.*Method(..)) && within(test.modifier.*)
33      */

34     Pointcut call_publicMethod;
35
36     /**
37      * @Expression call(static final * test.modifier.*.*Method(..)) && within(test.modifier.*)
38      */

39     Pointcut call_staticFinalMethod;
40
41     /**
42      * @Expression execution(private * test.modifier.*.*Method(..))
43      */

44     Pointcut execution_privateMethod;
45
46     /**
47      * @Expression execution(protected * test.modifier.*.*Method(..))
48      */

49     Pointcut execution_protectedMethod;
50
51     /**
52      * @Expression execution(public * test.modifier.*.*Method(..))
53      */

54     Pointcut execution_publicMethod;
55
56     /**
57      * @Expression get(private * test.modifier.*.*Field) && within(test.modifier.*)
58      */

59     Pointcut get_privateField;
60
61     /**
62      * @Expression get(protected * test.modifier.*.*Field) && within(test.modifier.*)
63      */

64     Pointcut get_protectedField;
65
66     /**
67      * @Expression get(public * test.modifier.*.*Field) && within(test.modifier.*)
68      */

69     Pointcut get_publicField;
70
71     /**
72      * @Expression set(private * test.modifier.*.*Field) && within(test.modifier.*)
73      */

74     Pointcut set_privateField;
75
76     /**
77      * @Expression set(protected * test.modifier.*.*Field) && within(test.modifier.*)
78      */

79     Pointcut set_protectedField;
80
81     /**
82      * @Expression set(public * test.modifier.*.*Field) && within(test.modifier.*)
83      */

84     Pointcut set_publicField;
85
86     // ============ Advices ============
87

88     /**
89      * @Around call_privateMethod || call_publicMethod || call_protectedMethod ||
90      * call_staticFinalMethod
91      */

92     public Object JavaDoc advice_CALL(final JoinPoint joinPoint) throws Throwable JavaDoc {
93         ModifierTest.log("call ");
94         Object JavaDoc result = joinPoint.proceed();
95         ModifierTest.log("call ");
96         return result;
97     }
98
99     /**
100      * @Around execution_privateMethod || execution_protectedMethod || execution_publicMethod
101      */

102     public Object JavaDoc advice_EXECUTION(final JoinPoint joinPoint) throws Throwable JavaDoc {
103         ModifierTest.log("execution ");
104         Object JavaDoc result = joinPoint.proceed();
105         ModifierTest.log("execution ");
106         return result;
107     }
108
109     /**
110      * @Around set_privateField || set_protectedField || set_publicField
111      */

112     public Object JavaDoc advice_SET(final JoinPoint joinPoint) throws Throwable JavaDoc {
113         ModifierTest.log("set ");
114         Object JavaDoc result = joinPoint.proceed();
115         ModifierTest.log("set ");
116         return result;
117     }
118
119     /**
120      * @Around get_privateField || get_protectedField || get_publicField
121      */

122     public Object JavaDoc advice_GET(final JoinPoint joinPoint) throws Throwable JavaDoc {
123         ModifierTest.log("get ");
124         Object JavaDoc result = joinPoint.proceed();
125         ModifierTest.log("get ");
126         return result;
127     }
128 }
Popular Tags