KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > jvmai > jikesrvm > advice_weaver > RedefineWeaver


1 package ch.ethz.prose.jvmai.jikesrvm.advice_weaver;
2
3 import java.lang.reflect.Method JavaDoc;
4 import java.util.*;
5
6 import ch.ethz.prose.crosscut.MethodRedefineCut;
7 import ch.ethz.prose.engine.MethodRedefineRequest;
8
9 /**
10  * Weave and unweave method redefine requests.
11  *
12  * @author Johann Gyger
13  */

14 public class RedefineWeaver {
15
16   /**
17    * Mapping from a crosscut (key) to a collection of method redefine requests
18    * (value).
19    */

20   protected Map requests = new HashMap();
21
22   /**
23    * Weave a method redefinition.
24    *
25    * @param cut crosscut that contains advice method
26    * @param request
27    */

28   public void weaveMethodRedefineCut(MethodRedefineCut cut, MethodRedefineRequest request) {
29     Method JavaDoc advice_method = cut.getMethod();
30     Method JavaDoc target_method = request.getMethod();
31     MethodWeaver weaver = MethodWeaver.getWeaver(target_method);
32
33     weaver.setRedefineAdvice(advice_method);
34     getRequests(cut).add(request);
35   }
36
37   /**
38    * Unweave a method redefinition.
39    *
40    * @param cut crosscut which should be unwoven.
41    */

42   public void unweaveMethodRedefineCut(MethodRedefineCut cut) {
43     Iterator it = getRequests(cut).iterator();
44
45     while (it.hasNext()) {
46       Method JavaDoc target_method = ((MethodRedefineRequest) it.next()).getMethod();
47       MethodWeaver weaver = MethodWeaver.getWeaver(target_method);
48
49       weaver.setRedefineAdvice(null);
50     }
51
52     requests.remove(cut);
53   }
54
55   /**
56    * Get requests for `cut'.
57    *
58    * @param cut crosscut whose requests are returned
59    * @return requests for `cut'
60    */

61   protected Collection getRequests(MethodRedefineCut cut) {
62     Collection c = (Collection) requests.get(cut);
63     if (c == null) {
64       c = new LinkedList();
65       requests.put(cut, c);
66     }
67     return c;
68   }
69
70 }
71
Popular Tags