KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > breakpoints > JspLineBreakpoint


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.debug.breakpoints;
21
22 import org.netbeans.api.debugger.*;
23 import org.netbeans.api.debugger.jpda.*;
24
25 import org.netbeans.modules.web.debug.util.Utils;
26 import java.util.*;
27 import org.openide.util.NbBundle;
28
29
30 /**
31  *
32  * @author Martin Grebac
33  */

34 public class JspLineBreakpoint extends Breakpoint {
35
36     /** Property name for enabled status of the breakpoint. */
37     public static final String JavaDoc PROP_ENABLED = JPDABreakpoint.PROP_ENABLED;
38
39     public static final String JavaDoc PROP_SUSPEND = JPDABreakpoint.PROP_SUSPEND;
40     public static final String JavaDoc PROP_HIDDEN = JPDABreakpoint.PROP_HIDDEN;
41     public static final String JavaDoc PROP_PRINT_TEXT = JPDABreakpoint.PROP_PRINT_TEXT;
42
43     public static final int SUSPEND_ALL = JPDABreakpoint.SUSPEND_ALL;
44     public static final int SUSPEND_EVENT_THREAD = JPDABreakpoint.SUSPEND_EVENT_THREAD;
45     public static final int SUSPEND_NONE = JPDABreakpoint.SUSPEND_NONE;
46
47     public static final String JavaDoc PROP_LINE_NUMBER = LineBreakpoint.PROP_LINE_NUMBER;
48     public static final String JavaDoc PROP_URL = LineBreakpoint.PROP_URL;
49     public static final String JavaDoc PROP_CONDITION = LineBreakpoint.PROP_CONDITION;
50     
51     private boolean enabled = true;
52     private boolean hidden = false;
53     private int suspend = SUSPEND_ALL;
54     private String JavaDoc printText;
55
56     private String JavaDoc url = ""; // NOI18N
57
private int lineNumber;
58     private String JavaDoc condition = ""; // NOI18N
59

60     private LineBreakpoint javalb;
61         
62     /** Creates a new instance of JspLineBreakpoint */
63     public JspLineBreakpoint() { }
64     
65     /** Creates a new instance of JspLineBreakpoint with url, linenumber*/
66     public JspLineBreakpoint(String JavaDoc url, int lineNumber) {
67         super();
68         
69         this.url = url;
70         this.lineNumber = lineNumber;
71         String JavaDoc pt = NbBundle.getMessage(JspLineBreakpoint.class, "CTL_Default_Print_Text");
72         this.printText = org.openide.util.Utilities.replaceString(pt, "{jspName}", Utils.getJspName(url));
73         
74         DebuggerManager d = DebuggerManager.getDebuggerManager();
75         
76         Utils.getEM().log("jsp url: " + url);
77
78         String JavaDoc filter = Utils.getClassFilter(url);
79         Utils.getEM().log("filter: " + filter);
80         
81         javalb = LineBreakpoint.create(url, lineNumber);
82         javalb.setStratum("JSP"); // NOI18N
83
javalb.setSourceName(Utils.getJspName(url));
84         javalb.setSourcePath(Utils.getJspPath(url));
85         javalb.setPreferredClassName(filter);
86         javalb.setHidden(true);
87         javalb.setPrintText(printText);
88         
89         String JavaDoc context = Utils.getContextPath(url);
90         String JavaDoc condition = "request.getContextPath().equals(\"" + context + "\")"; // NOI18N
91
javalb.setCondition(condition);
92         Utils.getEM().log("condition: " + condition);
93         
94         d.addBreakpoint(javalb);
95
96         this.setURL(url);
97         this.setLineNumber(lineNumber);
98     }
99
100     /**
101      * Creates a new breakpoint for given parameters.
102      *
103      * @param url a url
104      * @param lineNumber a line number
105      * @return a new breakpoint for given parameters
106      */

107     public static JspLineBreakpoint create(String JavaDoc url, int lineNumber) {
108         return new JspLineBreakpoint(url, lineNumber);
109     }
110     
111     /**
112      * Gets value of suspend property.
113      *
114      * @return value of suspend property
115      */

116     public int getSuspend () {
117         return suspend;
118     }
119
120     /**
121      * Sets value of suspend property.
122      *
123      * @param s a new value of suspend property
124      */

125     public void setSuspend (int s) {
126         if (s == suspend) return;
127         int old = suspend;
128         suspend = s;
129         if (javalb != null) {
130             javalb.setSuspend(s);
131         }
132         firePropertyChange(PROP_SUSPEND, new Integer JavaDoc(old), new Integer JavaDoc(s));
133     }
134     
135     /**
136      * Gets value of hidden property.
137      *
138      * @return value of hidden property
139      */

140     public boolean isHidden () {
141         return hidden;
142     }
143     
144     /**
145      * Sets value of hidden property.
146      *
147      * @param h a new value of hidden property
148      */

149     public void setHidden (boolean h) {
150         if (h == hidden) return;
151         boolean old = hidden;
152         hidden = h;
153         firePropertyChange(PROP_HIDDEN, Boolean.valueOf(old), Boolean.valueOf(h));
154     }
155     
156     /**
157      * Gets value of print text property.
158      *
159      * @return value of print text property
160      */

161     public String JavaDoc getPrintText () {
162         return printText;
163     }
164
165     /**
166      * Sets value of print text property.
167      *
168      * @param printText a new value of print text property
169      */

170     public void setPrintText (String JavaDoc printText) {
171         if (this.printText == printText) return;
172         String JavaDoc old = this.printText;
173         this.printText = printText;
174         if (javalb != null) {
175             javalb.setPrintText(printText);
176         }
177         firePropertyChange(PROP_PRINT_TEXT, old, printText);
178     }
179     
180     /**
181      * Called when breakpoint is removed.
182      */

183     protected void dispose() {
184         if (javalb != null) {
185             DebuggerManager.getDebuggerManager().removeBreakpoint(javalb);
186         }
187     }
188
189     /**
190      * Test whether the breakpoint is enabled.
191      *
192      * @return <code>true</code> if so
193      */

194     public boolean isEnabled() {
195         return enabled;
196     }
197     
198     /**
199      * Disables the breakpoint.
200      */

201     public void disable() {
202         if (!enabled) return;
203         enabled = false;
204         if (javalb != null) {
205             javalb.disable();
206         }
207         firePropertyChange(PROP_ENABLED, Boolean.TRUE, Boolean.FALSE);
208     }
209     
210     /**
211      * Enables the breakpoint.
212      */

213     public void enable() {
214         if (enabled) return;
215         enabled = true;
216         if (javalb != null) {
217             javalb.enable();
218         }
219         firePropertyChange(PROP_ENABLED, Boolean.FALSE, Boolean.TRUE);
220     }
221
222     /**
223      * Sets name of class to stop on.
224      *
225      * @param cn a new name of class to stop on
226      */

227     public void setURL (String JavaDoc url) {
228         if ( (url == this.url) ||
229              ((url != null) && (this.url != null) && url.equals (this.url))
230         ) return;
231         String JavaDoc old = url;
232         this.url = url;
233         firePropertyChange(PROP_URL, old, url);
234     }
235
236     /**
237      * Gets name of class to stop on.
238      *
239      * @return name of class to stop on
240      */

241     public String JavaDoc getURL () {
242         return url;
243     }
244     
245     /**
246      * Gets number of line to stop on.
247      *
248      * @return line number to stop on
249      */

250     public int getLineNumber () {
251         return lineNumber;
252     }
253     
254     /**
255      * Sets number of line to stop on.
256      *
257      * @param ln a line number to stop on
258      */

259     public void setLineNumber (int ln) {
260         if (ln == lineNumber) return;
261         int old = lineNumber;
262         lineNumber = ln;
263         if (javalb != null) {
264             javalb.setLineNumber(ln);
265         }
266         firePropertyChange(PROP_LINE_NUMBER, new Integer JavaDoc(old), new Integer JavaDoc(getLineNumber()));
267     }
268     
269     /**
270      * Sets condition.
271      *
272      * @param c a new condition
273      */

274     public void setCondition (String JavaDoc c) {
275         if (c != null) c = c.trim ();
276         if ( (c == condition) ||
277              ((c != null) && (condition != null) && condition.equals (c))
278         ) return;
279         String JavaDoc old = condition;
280         condition = c;
281         if (javalb != null) {
282             javalb.setCondition(c);
283         }
284         firePropertyChange(PROP_CONDITION, old, condition);
285     }
286     
287     /**
288      * Returns condition.
289      *
290      * @return cond a condition
291      */

292     public String JavaDoc getCondition () {
293         return condition;
294     }
295
296     /**
297      * Returns a string representation of this object.
298      *
299      * @return a string representation of the object
300      */

301     public String JavaDoc toString () {
302         return "JspLineBreakpoint " + url + " : " + lineNumber;
303     }
304             
305     /**
306      * Getter for property javalb.
307      * @return Value of property javalb.
308      */

309     public LineBreakpoint getJavalb() {
310         return javalb;
311     }
312     
313     /**
314      * Setter for property javalb.
315      * @param javalb New value of property javalb.
316      */

317     public void setJavalb(LineBreakpoint javalb) {
318         this.javalb = javalb;
319     }
320     
321     /**
322      * Sets group name of this JSP breakpoint and also sets the same group name for underlying Java breakpoint.
323      *
324      * @param newGroupName name of the group
325      */

326     public void setGroupName(String JavaDoc newGroupName) {
327         super.setGroupName(newGroupName);
328         javalb.setGroupName(newGroupName);
329     }
330 }
331
Popular Tags