1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.debug.core.DebugEvent; 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.model.DebugElement; 19 import org.eclipse.debug.core.model.IDebugElement; 20 import org.eclipse.debug.core.model.IDebugTarget; 21 import org.eclipse.debug.core.model.IDisconnect; 22 import org.eclipse.debug.core.model.IStepFilters; 23 import org.eclipse.debug.core.model.ITerminate; 24 import org.eclipse.jdi.TimeoutException; 25 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 26 import org.eclipse.jdt.debug.core.JDIDebugModel; 27 import org.eclipse.jdt.internal.debug.core.EventDispatcher; 28 import org.eclipse.jdt.internal.debug.core.IJDIEventListener; 29 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 30 31 import com.sun.jdi.VMDisconnectedException; 32 import com.sun.jdi.VirtualMachine; 33 import com.sun.jdi.request.EventRequest; 34 import com.sun.jdi.request.EventRequestManager; 35 36 public abstract class JDIDebugElement extends DebugElement implements IDisconnect { 37 38 44 public JDIDebugElement(JDIDebugTarget target) { 45 super(target); 46 } 47 48 51 protected void logError(Exception e) { 52 if (!((JDIDebugTarget)getDebugTarget()).isAvailable()) { 53 if (e instanceof VMDisconnectedException || 56 (e instanceof CoreException && ((CoreException)e).getStatus().getException() instanceof VMDisconnectedException)) { 57 return; 58 } 59 } 60 JDIDebugPlugin.log(e); 61 } 62 63 66 public Object getAdapter(Class adapter) { 67 if (adapter == IDebugElement.class) { 68 return this; 69 } 70 if (adapter == IStepFilters.class) { 71 return getDebugTarget(); 72 } 73 if (adapter == IDebugTarget.class) { 74 return getDebugTarget(); 75 } 76 if (adapter == ITerminate.class) { 77 return getDebugTarget(); 78 } 79 if (adapter == IJavaDebugTarget.class) { 80 return getJavaDebugTarget(); 81 } 82 return super.getAdapter(adapter); 83 } 84 85 88 public String getModelIdentifier() { 89 return JDIDebugModel.getPluginIdentifier(); 90 } 91 92 98 public void queueEvent(DebugEvent event) { 99 EventDispatcher dispatcher = ((JDIDebugTarget)getDebugTarget()).getEventDispatcher(); 100 if (dispatcher != null) { 101 dispatcher.queue(event); 102 } 103 } 104 105 112 public void fireSuspendEvent(int detail) { 113 getJavaDebugTarget().incrementSuspendCount(detail); 114 super.fireSuspendEvent(detail); 115 } 116 117 124 public void queueSuspendEvent(int detail) { 125 getJavaDebugTarget().incrementSuspendCount(detail); 126 queueEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail)); 127 } 128 129 136 public void requestFailed(String message, Exception e) throws DebugException { 137 requestFailed(message, e, DebugException.REQUEST_FAILED); 138 } 139 140 149 public void targetRequestFailed(String message, RuntimeException e) throws DebugException { 150 if (e == null || e.getClass().getName().startsWith("com.sun.jdi") || e instanceof TimeoutException) { requestFailed(message, e, DebugException.TARGET_REQUEST_FAILED); 152 } else { 153 throw e; 154 } 155 } 156 157 165 public void requestFailed(String message, Throwable e, int code) throws DebugException { 166 throwDebugException(message, code, e); 167 } 168 169 176 public void targetRequestFailed(String message, Throwable e) throws DebugException { 177 throwDebugException(message, DebugException.TARGET_REQUEST_FAILED, e); 178 } 179 180 189 public void jdiRequestFailed(String message, Throwable e) throws DebugException { 190 throwDebugException(message, DebugException.TARGET_REQUEST_FAILED, e); 191 } 192 193 199 public void notSupported(String message) throws DebugException { 200 throwDebugException(message, DebugException.NOT_SUPPORTED, null); 201 } 202 203 207 protected void throwDebugException(String message, int code, Throwable exception) throws DebugException { 208 if(exception instanceof VMDisconnectedException) { 209 disconnected(); 210 } 211 throw new DebugException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 212 code, message, exception)); 213 } 214 215 221 public void internalError(RuntimeException e) { 222 if (e.getClass().getName().startsWith("com.sun.jdi") || e instanceof TimeoutException) { logError(e); 224 } else { 225 throw e; 226 } 227 } 228 229 235 protected void internalError(String message) { 236 logError(new DebugException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 237 DebugException.INTERNAL_ERROR, message, null))); 238 } 239 240 245 protected String getUnknownMessage() { 246 return JDIDebugModelMessages.JDIDebugElement_unknown; 247 } 248 249 255 protected JDIDebugTarget getJavaDebugTarget() { 256 return (JDIDebugTarget)getDebugTarget(); 257 } 258 259 265 protected VirtualMachine getVM() { 266 return ((JDIDebugTarget)getDebugTarget()).getVM(); 267 } 268 269 275 public EventRequestManager getEventRequestManager() { 276 VirtualMachine vm = getVM(); 277 if (vm == null) { 278 return null; 279 } 280 return vm.eventRequestManager(); 281 } 282 283 291 public void addJDIEventListener(IJDIEventListener listener, EventRequest request) { 292 EventDispatcher dispatcher = ((JDIDebugTarget)getDebugTarget()).getEventDispatcher(); 293 if (dispatcher != null) { 294 dispatcher.addJDIEventListener(listener, request); 295 } 296 } 297 298 307 public void removeJDIEventListener(IJDIEventListener listener, EventRequest request) { 308 EventDispatcher dispatcher = ((JDIDebugTarget)getDebugTarget()).getEventDispatcher(); 309 if (dispatcher != null) { 310 dispatcher.removeJDIEventListener(listener, request); 311 } 312 } 313 314 317 protected void disconnected() { 318 if (getDebugTarget() != null) { 319 getJavaDebugTarget().disconnected(); 320 } 321 } 322 323 326 public void setRequestTimeout(int timeout) { 327 if (supportsRequestTimeout()) { 328 VirtualMachine vm = getVM(); 329 if (vm != null) { 330 ((org.eclipse.jdi.VirtualMachine)vm).setRequestTimeout(timeout); 331 } 332 } 333 } 334 335 338 public int getRequestTimeout() { 339 if (supportsRequestTimeout()) { 340 VirtualMachine vm = getVM(); 341 if (vm != null) { 342 return ((org.eclipse.jdi.VirtualMachine)vm).getRequestTimeout(); 343 } 344 } 345 return -1; 346 } 347 350 public boolean supportsRequestTimeout() { 351 return getJavaDebugTarget().isAvailable() && getVM() instanceof org.eclipse.jdi.VirtualMachine; 352 } 353 354 357 public boolean canDisconnect() { 358 return getDebugTarget().canDisconnect(); 359 } 360 361 364 public void disconnect() throws DebugException { 365 getDebugTarget().disconnect(); 366 } 367 368 371 public boolean isDisconnected() { 372 return getDebugTarget().isDisconnected(); 373 } 374 375 378 public boolean isStepFiltersEnabled() { 379 return getJavaDebugTarget().isStepFiltersEnabled(); 380 } 381 } 382 | Popular Tags |