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.request.*; 29 import com.sun.jdi.event.*; 30 import java.util.*; 31 32 40 41 public abstract class RequestAction extends RequestActionSupport implements ClassListener { 42 43 public RequestAction(Debugger debugger) { 44 super(debugger); 45 } 46 47 void resolveAll() { 48 resolveAgainstAllClasses(); 49 } 50 51 protected void addListeners() { 52 super.addListeners(); 53 debugger.addClassListener(this); 54 } 55 56 protected void removeListeners() { 57 super.removeListeners(); 58 debugger.removeClassListener(this); 59 } 60 61 public void removeFromDebugger(Debugger debugger) { 62 removeListeners(); 63 } 64 65 abstract EventRequest resolve(ReferenceType refType) 66 throws MultipleLocationsException, 67 UnableToSetRequestException; 68 69 protected boolean resolveAgainstAllClasses() { 70 try { 71 Iterator iter = debugger.getVM().allClasses().iterator(); 72 while (iter.hasNext()) { 73 EventRequest request = resolve((ReferenceType) iter.next()); 74 if (request != null) { 75 setRequest(request); 76 return success(); 77 } 78 } 79 } catch (NoVMException e) { 80 } catch (MultipleLocationsException mle) { 81 return failure(true); 82 } catch (UnableToSetRequestException utsre) { 83 return failure(true); 84 } 85 return defer(); 86 } 87 88 protected boolean resolveAgainstClass(ReferenceType refType) { 89 try { 90 EventRequest request = resolve(refType); 91 if (request != null) { 92 setRequest(request); 93 return success(); 94 } 95 } catch (MultipleLocationsException mle) { 96 return failure(true); 97 } catch (UnableToSetRequestException utsre) { 98 return failure(true); 99 } 100 return failure(false); 101 } 102 103 104 public void classPrepareEvent(ClassPrepareEvent e) { 105 if (!isSet) { 106 resolveAgainstClass(e.referenceType()); 107 } 108 } 109 public void classUnloadEvent(ClassUnloadEvent e) { 110 } 111 } 112 | Popular Tags |