KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > logging > ArgAspect


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 examples.logging;
9
10 import org.codehaus.aspectwerkz.annotation.Annotation;
11 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
12 import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
13 import org.codehaus.aspectwerkz.definition.Pointcut;
14 import org.codehaus.aspectwerkz.definition.Pointcut;
15
16 /**
17  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
18  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
19  */

20 public class ArgAspect {
21
22     private int m_level = 0;
23
24     /**
25      * @Around pc1(ai, as)
26      */

27     public Object JavaDoc around1(final JoinPoint joinPoint, int ai, String JavaDoc as) throws Throwable JavaDoc {
28         indent();
29         m_level++;
30         System.out.println(" ==> around1 -- pre " + ai + ", " + as);
31         Object JavaDoc result = joinPoint.proceed();
32         m_level--;
33         indent();
34         System.out.println(" ==> around1 -- post " + ai + ", " + as);
35         return result;
36     }
37
38     /**
39      * @Before pc1(ai, as)
40      */

41     public void before1(final JoinPoint joinPoint, int ai, String JavaDoc as) throws Throwable JavaDoc {
42         indent();
43         m_level++;
44         System.out.println(" ==> before1: " + ai + ", " + as);
45     }
46
47     /**
48      * @After pc1(ai, as)
49      */

50     public void after1(final JoinPoint joinPoint, int ai, String JavaDoc as) throws Throwable JavaDoc {
51         m_level--;
52         indent();
53         System.out.println(" ==> after1: " + ai + ", " + as);
54     }
55
56     /**
57      * @Before pc1(ai, as)
58      */

59     public void before2(final JoinPoint joinPoint, String JavaDoc as, int ai) throws Throwable JavaDoc {
60         indent();
61         m_level++;
62         System.out.println(" ==> before2: " + as + ", " + ai);
63     }
64
65     /**
66      * @After pc1(ai, as)
67      */

68     public void after2(final JoinPoint joinPoint, String JavaDoc as, int ai) throws Throwable JavaDoc {
69         m_level--;
70         indent();
71         System.out.println(" ==> after2: " + as + ", " + ai);
72     }
73
74     /**
75      * @Around pc2(sarr)
76      */

77     public Object JavaDoc around3(final JoinPoint joinPoint, String JavaDoc[] sarr) throws Throwable JavaDoc {
78         indent();
79         m_level++;
80         System.out.println("==> around3 -- pre " + sarr);
81         Object JavaDoc result = joinPoint.proceed();
82         m_level--;
83         indent();
84         System.out.println("==> around3 -- post " + sarr);
85         return result;
86     }
87
88     /**
89      * @Before pc2(sarr)
90      */

91     public void before3(final JoinPoint joinPoint, String JavaDoc[] sarr) throws Throwable JavaDoc {
92         indent();
93         m_level++;
94         System.out.println("==> before3: " + sarr);
95     }
96
97     /**
98      * @After pc2(sarr)
99      */

100     public void after3(final JoinPoint joinPoint, String JavaDoc[] sarr) throws Throwable JavaDoc {
101         m_level--;
102         indent();
103         System.out.println("==> after3: " + sarr);
104     }
105
106     /**
107      * @Around pcSet || pcGet
108      */

109     public Object JavaDoc aroundField(final JoinPoint joinPoint) throws Throwable JavaDoc {
110         indent();
111         m_level++;
112         System.out.println("==> aroundField -- pre");
113         Object JavaDoc result = joinPoint.proceed();
114         m_level--;
115         indent();
116         System.out.println("==> aroundField -- post");
117         return result;
118     }
119
120     /**
121      * @Before pcSet || pcGet
122      */

123     public void beforeField(final JoinPoint joinPoint) throws Throwable JavaDoc {
124         indent();
125         m_level++;
126         System.out.println("==> beforeField");
127     }
128
129     /**
130      * @After pcSet || pcGet
131      */

132     public void after3(final JoinPoint joinPoint) throws Throwable JavaDoc {
133         m_level--;
134         indent();
135         System.out.println("==> beforeField");
136     }
137
138     /**
139      * @Expression execution(* ..ArgLoggingTarget.toLog*(..)) && args(int, s, i)
140      */

141     Pointcut pc1(int i, String JavaDoc s) {
142         return null;
143     }
144
145     /**
146      * @Expression execution(* ..ArgLoggingTarget.toLog*(..)) && args(int, sarr)
147      */

148     Pointcut pc2(String JavaDoc[] sarr) {
149         return null;
150     }
151
152     /**
153      * @Expression execution(* ..ArgLoggingTarget.toLog*(..))
154      */

155     Pointcut pc3() {
156         return null;
157     }
158
159     /**
160      * @Expression set(* ..ArgLoggingTarget.*)
161      */

162     Pointcut pcSet() {
163         return null;
164     }
165
166     /**
167      * @Expression get(* ..ArgLoggingTarget.*)
168      */

169     Pointcut pcGet() {
170         return null;
171     }
172
173     private void indent() {
174         for (int i = 0; i < m_level; i++) {
175             System.out.print(" ");
176         }
177     }
178 }
Popular Tags