001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.debug.breakpoints;
043:
044: import org.netbeans.api.debugger.*;
045: import org.netbeans.api.debugger.jpda.*;
046:
047: import org.netbeans.modules.web.debug.util.Utils;
048: import java.util.*;
049: import org.openide.util.NbBundle;
050:
051: /**
052: *
053: * @author Martin Grebac
054: */
055: public class JspLineBreakpoint extends Breakpoint {
056:
057: /** Property name for enabled status of the breakpoint. */
058: public static final String PROP_ENABLED = JPDABreakpoint.PROP_ENABLED;
059:
060: public static final String PROP_SUSPEND = JPDABreakpoint.PROP_SUSPEND;
061: public static final String PROP_HIDDEN = JPDABreakpoint.PROP_HIDDEN;
062: public static final String PROP_PRINT_TEXT = JPDABreakpoint.PROP_PRINT_TEXT;
063:
064: public static final int SUSPEND_ALL = JPDABreakpoint.SUSPEND_ALL;
065: public static final int SUSPEND_EVENT_THREAD = JPDABreakpoint.SUSPEND_EVENT_THREAD;
066: public static final int SUSPEND_NONE = JPDABreakpoint.SUSPEND_NONE;
067:
068: public static final String PROP_LINE_NUMBER = LineBreakpoint.PROP_LINE_NUMBER;
069: public static final String PROP_URL = LineBreakpoint.PROP_URL;
070: public static final String PROP_CONDITION = LineBreakpoint.PROP_CONDITION;
071:
072: private boolean enabled = true;
073: private boolean hidden = false;
074: private int suspend = SUSPEND_ALL;
075: private String printText;
076:
077: private String url = ""; // NOI18N
078: private int lineNumber;
079: private String condition = ""; // NOI18N
080:
081: private LineBreakpoint javalb;
082:
083: /** Creates a new instance of JspLineBreakpoint */
084: public JspLineBreakpoint() {
085: }
086:
087: /** Creates a new instance of JspLineBreakpoint with url, linenumber*/
088: public JspLineBreakpoint(String url, int lineNumber) {
089: super ();
090:
091: this .url = url;
092: this .lineNumber = lineNumber;
093: String pt = NbBundle.getMessage(JspLineBreakpoint.class,
094: "CTL_Default_Print_Text");
095: this .printText = org.openide.util.Utilities.replaceString(pt,
096: "{jspName}", Utils.getJspName(url));
097:
098: DebuggerManager d = DebuggerManager.getDebuggerManager();
099:
100: Utils.log("jsp url: " + url);
101:
102: String filter = Utils.getClassFilter(url);
103: Utils.log("filter: " + filter);
104:
105: javalb = LineBreakpoint.create(url, lineNumber);
106: javalb.setStratum("JSP"); // NOI18N
107: javalb.setSourceName(Utils.getJspName(url));
108: javalb.setSourcePath(Utils.getJspPath(url));
109: javalb.setPreferredClassName(filter);
110: javalb.setHidden(true);
111: javalb.setPrintText(printText);
112:
113: String context = Utils.getContextPath(url);
114: String condition = "request.getContextPath().equals(\""
115: + context + "\")"; // NOI18N
116: javalb.setCondition(condition);
117: Utils.log("condition: " + condition);
118:
119: d.addBreakpoint(javalb);
120:
121: this .setURL(url);
122: this .setLineNumber(lineNumber);
123: }
124:
125: /**
126: * Creates a new breakpoint for given parameters.
127: *
128: * @param url a url
129: * @param lineNumber a line number
130: * @return a new breakpoint for given parameters
131: */
132: public static JspLineBreakpoint create(String url, int lineNumber) {
133: return new JspLineBreakpoint(url, lineNumber);
134: }
135:
136: /**
137: * Gets value of suspend property.
138: *
139: * @return value of suspend property
140: */
141: public int getSuspend() {
142: return suspend;
143: }
144:
145: /**
146: * Sets value of suspend property.
147: *
148: * @param s a new value of suspend property
149: */
150: public void setSuspend(int s) {
151: if (s == suspend)
152: return;
153: int old = suspend;
154: suspend = s;
155: if (javalb != null) {
156: javalb.setSuspend(s);
157: }
158: firePropertyChange(PROP_SUSPEND, new Integer(old), new Integer(
159: s));
160: }
161:
162: /**
163: * Gets value of hidden property.
164: *
165: * @return value of hidden property
166: */
167: public boolean isHidden() {
168: return hidden;
169: }
170:
171: /**
172: * Sets value of hidden property.
173: *
174: * @param h a new value of hidden property
175: */
176: public void setHidden(boolean h) {
177: if (h == hidden)
178: return;
179: boolean old = hidden;
180: hidden = h;
181: firePropertyChange(PROP_HIDDEN, Boolean.valueOf(old), Boolean
182: .valueOf(h));
183: }
184:
185: /**
186: * Gets value of print text property.
187: *
188: * @return value of print text property
189: */
190: public String getPrintText() {
191: return printText;
192: }
193:
194: /**
195: * Sets value of print text property.
196: *
197: * @param printText a new value of print text property
198: */
199: public void setPrintText(String printText) {
200: if (this .printText == printText)
201: return;
202: String old = this .printText;
203: this .printText = printText;
204: if (javalb != null) {
205: javalb.setPrintText(printText);
206: }
207: firePropertyChange(PROP_PRINT_TEXT, old, printText);
208: }
209:
210: /**
211: * Called when breakpoint is removed.
212: */
213: protected void dispose() {
214: if (javalb != null) {
215: DebuggerManager.getDebuggerManager().removeBreakpoint(
216: javalb);
217: }
218: }
219:
220: /**
221: * Test whether the breakpoint is enabled.
222: *
223: * @return <code>true</code> if so
224: */
225: public boolean isEnabled() {
226: return enabled;
227: }
228:
229: /**
230: * Disables the breakpoint.
231: */
232: public void disable() {
233: if (!enabled)
234: return;
235: enabled = false;
236: if (javalb != null) {
237: javalb.disable();
238: }
239: firePropertyChange(PROP_ENABLED, Boolean.TRUE, Boolean.FALSE);
240: }
241:
242: /**
243: * Enables the breakpoint.
244: */
245: public void enable() {
246: if (enabled)
247: return;
248: enabled = true;
249: if (javalb != null) {
250: javalb.enable();
251: }
252: firePropertyChange(PROP_ENABLED, Boolean.FALSE, Boolean.TRUE);
253: }
254:
255: /**
256: * Sets name of class to stop on.
257: *
258: * @param cn a new name of class to stop on
259: */
260: public void setURL(String url) {
261: if ((url == this .url)
262: || ((url != null) && (this .url != null) && url
263: .equals(this .url)))
264: return;
265: String old = url;
266: this .url = url;
267: firePropertyChange(PROP_URL, old, url);
268: }
269:
270: /**
271: * Gets name of class to stop on.
272: *
273: * @return name of class to stop on
274: */
275: public String getURL() {
276: return url;
277: }
278:
279: /**
280: * Gets number of line to stop on.
281: *
282: * @return line number to stop on
283: */
284: public int getLineNumber() {
285: return lineNumber;
286: }
287:
288: /**
289: * Sets number of line to stop on.
290: *
291: * @param ln a line number to stop on
292: */
293: public void setLineNumber(int ln) {
294: if (ln == lineNumber)
295: return;
296: int old = lineNumber;
297: lineNumber = ln;
298: if (javalb != null) {
299: javalb.setLineNumber(ln);
300: }
301: firePropertyChange(PROP_LINE_NUMBER, new Integer(old),
302: new Integer(getLineNumber()));
303: }
304:
305: /**
306: * Sets condition.
307: *
308: * @param c a new condition
309: */
310: public void setCondition(String c) {
311: if (c != null)
312: c = c.trim();
313: if ((c == condition)
314: || ((c != null) && (condition != null) && condition
315: .equals(c)))
316: return;
317: String old = condition;
318: condition = c;
319: if (javalb != null) {
320: javalb.setCondition(c);
321: }
322: firePropertyChange(PROP_CONDITION, old, condition);
323: }
324:
325: /**
326: * Returns condition.
327: *
328: * @return cond a condition
329: */
330: public String getCondition() {
331: return condition;
332: }
333:
334: /**
335: * Returns a string representation of this object.
336: *
337: * @return a string representation of the object
338: */
339: public String toString() {
340: return "JspLineBreakpoint " + url + " : " + lineNumber;
341: }
342:
343: /**
344: * Getter for property javalb.
345: * @return Value of property javalb.
346: */
347: public LineBreakpoint getJavalb() {
348: return javalb;
349: }
350:
351: /**
352: * Setter for property javalb.
353: * @param javalb New value of property javalb.
354: */
355: public void setJavalb(LineBreakpoint javalb) {
356: this .javalb = javalb;
357: }
358:
359: /**
360: * Sets group name of this JSP breakpoint and also sets the same group name for underlying Java breakpoint.
361: *
362: * @param newGroupName name of the group
363: */
364: public void setGroupName(String newGroupName) {
365: super.setGroupName(newGroupName);
366: javalb.setGroupName(newGroupName);
367: }
368: }
|