First submit for debug plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / breakpoints / PHPBreakpoint.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core.breakpoints;
13
14 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
15 import org.eclipse.core.resources.IWorkspaceRunnable;
16 import org.eclipse.core.resources.IMarker;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.debug.core.DebugException;
21 import org.eclipse.debug.core.model.IBreakpoint;
22 import org.eclipse.debug.core.model.Breakpoint;
23
24 /**
25  * A breakpoint is capable of suspending the execution of a
26  * program at a specific location when a program is running
27  * in debug mode. Each breakpoint has an associated marker which
28  * stores and persists all attributes associated with a breakpoint.
29  * <p>
30  * A breakpoint is defined in two parts:
31  * <ol>
32  * <li>By an extension of kind <code>"org.eclipse.debug.core.breakpoints"</code></li>
33  * <li>By a marker definition that corresponds to the above breakpoint extension</li>
34  * </ol>
35  * <p>
36  * For example, following is a definition of corresponding breakpoint
37  * and breakpoint marker definitions. Note that the <code>markerType</code>
38  * attribute defined by the breakpoint extension corresponds to the 
39  * type of the marker definition.
40  * <pre>
41  * &lt;extension point="org.eclipse.debug.core.breakpoints"&gt;
42  *   &lt;breakpoint 
43  *      id="com.example.Breakpoint"
44  *      class="com.example.Breakpoint"
45  *      markerType="com.example.BreakpointMarker"&gt;
46  *   &lt;/breakpoint&gt;
47  * &lt;/extension&gt;
48  * &lt;extension point="org.eclipse.core.resources.markers"&gt;
49  *   &lt;marker 
50  *      id="com.example.BreakpointMarker"
51  *      super type="org.eclipse.debug.core.breakpointMarker"
52  *      attribute name ="exampleAttribute"&gt;
53  *   &lt;/marker&gt;
54  * &lt;/extension&gt;
55  * </pre>
56  * <p>
57  * The breakpoint manager instantiates persisted breakpoints by
58  * traversing all markers that are a subtype of
59  * <code>"org.eclipse.debug.core.breakpointMarker"</code>, and 
60  * instantiating the class defined by the <code>class</code> attribute
61  * on the associated breakpoint extension. The method <code>setMarker</code>
62  * is then called to associate a marker with the breakpoint.
63  * </p>
64  * <p>
65  * Breakpoints may or may not be registered with the breakpoint manager, and
66  * are persisted and restored as such. Since marker definitions only allow
67  * all or none of a specific marker type to be persisted, breakpoints define
68  * a <code>PERSISTED</code> attribute for selective persistence of breakpoints
69  * of the same type.
70  * </p>
71  * 
72  * @since 2.0
73  */
74
75 public abstract class PHPBreakpoint extends Breakpoint implements IBreakpoint {
76
77         /**
78          * Breakpoint attribute storing a breakpoint's hit count value
79          * (value <code>"net.sourceforge.phpeclipse.debug.hitCount"</code>). This attribute is stored as an
80          * <code>int</code>.
81          */
82         protected static final String HIT_COUNT = "net.sourceforge.phpeclipse.debug.hitCount"; //$NON-NLS-1$
83
84         /**
85          * Breakpoint attribute storing the fully qualified name of the type
86          * this breakpoint is located in.
87          * (value <code>"net.sourceforge.phpeclipse.debug.typeName"</code>). This attribute is a <code>String</code>.
88          */
89         protected static final String TYPE_NAME = "net.sourceforge.phpeclipse.debug.typeName"; //$NON-NLS-1$            
90
91         /**
92          * Root breakpoint marker type  
93          * (value <code>"org.eclipse.debug.core.breakpoint"</code>).
94          */
95         public static final String BREAKPOINT_MARKER = DebugPlugin.getUniqueIdentifier() + ".breakpointMarker"; //$NON-NLS-1$
96         
97         /**
98          * Line breakpoint marker type
99          * (value <code>"org.eclipse.debug.core.lineBreakpoint"</code>).
100          */
101         public static final String LINE_BREAKPOINT_MARKER = DebugPlugin.getUniqueIdentifier() + ".lineBreakpointMarker"; //$NON-NLS-1$
102                         
103         /**
104          * Enabled breakpoint marker attribute (value <code>"org.eclipse.debug.core.enabled"</code>).
105          * The attribute is a <code>boolean</code> corresponding to the
106          * enabled state of a breakpoint.
107          *
108          * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean)
109          */
110         public static final String ENABLED= "org.eclipse.debug.core.enabled"; //$NON-NLS-1$
111         
112         /**
113          * Debug model identifier breakpoint marker attribute (value <code>"org.eclipse.debug.core.id"</code>).
114          * The attribute is a <code>String</code> corresponding to the
115          * identifier of the debug model a breakpoint is associated with.
116          */
117         public static final String ID= "org.eclipse.debug.core.id"; //$NON-NLS-1$
118         
119         /**
120          * Registered breakpoint marker attribute (value <code>"org.eclipse.debug.core.registered"</code>).
121          * The attribute is a <code>boolean</code> corresponding to
122          * whether a breakpoint has been registered with the breakpoint manager.
123          *
124          * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean)
125          */
126         public static final String REGISTERED= "org.eclipse.debug.core.registered"; //$NON-NLS-1$       
127         
128         /**
129          * Persisted breakpoint marker attribute (value <code>"org.eclipse.debug.core.persisted"</code>).
130          * The attribute is a <code>boolean</code> corresponding to
131          * whether a breakpoint is to be persisted accross workspace
132          * invocations.
133          *
134          * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean)
135          */
136         public static final String PERSISTED= "org.eclipse.debug.core.persisted"; //$NON-NLS-1$         
137
138         private int DBGBpNo=0;
139
140         public PHPBreakpoint() {
141         }       
142
143         /**
144          * @see IBreakpoint#setMarker(IMarker)
145          */
146         public void setMarker(IMarker marker) throws CoreException {
147                 super.setMarker(marker);
148         }
149         
150         /**
151          * Add this breakpoint to the breakpoint manager,
152          * or sets it as unregistered.
153          */
154         protected void register(boolean register) throws CoreException {
155                 if (register) {
156                         DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
157                 } else {
158                         setRegistered(false);
159                 }
160         }
161         
162         /**
163          * Execute the given workspace runnable
164          */
165         protected void run(IWorkspaceRunnable wr) throws DebugException {
166                 try {
167                         ResourcesPlugin.getWorkspace().run(wr, null);
168                 } catch (CoreException e) {
169                         throw new DebugException(e.getStatus());
170                 }                       
171         }
172
173         /**
174          * @see IBreakpoint#getModelIdentifier()
175          */
176         public String getModelIdentifier() {
177                 if (PHPDebugCorePlugin.getDefault() == null) {
178                         // If the default instance is not yet initialized,
179                         // return a static identifier. This identifier must
180                         // match the plugin id defined in plugin.xml
181                         return "net.sourceforge.phpeclipse.debug.core"; //$NON-NLS-1$
182                 }
183                 return PHPDebugCorePlugin.getDefault().getDescriptor().getUniqueIdentifier();
184         }
185         
186         public void setDBGBpNo(int bpNo) {
187                 this.DBGBpNo= bpNo;
188         }
189         
190         public int getDBGBpNo() {
191                 return this.DBGBpNo;
192         }
193 }