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 RequestActionSupport extends Request implements VMListener, StopListener { 42 43 protected boolean isSet = false; 44 protected EventRequest request; 45 protected String text; 46 public RequestActionSupport setText(String text) { 47 this.text = text; 48 return this; 49 } 50 51 private boolean isDeferred = false; 52 private SourceManager.SourceLine sourceLine; 53 54 55 protected boolean isEnabled = true; 56 public boolean isEnabled() { return isEnabled; } 57 58 public RequestActionSupport(Debugger debugger, String text) { 59 super(debugger); 60 if (text != null && !text.trim().equals("")) debugger.addStopListener(this); 61 setText(text); 62 } 63 64 public RequestActionSupport(Debugger debugger) { 65 this(debugger, null); 66 } 67 68 abstract void resolveAll(); 69 70 public boolean isSetting() { 71 return true; 72 } 73 74 public boolean isBreakpoint() { 75 return false; 76 } 77 78 public boolean isSet() { 79 return isSet; 80 } 81 82 public EventRequest setRequest(EventRequest request) { 83 return (this.request = request); 84 } 85 86 protected EventRequest set() { 87 add(); 88 try { 89 resolveAll(); 90 } catch (VMDisconnectedException e) { 91 } 92 return getRequest(); 93 } 94 95 protected EventRequest unset() { 96 RequestAction request = remove(); EventRequest req = null; 99 if (request != null) { 100 try { 101 req = request.getRequest(); if (req != null) { 103 vm().eventRequestManager().deleteEventRequest(req); 104 } 105 } catch (NoVMException e) { 106 } 107 } else { 108 try { 109 req = getRequest(); req = getRequest(); if (req != null) { 111 vm().eventRequestManager().deleteEventRequest(req); 112 113 } 114 } catch (NoVMException e) { 115 } 116 } 117 return req; } 119 120 public static String f(BreakpointRequest req) { 121 String str = req + ""; 122 str += ", suspendPolicy=" + req.suspendPolicy(); 123 str += ", enabled=" + req.isEnabled(); 124 str += ", location=" + req.location(); 125 return str; 126 } 127 128 public EventRequest getRequest() { 129 return request; 130 } 131 132 public boolean isDeferred() { 133 return isDeferred; 134 } 135 136 protected void setDeferred(boolean isDeferred) { 137 this.isDeferred = isDeferred; 138 } 139 140 protected VirtualMachine vm() throws NoVMException { 141 return debugger.getVM(); 142 } 143 144 protected void addListeners() { 145 debugger.addVMListener(this); 146 } 147 148 protected void add() { 149 addListeners(); 150 debugger.addRequest(this); 151 isEnabled = true; 152 } 153 154 protected void removeListeners() { 155 debugger.removeVMListener(this); 156 } 157 158 protected RequestAction remove() { 159 removeListeners(); 160 RequestAction req = debugger.removeRequest(this); 161 isEnabled = false; 162 if (req != null) { 163 dbg().fireRequestClearEvent(new RequestEvent(this, true)); 164 } 165 return req; 166 } 167 168 public SourceManager.SourceLine getSourceLine() { 169 return this.sourceLine; 170 } 171 172 public void setSourceLine(SourceManager.SourceLine sourceLine) { 173 this.sourceLine = sourceLine; 174 } 175 176 protected boolean success() { 177 if (isSetting()) { 178 dbg().setStatus("Set " + this); 179 dbg().fireRequestSetEvent(new RequestEvent(this, true)); 180 } else { 181 dbg().setStatus("Clear " + this); 182 dbg().fireRequestClearEvent(new RequestEvent(this, true)); 183 } 184 return (isSet = true); 185 } 186 187 protected boolean defer() { 188 setDeferred(true); 189 dbg().fireRequestDeferredEvent(new RequestEvent(this, false)); 190 return (isSet = false); 191 } 192 193 protected boolean failure(boolean verbose) { 194 dbg().setStatus("Deferring " + this); 195 if (verbose) { 196 dbg().fireRequestFailedEvent(new RequestEvent(this, false)); 197 } 198 return (isSet = false); 199 } 200 201 private void reset() { 202 isSet = false; 203 request = null; 204 } 205 206 207 public void vmStartEvent(VMStartEvent e) { 208 if (!isSet()) { 209 resolveAll(); 210 } 211 } 212 public void vmDeathEvent(VMDeathEvent e) {} 213 public void vmDisconnectEvent(VMDisconnectEvent e) {} 214 215 216 public void breakpointEvent(BreakpointEvent e) { } 217 public void exceptionEvent(ExceptionEvent e) { } 218 public void accessWatchpointEvent(AccessWatchpointEvent e) { } 219 public void modificationWatchpointEvent(ModificationWatchpointEvent e) { } 220 public void stepEvent(StepEvent e) { } 221 222 protected String format(String str) { return str; } 223 protected void print(Event e) { 224 if (isEnabled() && text != null && e != null && e.request().equals(request)) { 225 debugger.app().outln(format(text)); 226 } 227 } 228 } 229 | Popular Tags |