1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 import org.eclipse.core.runtime.PlatformObject; 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.debug.core.ILaunch; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.model.IDebugElement; 18 import org.eclipse.debug.core.model.IDebugTarget; 19 import org.eclipse.debug.core.model.ISuspendResume; 20 import org.eclipse.debug.core.model.ITerminate; 21 import org.eclipse.debug.core.model.IThread; 22 23 28 public class JavaContendedMonitor extends PlatformObject implements IDebugElement, ITerminate, ISuspendResume { 29 30 33 private JavaMonitor fMonitor; 34 37 private JavaOwningThread fOwningThread; 38 41 private JavaOwningThread fParent; 42 43 48 public JavaContendedMonitor(JavaMonitor monitor, JavaOwningThread parent) { 49 fMonitor= monitor; 50 monitor.addElement(this); 51 fParent= parent; 52 } 53 54 58 public JavaMonitor getMonitor() { 59 return fMonitor; 60 } 61 62 66 public Object getParent() { 67 if (fParent.getParent() == null) { 68 return fParent.getThread().getOriginalThread(); 69 } 70 return fParent; 71 } 72 73 77 public JavaOwningThread getOwningThread() { 78 JavaMonitorThread owningThread= fMonitor.getOwningThread0(); 79 if (owningThread == null) { 80 fOwningThread= null; 81 } else if (fOwningThread == null || fOwningThread.getThread() != owningThread) { 82 fOwningThread= new JavaOwningThread(owningThread, this); 84 } 85 return fOwningThread; 86 } 87 88 91 public String getModelIdentifier() { 92 return fMonitor.getModelIdentifier(); 93 } 94 95 98 public IDebugTarget getDebugTarget() { 99 return fMonitor.getDebugTarget(); 100 } 101 102 105 public ILaunch getLaunch() { 106 return fMonitor.getLaunch(); 107 } 108 109 112 public Object getAdapter(Class adapter) { 113 if(adapter == IDebugTarget.class) { 114 return getDebugTarget(); 115 } 116 if(adapter.equals(ILaunchConfiguration.class)) { 118 return getLaunch().getLaunchConfiguration(); 119 } 120 return super.getAdapter(adapter); 121 } 122 123 127 protected IThread getParentThread() { 128 Object parent = getParent(); 129 IThread thread = null; 130 if(parent instanceof IThread) { 131 thread = (IThread) parent; 132 } 133 else if(parent instanceof JavaOwningThread) { 134 thread = ((JavaOwningThread)parent).getThread().getOriginalThread(); 135 } 136 return thread; 137 } 138 139 142 public boolean canTerminate() { 143 return getDebugTarget().canTerminate(); 144 } 145 146 149 public boolean isTerminated() { 150 return getDebugTarget().isTerminated(); 151 } 152 153 156 public void terminate() throws DebugException { 157 getDebugTarget().terminate(); 158 } 159 160 163 public boolean canResume() { 164 if(getOwningThread() != null) { 165 return getOwningThread().getThread().getOriginalThread().canResume(); 166 } 167 return false; 168 } 169 170 173 public boolean canSuspend() { 174 return false; 175 } 176 177 180 public boolean isSuspended() { 181 if(getOwningThread() != null) { 182 return getOwningThread().getThread().getOriginalThread().isSuspended(); 183 } 184 return false; 185 } 186 187 190 public void resume() throws DebugException { 191 getOwningThread().getThread().getOriginalThread().resume(); 192 } 193 194 197 public void suspend() throws DebugException { 198 getOwningThread().getThread().getOriginalThread().suspend(); 199 } 200 } 201 | Popular Tags |