1 package samples.event; 2 3 import alt.jiapi.InstrumentationContext; 4 import alt.jiapi.InstrumentationDescriptor; 5 import alt.jiapi.reflect.Loader; 6 import alt.jiapi.reflect.JiapiClass; 7 8 import alt.jiapi.event.FieldEvent; 9 import alt.jiapi.event.FieldEventProducer; 10 import alt.jiapi.event.FieldListener; 11 12 import alt.jiapi.util.Bootstrapper; 13 import alt.jiapi.util.InstrumentingClassLoader; 14 15 public class Sample2 implements FieldListener { 16 public static void main(String args[]) throws Exception { 17 new Sample2(); 18 } 19 20 public Sample2() throws Exception { 21 InstrumentationContext ctx = new InstrumentationContext(); 23 InstrumentationDescriptor id = new InstrumentationDescriptor(); 24 id.addInclusionRule("samples.*"); 25 ctx.addInstrumentationDescriptor(id); 26 27 FieldEventProducer fieldEventProducer = new FieldEventProducer(id); 30 fieldEventProducer.addFieldListener(this); 31 32 34 Bootstrapper.launch("samples.Foo", null, ctx, 35 InstrumentingClassLoader.createClassLoader(ctx)); 36 } 37 38 39 public void fieldChanging(FieldEvent fe) { 41 System.out.println("Field " + fe.getFieldName() + " is changing"); 42 } 43 public void fieldSet(FieldEvent fe) { 44 System.out.println("Field " + fe.getFieldName() + " is set"); 45 } 46 47 public void fieldGet(FieldEvent fe) { 48 System.out.println("Field " + fe.getFieldName() + " has been get"); 49 } 50 } 51 | Popular Tags |