1 17 18 package org.objectweb.jac.aspects.tracing; 19 20 import java.util.*; 21 import org.aopalliance.intercept.ConstructorInvocation; 22 import org.aopalliance.intercept.MethodInvocation; 23 import org.objectweb.jac.core.*; 24 import org.objectweb.jac.core.rtti.ClassItem; 25 import org.objectweb.jac.core.rtti.ClassRepository; 26 27 40 41 public class OptimizedCountingWrapper extends SimpleCountingWrapper { 42 43 44 String field = null; 45 46 47 int arg = 0; 48 49 55 56 public OptimizedCountingWrapper(AspectComponent ac, Counter c, String field) { 57 super(ac,c); 58 this.field = field; 59 } 60 61 68 69 public OptimizedCountingWrapper(AspectComponent ac, Counter c, int arg) { 70 super(ac,c); 71 this.arg = arg; 72 } 73 74 81 82 public Object incrWithField(Interaction interaction) { 83 attrdef( "tracing.globalIncr", "" ); 84 Object ret = proceed(interaction); 85 ClassItem cl=ClassRepository.get().getClass(interaction.wrappee); 86 Object fval = cl.getField(field).get(interaction.wrappee); 87 if (fval == null) { 88 System.out.println( "<<< Counting aspect says: the field to count (" + 89 field + ") is null or does not exist... >>>" ); 90 return ret; 91 } 92 if (fval.getClass().isArray()) { 93 counter.incr(((Object [])fval).length); 94 } else if ( fval instanceof Collection ) { 95 counter.incr(((Collection)fval).size()); 96 } else { 97 98 System.out.println( "<<< Counting aspect says: the field to count (" + 99 field + ") is not of a supported type... >>>" ); 100 return ret; 101 } 102 printCounter(); 103 return ret; 104 } 105 106 113 114 public Object incrWithArg(Interaction interaction) { 115 attrdef( "tracing.globalIncr", "" ); 116 Object ret = proceed(interaction); 117 counter.incr( ((Integer )interaction.args[arg]).intValue() ); 118 printCounter(); 119 return ret; 120 } 121 122 public Object invoke(MethodInvocation invocation) throws Throwable { 123 if (field==null) 124 return incrWithArg((Interaction)invocation); 125 else 126 return incrWithField((Interaction)invocation); 127 } 128 129 public Object construct(ConstructorInvocation invocation) throws Throwable { 130 if (field==null) 131 return incrWithArg((Interaction)invocation); 132 else 133 return incrWithField((Interaction)invocation); 134 } 135 136 } 137 | Popular Tags |