1 package ch.ethz.prose.jvmai.jikesrvm.advice_weaver; 2 3 import java.lang.reflect.Method ; 4 import java.util.*; 5 6 import ch.ethz.prose.crosscut.MethodRedefineCut; 7 import ch.ethz.prose.engine.MethodRedefineRequest; 8 9 14 public class RedefineWeaver { 15 16 20 protected Map requests = new HashMap(); 21 22 28 public void weaveMethodRedefineCut(MethodRedefineCut cut, MethodRedefineRequest request) { 29 Method advice_method = cut.getMethod(); 30 Method 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 42 public void unweaveMethodRedefineCut(MethodRedefineCut cut) { 43 Iterator it = getRequests(cut).iterator(); 44 45 while (it.hasNext()) { 46 Method 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 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 |