1 17 18 package org.objectweb.jac.aspects.tracing; 19 20 import org.aopalliance.intercept.ConstructorInvocation; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.objectweb.jac.core.*; 23 24 32 33 public class SimpleCountingWrapper extends Wrapper { 34 35 36 Counter counter = null; 37 38 42 43 public SimpleCountingWrapper(AspectComponent ac, Counter counter) { 44 super(ac); 45 this.counter = counter; 46 } 47 48 53 54 public Object incr(Interaction interaction) { 55 Object ret = proceed(interaction); 56 counter.incr(1); 57 printCounter(); 58 return ret; 59 } 60 61 66 67 public void setCounter(int value) { 68 counter.set(value); 69 } 70 71 76 77 public int getCounter() { 78 return counter.get(); 79 } 80 81 84 public void printCounter() { 85 System.out.println("<<< Counting aspect says : " + 86 counter.get() + 87 " line(s) printed. >>>"); 88 } 89 90 public Object invoke(MethodInvocation invocation) throws Throwable { 91 return incr((Interaction)invocation); 92 } 93 94 public Object construct(ConstructorInvocation invocation) throws Throwable { 95 return incr((Interaction)invocation); 96 } 97 98 } 99 100 101 102 | Popular Tags |