1 18 19 package alt.jiapi.interceptor; 20 21 import java.lang.reflect.Field ; 22 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import org.apache.log4j.Category; 28 29 import alt.jiapi.InstrumentationContext; 30 import alt.jiapi.InstrumentationDescriptor; 31 import alt.jiapi.reflect.Signature; 32 33 import alt.jiapi.event.EventProducer; 34 35 57 public class FieldInterceptor extends EventProducer { 58 private AccessAdvisor advisor; 59 60 67 public FieldInterceptor(InstrumentationDescriptor id, 68 AccessAdvisor advisor){ 69 this(id, "*", advisor); 70 } 71 72 73 83 public FieldInterceptor(InstrumentationDescriptor id, 84 String resolution, AccessAdvisor advisor){ 85 this(id, new String [] { resolution }, advisor); 86 } 87 88 89 98 public FieldInterceptor(InstrumentationDescriptor id, 99 String [] resolutions, 100 AccessAdvisor advisor) { 101 super(resolutions); 102 this.advisor = advisor; 103 104 id.addInstrumentor(new FieldAdvisorInstrumentor(this, advisor)); 105 } 106 107 108 109 120 public Object setField(Object o, String name, Object value) { 121 try { 122 return advisor.set(o, name, value); 123 } 124 catch(Throwable t) { 125 t.printStackTrace(); 126 } 127 128 return value; 129 } 130 131 public Object getField(Object o, String name, Object value) { 132 try { 133 return advisor.get(o, name, value); 134 } 135 catch(Throwable t) { 136 t.printStackTrace(); 137 } 138 139 return value; 140 } 141 } 142 143 | Popular Tags |