KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > monitors > JavaWaitingThread


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.monitors;
12
13 import org.eclipse.core.runtime.Platform;
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.ITerminate;
20
21 /**
22  * Object used to display waiting thread in the debug launch view.
23  * In this case, the thread owns for the owned monitors, and is waiting
24  * for the parent monitor.
25  */

26 public class JavaWaitingThread implements IDebugElement, ITerminate {
27
28     /**
29      * The thread object in the thread and monitor model.
30      */

31     private JavaMonitorThread fThread;
32
33     /**
34      * The monitors this thread owns.
35      */

36     private JavaOwnedMonitor[] fOwnedMonitors;
37     /**
38      * The parent, in the debug view tree.
39      */

40     private JavaOwnedMonitor fParent;
41
42     public JavaWaitingThread(JavaMonitorThread thread, JavaOwnedMonitor parent) {
43         fThread= thread;
44         thread.addElement(this);
45         fParent= parent;
46     }
47
48     public JavaMonitorThread getThread() {
49         return fThread;
50     }
51     
52     public JavaOwnedMonitor getParent() {
53         return fParent;
54     }
55
56     public JavaOwnedMonitor[] getOwnedMonitors() {
57         JavaMonitor[] ownedMonitors= fThread.getOwnedMonitors0();
58         JavaOwnedMonitor[] tmp= new JavaOwnedMonitor[ownedMonitors.length];
59         if (fOwnedMonitors == null) {
60             // the list was empty, creating new objects
61
for (int i= 0; i < ownedMonitors.length; i++) {
62                 tmp[i]= new JavaOwnedMonitor(ownedMonitors[i], this);
63             }
64         } else {
65             // trying to reuse the objects from the previous list
66
outer: for (int i= 0; i < ownedMonitors.length; i++) {
67                 JavaMonitor ownedMonitor= ownedMonitors[i];
68                 for (int j= 0; j < fOwnedMonitors.length; j++) {
69                     if (fOwnedMonitors[j].getMonitor() == ownedMonitor) {
70                         tmp[i]= fOwnedMonitors[j];
71                         continue outer;
72                     }
73                 }
74                 tmp[i]= new JavaOwnedMonitor(ownedMonitor, this);
75             }
76         }
77         fOwnedMonitors= tmp;
78         return fOwnedMonitors;
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
83      */

84     public String JavaDoc getModelIdentifier() {
85         return fThread.getModelIdentifier();
86     }
87
88     /* (non-Javadoc)
89      * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
90      */

91     public IDebugTarget getDebugTarget() {
92         return fThread.getDebugTarget();
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
97      */

98     public ILaunch getLaunch() {
99         return fThread.getLaunch();
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
104      */

105     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
106         if(adapter == IDebugTarget.class) {
107             return getDebugTarget();
108         }
109         //CONTEXTLAUNCHING
110
if(adapter.equals(ILaunchConfiguration.class)) {
111             return getLaunch().getLaunchConfiguration();
112         }
113         return Platform.getAdapterManager().getAdapter(this, adapter);
114     }
115
116     /**
117      * Returns whether this waiting thread is suspended
118      */

119     public boolean isSuspended() {
120         return fThread.isSuspended();
121     }
122
123     /* (non-Javadoc)
124      * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
125      */

126     public boolean canTerminate() {
127         return getDebugTarget().canTerminate();
128     }
129
130     /* (non-Javadoc)
131      * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
132      */

133     public boolean isTerminated() {
134         return getDebugTarget().isTerminated();
135     }
136
137     /* (non-Javadoc)
138      * @see org.eclipse.debug.core.model.ITerminate#terminate()
139      */

140     public void terminate() throws DebugException {
141         getDebugTarget().terminate();
142     }
143 }
144
Popular Tags