1 22 package org.jboss.aop.instrument; 23 24 import javassist.CannotCompileException; 25 import javassist.CtClass; 26 import javassist.CtField; 27 import javassist.Modifier; 28 import javassist.NotFoundException; 29 30 36 public abstract class CallerInfoAdder 37 { 38 Instrumentor instrumentor; 39 int infoModifier = Modifier.PRIVATE | Modifier.STATIC; 40 41 protected CallerInfoAdder(Instrumentor instrumentor) 42 { 43 this.instrumentor = instrumentor; 44 } 45 46 protected CallerInfoAdder(Instrumentor instrumentor, int mod) 47 { 48 this.instrumentor = instrumentor; 49 infoModifier = mod; 50 } 51 52 protected abstract void addMethodByMethodInfoField(CtClass addTo, String fieldName, long callingHash, String classname, long calledHash) throws NotFoundException, CannotCompileException; 53 54 protected abstract void addConByMethodInfoField(CtClass addTo, String fieldName, long callingHash, String classname, long calledHash) throws NotFoundException, CannotCompileException; 55 56 protected abstract void addConByConInfoField(CtClass addTo, String fieldName, int callingIndex, String classname, long calledHash) throws NotFoundException, CannotCompileException; 57 58 protected abstract void addMethodByConInfoField(CtClass addTo, String fieldName, int callingIndex, String classname, long calledHash) throws NotFoundException, CannotCompileException; 59 60 61 protected void addConByConInfoField(CtClass addTo, String fieldName, String init) throws NotFoundException, CannotCompileException 62 { 63 addField(addTo, "org.jboss.aop.ConByConInfo", fieldName, init); 64 } 65 66 protected void addConByMethodInfoField(CtClass addTo, String fieldName, 67 String init) throws NotFoundException, CannotCompileException 68 { 69 addField(addTo, "org.jboss.aop.ConByMethodInfo", fieldName, init); 70 } 71 72 protected void addMethodByConInfoField(CtClass addTo, String fieldName, 73 String init) throws NotFoundException, CannotCompileException 74 { 75 addField(addTo, "org.jboss.aop.MethodByConInfo", fieldName, init); 76 } 77 78 protected void addMethodByMethodInfoField(CtClass addTo, String fieldName, 79 String init) throws NotFoundException, CannotCompileException 80 { 81 addField(addTo, "org.jboss.aop.MethodByMethodInfo", fieldName, init); 82 } 83 84 private void addField(CtClass addTo, String typeName, String fieldName, 85 String init) throws NotFoundException, CannotCompileException 86 { 87 CtField.Initializer initializer = (init != null ) ? CtField.Initializer.byExpr(init) : null; 88 TransformerCommon.addInfoField(instrumentor, typeName, fieldName, infoModifier, addTo, addInfoAsWeakReference(), initializer); 89 } 90 91 protected abstract boolean addInfoAsWeakReference(); 92 } 93 | Popular Tags |