KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > core > model > DebugElement


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.debug.core.model;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.PlatformObject;
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.DebugPlugin;
19 import org.eclipse.debug.core.ILaunch;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21
22 /**
23  * Implementation of common function for debug elements.
24  * <p>
25  * Clients may subclass this class.
26  * </p>
27  * @since 3.1
28  */

29 public abstract class DebugElement extends PlatformObject implements IDebugElement {
30     
31     private IDebugTarget fTarget;
32
33     /**
34      * Constructs a debug element referring to an artifact in the given
35      * debug target.
36      *
37      * @param target debug target containing this element
38      */

39     public DebugElement(IDebugTarget target) {
40         fTarget = target;
41     }
42
43     /* (non-Javadoc)
44      *
45      * Debug target implementation should override this method.
46      *
47      * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
48      */

49     public IDebugTarget getDebugTarget() {
50         return fTarget;
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
55      */

56     public ILaunch getLaunch() {
57         return getDebugTarget().getLaunch();
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
62      */

63     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
64         if (adapter == IDebugElement.class) {
65             return this;
66         }
67         
68         // a debug target may not implement IStepFilters
69
if (adapter == IStepFilters.class) {
70             if (getDebugTarget() instanceof IStepFilters)
71                 return getDebugTarget();
72         }
73         if (adapter == IDebugTarget.class) {
74             return getDebugTarget();
75         }
76         if (adapter == ILaunch.class) {
77             return getLaunch();
78         }
79         if (adapter == IProcess.class) {
80             return getDebugTarget().getProcess();
81         }
82         //CONTEXTLAUNCHING
83
if(adapter == ILaunchConfiguration.class) {
84             return getLaunch().getLaunchConfiguration();
85         }
86         return super.getAdapter(adapter);
87     }
88
89     /**
90      * Fires a debug event.
91      *
92      * @param event debug event to fire
93      */

94     public void fireEvent(DebugEvent event) {
95         DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event});
96     }
97
98     /**
99      * Fires a change event for this debug element
100      * with the specified detail code.
101      *
102      * @param detail detail code for the change event,
103      * such as <code>DebugEvent.STATE</code> or <code>DebugEvent.CONTENT</code>
104      */

105     public void fireChangeEvent(int detail) {
106         fireEvent(new DebugEvent(this, DebugEvent.CHANGE, detail));
107     }
108     
109     /**
110      * Fires a creation event for this debug element.
111      */

112     public void fireCreationEvent() {
113         fireEvent(new DebugEvent(this, DebugEvent.CREATE));
114     }
115     
116     /**
117      * Fires a resume for this debug element with
118      * the specified detail code.
119      *
120      * @param detail detail code for the resume event, such
121      * as <code>DebugEvent.STEP_OVER</code>
122      */

123     public void fireResumeEvent(int detail) {
124         fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
125     }
126     
127     /**
128      * Fires a suspend event for this debug element with
129      * the specified detail code.
130      *
131      * @param detail detail code for the suspend event, such
132      * as <code>DebugEvent.BREAKPOINT</code>
133      */

134     public void fireSuspendEvent(int detail) {
135         fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));
136     }
137     
138     /**
139      * Fires a terminate event for this debug element.
140      */

141     public void fireTerminateEvent() {
142         fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
143     }
144     
145     /**
146      * Throws a debug exception with a status code of <code>TARGET_REQUEST_FAILED</code>.
147      *
148      * @param message exception message
149      * @param e underlying exception or <code>null</code>
150      * @throws DebugException
151      */

152     protected void requestFailed(String JavaDoc message, Throwable JavaDoc e) throws DebugException {
153         throw new DebugException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
154                 DebugException.TARGET_REQUEST_FAILED, message, e));
155     }
156     
157     /**
158      * Throws a debug exception with a status code of <code>NOT_SUPPORTED</code>.
159      *
160      * @param message exception message
161      * @param e underlying exception or <code>null</code>
162      * @throws DebugException
163      */

164     protected void notSupported(String JavaDoc message, Throwable JavaDoc e) throws DebugException {
165         throw new DebugException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
166                 DebugException.NOT_SUPPORTED, message, e));
167     }
168 }
169
Popular Tags