KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > event > Sample1


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 import alt.jiapi.event.MethodEvent;
8 import alt.jiapi.event.MethodEventProducer;
9 import alt.jiapi.event.MethodListener;
10 import alt.jiapi.util.Bootstrapper;
11 import alt.jiapi.util.InstrumentingClassLoader;
12
13 public class Sample1 implements MethodListener {
14     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
15         new Sample1();
16     }
17     
18     public Sample1() throws Exception JavaDoc {
19         // Configure:
20
InstrumentationContext ctx = new InstrumentationContext();
21         InstrumentationDescriptor id = new InstrumentationDescriptor();
22         id.addInclusionRule("samples.*");
23         ctx.addInstrumentationDescriptor(id);
24         
25         // Use event API:
26
MethodEventProducer eventProducer = new MethodEventProducer(id);
27         eventProducer.addMethodListener(this);
28         
29         Bootstrapper.launch("samples.Foo", null, ctx,
30                             InstrumentingClassLoader.createClassLoader(ctx));
31     }
32        
33     public void methodEntered(MethodEvent event) {
34         System.out.println("Method " + event.getClassName() + "." +
35                            event.getMethodName() + " entered.");
36     }
37        
38     public void methodExited(MethodEvent event) {
39         System.out.println("Method " + event.getClassName() + "." +
40                            event.getMethodName() + " exited.");
41     }
42 }
43
Popular Tags