KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.ITerminate;
20
21 /**
22  * Object used to display owning thread in the debug launch view.
23  * In this case, the thread is waiting for the contended monitor,
24  * and owns the parent monitor.
25  */

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

31     private JavaMonitorThread fThread;
32     
33     /**
34      * The monitor this thread is waiting for.
35      */

36     private JavaContendedMonitor fContendedMonitor;
37     /**
38      * The parent, in the debug view tree.
39      */

40     private JavaContendedMonitor fParent;
41
42     /**
43      * Constructor
44      * @param thread
45      * @param parent
46      */

47     public JavaOwningThread(JavaMonitorThread thread, JavaContendedMonitor parent) {
48         fThread= thread;
49         thread.addElement(this);
50         fParent= parent;
51     }
52
53     /** Returns the <code>JavaMonitorThread</code> of this owning thread
54      * @return the <code>JavaMonitorThread</code> of this owning thread
55      */

56     public JavaMonitorThread getThread() {
57         return fThread;
58     }
59     
60     /**
61      * Returns the parent contended
62      * @return
63      */

64     public JavaContendedMonitor getParent() {
65         return fParent;
66     }
67
68     public JavaContendedMonitor getContendedMonitor() {
69         JavaMonitor contendedMonitor= fThread.getContendedMonitor0();
70         if (contendedMonitor == null) {
71             fContendedMonitor= null;
72         } else if (fContendedMonitor == null || fContendedMonitor.getMonitor() != contendedMonitor) {
73             // create a new object only if the monitor from the model changed
74
fContendedMonitor= new JavaContendedMonitor(contendedMonitor, this);
75         }
76         return fContendedMonitor;
77     }
78     
79     public void update() {
80     }
81
82     /* (non-Javadoc)
83      * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
84      */

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

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

99     public ILaunch getLaunch() {
100         return fThread.getLaunch();
101     }
102
103     /**
104      * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
105      */

106     public boolean isSuspended() {
107         return fThread.isSuspended();
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
112      */

113     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
114         if(adapter == IDebugTarget.class) {
115             return getDebugTarget();
116         }
117         //CONTEXTLAUNCHING
118
if(adapter.equals(ILaunchConfiguration.class)) {
119             return getLaunch().getLaunchConfiguration();
120         }
121         return super.getAdapter(adapter);
122     }
123
124     /**
125      * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
126      */

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

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

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