KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > MethodInstrumentor


1 package alt.jiapi;
2
3 import alt.jiapi.InstrumentationException;
4 import alt.jiapi.Instrumentor;
5 import alt.jiapi.reflect.JiapiClass;
6 import alt.jiapi.reflect.JiapiMethod;
7
8 import org.apache.log4j.Category;
9
10 /**
11  * This class is a simple implementation of Instrumentor,
12  * that gets all the declared methods of the target class,
13  * and forwards instrumentation to <code>instrument(JiapiMethod)</code>
14  * method.
15  */

16 public abstract class MethodInstrumentor implements Instrumentor {
17     private static Category log = Category.getInstance(MethodInstrumentor.class);
18     /**
19      * Implementation of Instrumentor.instrument(JiapiClass).
20      * Call instrument(JiapiMethod) for each declared method found
21      * from give JiapiClass.
22      */

23     public void instrument(JiapiClass clazz) throws InstrumentationException {
24         log.debug("Instrumenting " + clazz.getName());
25         JiapiMethod[] methods = clazz.getDeclaredMethods();
26         for (int i = 0; i < methods.length; i++) {
27         if (methods[i].getInstructionList() != null) {
28         instrument(methods[i]);
29         }
30         else {
31         log.debug("Won't instrument " + clazz + "#" + methods[i] +
32               ", it has no instructions");
33         }
34         }
35     }
36
37     public abstract void instrument(JiapiMethod m) throws InstrumentationException;
38 }
39
Popular Tags