001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package examples.logging;
008:
009: import org.codehaus.aspectwerkz.annotation.Annotation;
010: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
011: import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
012: import org.codehaus.aspectwerkz.definition.Pointcut;
013: import org.codehaus.aspectwerkz.definition.Pointcut;
014:
015: /**
016: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
017: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
018: */
019: public class ArgAspect {
020:
021: private int m_level = 0;
022:
023: /**
024: * @Around pc1(ai, as)
025: */
026: public Object around1(final JoinPoint joinPoint, int ai, String as)
027: throws Throwable {
028: indent();
029: m_level++;
030: System.out.println(" ==> around1 -- pre " + ai + ", " + as);
031: Object result = joinPoint.proceed();
032: m_level--;
033: indent();
034: System.out.println(" ==> around1 -- post " + ai + ", " + as);
035: return result;
036: }
037:
038: /**
039: * @Before pc1(ai, as)
040: */
041: public void before1(final JoinPoint joinPoint, int ai, String as)
042: throws Throwable {
043: indent();
044: m_level++;
045: System.out.println(" ==> before1: " + ai + ", " + as);
046: }
047:
048: /**
049: * @After pc1(ai, as)
050: */
051: public void after1(final JoinPoint joinPoint, int ai, String as)
052: throws Throwable {
053: m_level--;
054: indent();
055: System.out.println(" ==> after1: " + ai + ", " + as);
056: }
057:
058: /**
059: * @Before pc1(ai, as)
060: */
061: public void before2(final JoinPoint joinPoint, String as, int ai)
062: throws Throwable {
063: indent();
064: m_level++;
065: System.out.println(" ==> before2: " + as + ", " + ai);
066: }
067:
068: /**
069: * @After pc1(ai, as)
070: */
071: public void after2(final JoinPoint joinPoint, String as, int ai)
072: throws Throwable {
073: m_level--;
074: indent();
075: System.out.println(" ==> after2: " + as + ", " + ai);
076: }
077:
078: /**
079: * @Around pc2(sarr)
080: */
081: public Object around3(final JoinPoint joinPoint, String[] sarr)
082: throws Throwable {
083: indent();
084: m_level++;
085: System.out.println("==> around3 -- pre " + sarr);
086: Object result = joinPoint.proceed();
087: m_level--;
088: indent();
089: System.out.println("==> around3 -- post " + sarr);
090: return result;
091: }
092:
093: /**
094: * @Before pc2(sarr)
095: */
096: public void before3(final JoinPoint joinPoint, String[] sarr)
097: throws Throwable {
098: indent();
099: m_level++;
100: System.out.println("==> before3: " + sarr);
101: }
102:
103: /**
104: * @After pc2(sarr)
105: */
106: public void after3(final JoinPoint joinPoint, String[] sarr)
107: throws Throwable {
108: m_level--;
109: indent();
110: System.out.println("==> after3: " + sarr);
111: }
112:
113: /**
114: * @Around pcSet || pcGet
115: */
116: public Object aroundField(final JoinPoint joinPoint)
117: throws Throwable {
118: indent();
119: m_level++;
120: System.out.println("==> aroundField -- pre");
121: Object result = joinPoint.proceed();
122: m_level--;
123: indent();
124: System.out.println("==> aroundField -- post");
125: return result;
126: }
127:
128: /**
129: * @Before pcSet || pcGet
130: */
131: public void beforeField(final JoinPoint joinPoint) throws Throwable {
132: indent();
133: m_level++;
134: System.out.println("==> beforeField");
135: }
136:
137: /**
138: * @After pcSet || pcGet
139: */
140: public void after3(final JoinPoint joinPoint) throws Throwable {
141: m_level--;
142: indent();
143: System.out.println("==> beforeField");
144: }
145:
146: /**
147: * @Expression execution(* ..ArgLoggingTarget.toLog*(..)) && args(int, s, i)
148: */
149: Pointcut pc1(int i, String s) {
150: return null;
151: }
152:
153: /**
154: * @Expression execution(* ..ArgLoggingTarget.toLog*(..)) && args(int, sarr)
155: */
156: Pointcut pc2(String[] sarr) {
157: return null;
158: }
159:
160: /**
161: * @Expression execution(* ..ArgLoggingTarget.toLog*(..))
162: */
163: Pointcut pc3() {
164: return null;
165: }
166:
167: /**
168: * @Expression set(* ..ArgLoggingTarget.*)
169: */
170: Pointcut pcSet() {
171: return null;
172: }
173:
174: /**
175: * @Expression get(* ..ArgLoggingTarget.*)
176: */
177: Pointcut pcGet() {
178: return null;
179: }
180:
181: private void indent() {
182: for (int i = 0; i < m_level; i++) {
183: System.out.print(" ");
184: }
185: }
186: }
|