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 JavaOwnedMonitor extends PlatformObject implements IDebugElement, ITerminate, ISuspendResume { 29 30 33 private JavaMonitor fMonitor; 34 35 38 private JavaWaitingThread[] fWaitingThreads; 39 42 private JavaWaitingThread fParent; 43 44 49 public JavaOwnedMonitor(JavaMonitor monitor, JavaWaitingThread parent) { 50 fMonitor= monitor; 51 monitor.addElement(this); 52 fParent= parent; 53 } 54 55 59 public JavaMonitor getMonitor() { 60 return fMonitor; 61 } 62 63 67 public Object getParent() { 68 if (fParent.getParent() == null) { 69 return fParent.getThread().getOriginalThread(); 70 } 71 return fParent; 72 } 73 74 78 public JavaWaitingThread[] getWaitingThreads() { 79 JavaMonitorThread[] waitingThreads= fMonitor.getWaitingThreads0(); 80 JavaWaitingThread[] tmp= new JavaWaitingThread[waitingThreads.length]; 81 if (fWaitingThreads == null) { 82 for (int i= 0; i < waitingThreads.length; i++) { 84 tmp[i]= new JavaWaitingThread(waitingThreads[i], this); 85 } 86 } else { 87 outer: for (int i= 0; i < waitingThreads.length; i++) { 89 JavaMonitorThread waitingThread= waitingThreads[i]; 90 for (int j= 0; j < fWaitingThreads.length; j++) { 91 if (fWaitingThreads[j].getThread() == waitingThread) { 92 tmp[i]= fWaitingThreads[j]; 93 continue outer; 94 } 95 } 96 tmp[i]= new JavaWaitingThread(waitingThread, this); 97 } 98 } 99 fWaitingThreads = tmp; 100 return fWaitingThreads; 101 } 102 103 106 public String getModelIdentifier() { 107 return fMonitor.getModelIdentifier(); 108 } 109 110 113 public IDebugTarget getDebugTarget() { 114 return fMonitor.getDebugTarget(); 115 } 116 117 120 public ILaunch getLaunch() { 121 return fMonitor.getLaunch(); 122 } 123 124 127 public Object getAdapter(Class adapter) { 128 if(adapter == IDebugTarget.class) { 129 return getDebugTarget(); 130 } 131 if(adapter.equals(ILaunchConfiguration.class)) { 133 return getLaunch().getLaunchConfiguration(); 134 } 135 return super.getAdapter(adapter); 136 } 137 138 142 protected IThread getParentThread() { 143 Object parent = getParent(); 144 IThread thread = null; 145 if(parent instanceof IThread) { 146 thread = (IThread) parent; 147 } 148 else if(parent instanceof JavaWaitingThread) { 149 thread = ((JavaWaitingThread)parent).getThread().getOriginalThread(); 150 } 151 return thread; 152 } 153 154 157 public boolean canTerminate() { 158 return getDebugTarget().canTerminate(); 159 } 160 161 164 public boolean isTerminated() { 165 return getDebugTarget().isTerminated(); 166 } 167 168 171 public void terminate() throws DebugException { 172 getDebugTarget().terminate(); 173 } 174 175 178 public boolean canResume() { 179 IThread thread = getParentThread(); 180 if(thread != null) { 181 return thread.canResume(); 182 } 183 return false; 184 } 185 186 189 public boolean canSuspend() { 190 IThread thread = getParentThread(); 191 if(thread != null) { 192 return thread.canSuspend(); 193 } 194 return false; 195 } 196 197 200 public boolean isSuspended() { 201 IThread thread = getParentThread(); 202 if(thread != null) { 203 return thread.isSuspended(); 204 } 205 return false; 206 } 207 208 211 public void resume() throws DebugException { 212 IThread thread = getParentThread(); 213 if(thread != null) { 214 thread.resume(); 215 } 216 } 217 218 221 public void suspend() throws DebugException { 222 IThread thread = getParentThread(); 223 if(thread != null) { 224 thread.suspend(); 225 } 226 } 227 } 228 | Popular Tags |