Initial implementation of the new Debug Plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugElement.java
1 /**
2  * 
3  */
4 package net.sourceforge.phpeclipse.xdebug.php.model;
5
6
7 import net.sourceforge.phpeclipse.xdebug.core.ResponseData;
8 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
9
10 import org.eclipse.core.runtime.PlatformObject;
11 import org.eclipse.debug.core.DebugEvent;
12 import org.eclipse.debug.core.DebugException;
13 import org.eclipse.debug.core.DebugPlugin;
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.model.IDebugElement;
16 import org.eclipse.debug.core.model.IDebugTarget;
17
18 /**
19  * @author Christian
20  *
21  */
22 public class XDebugElement extends PlatformObject implements IDebugElement {
23         
24         // containing target 
25         protected XDebugTarget fTarget;
26         
27         /**
28          * Constructs a new debug element contained in the given
29          * debug target.
30          * 
31          * @param target debug target (PDA VM)
32          */
33         public XDebugElement(XDebugTarget target) {
34                 fTarget = target;
35         }
36         
37         /* (non-Javadoc)
38          * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
39          */
40         public String getModelIdentifier() {
41                 return IXDebugConstants.ID_PHP_DEBUG_MODEL;
42         }
43         /* (non-Javadoc)
44          * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
45          */
46         public IDebugTarget getDebugTarget() {
47                 return fTarget;
48         }
49         /* (non-Javadoc)
50          * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
51          */
52         public ILaunch getLaunch() {
53                 return getDebugTarget().getLaunch();
54         }
55         /* (non-Javadoc)
56          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
57          */
58         public Object getAdapter(Class adapter) {
59                 if (adapter == IDebugElement.class) {
60                         return this;
61                 }
62                 return super.getAdapter(adapter);
63         }
64         
65         protected void abort(String message, Throwable e) throws DebugException {
66 /*      Axel auskommentiert
67                 throw new DebugException(new Status(IStatus.ERROR, DebugExamplesPlugin.getDefault().getDescriptor().getUniqueIdentifier(), 
68                                 DebugPlugin.INTERNAL_ERROR, message, e));
69 */
70                 }
71         
72         /**
73          * Fires a debug event
74          * 
75          * @param event the event to be fired
76          */
77         protected void fireEvent(DebugEvent event) {
78                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event});
79         }
80         
81         /**
82          * Fires a <code>CREATE</code> event for this element.
83          */
84         public void fireCreationEvent() {
85                 fireEvent(new DebugEvent(this, DebugEvent.CREATE));
86         }       
87         
88         /**
89          * Fires a <code>RESUME</code> event for this element with
90          * the given detail.
91          * 
92          * @param detail event detail code
93          */
94         public void fireResumeEvent(int detail) {
95                 fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
96         }
97
98         /**
99          * Fires a <code>SUSPEND</code> event for this element with
100          * the given detail.
101          * 
102          * @param detail event detail code
103          */
104         public void fireSuspendEvent(int detail) {
105                 fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));
106         }
107         
108         /**
109          * Fires a <code>TERMINATE</code> event for this element.
110          */
111         protected void fireTerminateEvent() {
112                 fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
113         }
114         
115         public void fireDebugResponseEvent(ResponseData data) {
116                 DebugEvent de=new DebugEvent(this, DebugEvent.MODEL_SPECIFIC);
117                 de.setData(data);
118                 fireEvent(de);
119         }
120 }