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.api.debugger.jpda;
043:
044: import com.sun.jdi.request.EventRequest;
045:
046: import java.util.Collection;
047: import java.util.HashSet;
048: import java.util.Iterator;
049:
050: import org.netbeans.api.debugger.Breakpoint;
051: import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent;
052: import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener;
053:
054: /**
055: * Abstract definition of JPDA breakpoint.
056: *
057: * @author Jan Jancura
058: */
059: public class JPDABreakpoint extends Breakpoint {
060:
061: // static ..................................................................
062:
063: /** Property name constant. */
064: public static final String PROP_SUSPEND = "suspend"; // NOI18N
065: /** Property name constant. */
066: public static final String PROP_HIDDEN = "hidden"; // NOI18N
067: /** Property name constant. */
068: public static final String PROP_PRINT_TEXT = "printText"; // NOI18N
069:
070: /** Suspend property value constant. */
071: public static final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
072: /** Suspend property value constant. */
073: public static final int SUSPEND_EVENT_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
074: /** Suspend property value constant. */
075: public static final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
076:
077: // private variables .....................................................
078:
079: /** Set of actions. */
080: private boolean enabled = true;
081: private boolean hidden = false;
082: private int suspend = SUSPEND_ALL;
083: private String printText;
084: private Collection<JPDABreakpointListener> breakpointListeners = new HashSet<JPDABreakpointListener>();
085:
086: JPDABreakpoint() {
087: }
088:
089: // main methods ............................................................
090:
091: /**
092: * Gets value of suspend property.
093: *
094: * @return value of suspend property
095: */
096: public int getSuspend() {
097: return suspend;
098: }
099:
100: /**
101: * Sets value of suspend property.
102: *
103: * @param s a new value of suspend property
104: */
105: public void setSuspend(int s) {
106: if (s == suspend)
107: return;
108: int old = suspend;
109: suspend = s;
110: firePropertyChange(PROP_SUSPEND, new Integer(old), new Integer(
111: s));
112: }
113:
114: /**
115: * Gets value of hidden property.
116: *
117: * @return value of hidden property
118: */
119: public boolean isHidden() {
120: return hidden;
121: }
122:
123: /**
124: * Sets value of hidden property.
125: *
126: * @param h a new value of hidden property
127: */
128: public void setHidden(boolean h) {
129: if (h == hidden)
130: return;
131: boolean old = hidden;
132: hidden = h;
133: firePropertyChange(PROP_HIDDEN, Boolean.valueOf(old), Boolean
134: .valueOf(h));
135: }
136:
137: /**
138: * Gets value of print text property.
139: *
140: * @return value of print text property
141: */
142: public String getPrintText() {
143: return printText;
144: }
145:
146: /**
147: * Sets value of print text property.
148: *
149: * @param printText a new value of print text property
150: */
151: public void setPrintText(String printText) {
152: if (this .printText == printText)
153: return;
154: String old = this .printText;
155: this .printText = printText;
156: firePropertyChange(PROP_PRINT_TEXT, old, printText);
157: }
158:
159: /**
160: * Test whether the breakpoint is enabled.
161: *
162: * @return <code>true</code> if so
163: */
164: public boolean isEnabled() {
165: return enabled;
166: }
167:
168: /**
169: * Disables the breakpoint.
170: */
171: public void disable() {
172: if (!enabled)
173: return;
174: enabled = false;
175: firePropertyChange(PROP_ENABLED, Boolean.TRUE, Boolean.FALSE);
176: }
177:
178: /**
179: * Enables the breakpoint.
180: */
181: public void enable() {
182: if (enabled)
183: return;
184: enabled = true;
185: firePropertyChange(PROP_ENABLED, Boolean.FALSE, Boolean.TRUE);
186: }
187:
188: /**
189: * Adds a JPDABreakpointListener.
190: *
191: * @param listener the listener to add
192: */
193: public synchronized void addJPDABreakpointListener(
194: JPDABreakpointListener listener) {
195: breakpointListeners.add(listener);
196: }
197:
198: /**
199: * Removes a JPDABreakpointListener.
200: *
201: * @param listener the listener to remove
202: */
203: public synchronized void removeJPDABreakpointListener(
204: JPDABreakpointListener listener) {
205: breakpointListeners.remove(listener);
206: }
207:
208: /**
209: * Fire JPDABreakpointEvent.
210: *
211: * @param event a event to be fired
212: */
213: void fireJPDABreakpointChange(JPDABreakpointEvent event) {
214: Iterator<JPDABreakpointListener> i = new HashSet<JPDABreakpointListener>(
215: breakpointListeners).iterator();
216: while (i.hasNext())
217: i.next().breakpointReached(event);
218: }
219: }
|