1 18 19 package alt.jiapi; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.log4j.Category; 26 27 import alt.jiapi.reflect.JiapiClass; 28 import alt.jiapi.reflect.Loader; 29 30 40 public class InstrumentationContext { 41 private static Category log = Runtime.getLogCategory(InstrumentationContext.class); 42 43 private List descriptors = new ArrayList (); 44 private Loader loader; 45 46 49 public InstrumentationContext() { 50 loader = new Loader(); 51 } 52 53 60 public void addInstrumentationDescriptor(InstrumentationDescriptor id) { 61 descriptors.add(id); 62 } 63 64 69 public Loader getLoader() { 70 return loader; 71 } 72 73 79 public List getDescriptors() { 80 return descriptors; 81 } 82 83 90 public void instrument(JiapiClass clazz) { 91 List list = new ArrayList (); 92 for (Iterator i = getDescriptors().iterator(); i.hasNext(); ) { 93 InstrumentationDescriptor id = (InstrumentationDescriptor)i.next(); 94 95 if (id.match(clazz.getName())) { 96 list.addAll(id.getInstrumentors()); 97 } 98 } 99 100 if (!list.isEmpty()) { 101 Iterator i = list.iterator(); 102 long l1 = System.currentTimeMillis(); 103 while(i.hasNext()) { 104 Instrumentor instrumentor = (Instrumentor)i.next(); 105 instrumentor.instrument(clazz); 106 } 107 long l2 = System.currentTimeMillis(); 108 109 log.debug("It took " + (l2-l1) + " ms to instrument " + clazz); 110 } 111 else { 112 log.debug("No inclusion rules match " + clazz.getName()); 113 } 114 } 115 } 116 | Popular Tags |