1 22 23 package org.aspectj.debugger.request; 24 25 import org.aspectj.debugger.base.*; 26 27 import com.sun.jdi.*; 28 import com.sun.jdi.event.*; 29 import java.util.*; 30 31 39 40 public class RequestList 41 implements ClassListener, VMListener { 42 43 44 private List requests; 45 46 47 private Debugger debugger; 48 49 public RequestList(Debugger debugger) { 50 this.debugger = debugger; 51 debugger.addClassListener(this); 52 debugger.addVMListener(this); 53 requests = Collections.synchronizedList(new Vector()); 54 } 55 56 private void add(EventRequestWrapper wrapper) { 57 System.out.println("Adding wrapper=" + wrapper); 58 requests.add(wrapper); 59 } 60 61 public EventRequestWrapper remove(EventRequestWrapper wrapper) { 62 if (requests.remove(wrapper)) { 63 return wrapper; 64 } 65 return null; 66 } 67 68 69 public ClassLineBreakpointRequestWrapper createBreakpointRequest(String className, int line) { 70 ClassLineBreakpointRequestWrapper wrapper = 71 new ClassLineBreakpointRequestWrapper(debugger, className, line); 72 add(wrapper); 73 resolveAgainstAllClasses(wrapper); 74 return wrapper; 75 } 76 77 boolean resolveAgainstAllClasses(EventRequestWrapper wrapper) { 78 try { 79 Iterator iter = debugger.getVM().allClasses().iterator(); 80 while (iter.hasNext()) { 81 if (wrapper.resolve((ReferenceType) iter.next()) != null) { 82 remove(wrapper); 83 return true; 84 } 85 } 86 } catch (NoVMException e) { 87 } 88 return false; 89 } 90 91 boolean resolveAgainstClass(EventRequestWrapper wrapper, ReferenceType refType) { 92 if (wrapper.resolve(refType) != null) { 93 remove(wrapper); 94 return true; 95 } 96 return false; 97 } 98 99 100 101 public void classPrepareEvent(ClassPrepareEvent e) { 102 for (int i = 0; i < requests.size(); i++) { 103 resolveAgainstClass((EventRequestWrapper) requests.get(i), e.referenceType()); 104 } 105 } 106 public void classUnloadEvent(ClassUnloadEvent e) { 107 } 108 109 110 public void vmStartEvent(VMStartEvent e) { 111 for (int i = 0; i < requests.size(); i++) { 112 resolveAgainstAllClasses((EventRequestWrapper) requests.get(i)); 113 } 114 } 115 public void vmDeathEvent(VMDeathEvent e) { 116 } 117 public void vmDisconnectEvent(VMDisconnectEvent e) { 118 } 119 120 } 121 | Popular Tags |