1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.HashMap ; 22 23 import org.apache.log4j.Category; 24 25 import alt.jiapi.reflect.InstructionList; 26 import alt.jiapi.reflect.JiapiClass; 27 import alt.jiapi.reflect.JiapiMethod; 28 29 37 public abstract class AbstractInstrumentor implements ChainInstrumentor { 38 private Instrumentation instrumentation; 39 private static Category log = alt.jiapi.Runtime.getLogCategory(AbstractInstrumentor.class); 40 private AbstractInstrumentor child; 41 42 53 public InstrumentorChain preInstrument() { 54 return null; 55 } 56 57 67 public InstrumentorChain postInstrument() { 68 return null; 69 } 70 71 85 public abstract void instrument(InstructionList il); 86 87 91 void instrument(InstructionList il, Instrumentation i) { 92 log.info("Instrumenting with " + this); 93 this.instrumentation = i; 94 if (i == null) { 95 log.error("Got null instrumentation"); 96 } 97 98 instrument(il); 99 } 100 101 102 public String toString() { 103 return this.getClass().getName(); 104 } 105 106 107 108 111 116 protected void forward(InstructionList il) { 117 if (child != null) { 118 JiapiClass jc = getCurrentClass(); 119 child.setCurrentClass(jc); 120 121 InstrumentorChain pre = child.preInstrument(); 122 if (pre != null) { 123 log.debug("Pre instrumenting with " + pre); 125 pre.instrument(jc); 127 } 130 else { 131 log.debug(child + " has no need for pre-instrumentation"); 132 } 133 134 child.instrument(il, instrumentation); 135 136 InstrumentorChain post = child.postInstrument(); 137 if (post != null) { 138 log.debug("Post instrumenting with " + post); 140 post.instrument(jc); 141 } 144 else { 145 log.debug(child + " has no need for post-instrumentation"); 146 } 147 } 148 } 149 150 151 private JiapiClass currentClass; 152 153 158 protected JiapiClass getCurrentClass() { 159 return currentClass; 160 } 161 162 167 void setCurrentClass(JiapiClass clazz) { 168 this.currentClass = clazz; 169 } 170 171 176 177 184 public Instrumentation getInstrumentation() { 185 if(instrumentation == null) { 189 log.warn("Instrumentation is null: " + this.getClass()); 190 } 191 192 return instrumentation; 193 } 194 195 196 197 void setDescriptorData() { 201 } 202 Object getDescriptorData() { 203 return null; 204 } 205 206 207 void setContexData() { 211 } 212 Object getContextData() { 213 return null; 214 } 215 216 217 218 219 void setChild(AbstractInstrumentor i) { 221 this.child = i; 222 } 223 224 227 ChainInstrumentor getChild() { 228 return child; 229 } 230 } 231 232 | Popular Tags |