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-2007 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;
043:
044: import java.beans.PropertyChangeListener;
045: import java.beans.PropertyChangeSupport;
046:
047: /**
048: * Abstract definition of breakpoint.
049: *
050: * @author Jan Jancura
051: */
052: public abstract class Breakpoint {
053:
054: /** Property name for enabled status of the breakpoint. */
055: public static final String PROP_ENABLED = "enabled"; // NOI18N
056: /** Property name for disposed state of the breakpoint. */
057: public static final String PROP_DISPOSED = "disposed"; // NOI18N
058: /** Property name for name of group of the breakpoint. */
059: public static final String PROP_GROUP_NAME = "groupName"; // NOI18N
060: /** Property name for breakpoint validity */
061: public static final String PROP_VALIDITY = "validity"; // NOI18N
062: /** Property name constant. */
063: public static final String PROP_HIT_COUNT_FILTER = "hitCountFilter"; // NOI18N
064:
065: /** Validity values */
066: public static enum VALIDITY {
067: UNKNOWN, VALID, INVALID
068: }
069:
070: /** The style of filtering of hit counts.
071: * The breakpoint is reported when the actual hit count is "equal to",
072: * "greater than" or "multiple of" the number specified by the hit count filter. */
073: public static enum HIT_COUNT_FILTERING_STYLE {
074: EQUAL, GREATER, MULTIPLE
075: }
076:
077: /** Support for property listeners. */
078: private PropertyChangeSupport pcs;
079: private String groupName = "";
080: private VALIDITY validity = VALIDITY.UNKNOWN;
081: private String validityMessage;
082: private int hitCountFilter;
083: private HIT_COUNT_FILTERING_STYLE hitCountFilteringStyle;
084:
085: {
086: pcs = new PropertyChangeSupport(this );
087: }
088:
089: /**
090: * Called when breakpoint is removed.
091: */
092: protected void dispose() {
093: }
094:
095: /**
096: * Test whether the breakpoint is enabled.
097: *
098: * @return <code>true</code> if so
099: */
100: public abstract boolean isEnabled();
101:
102: /**
103: * Disables the breakpoint.
104: */
105: public abstract void disable();
106:
107: /**
108: * Enables the breakpoint.
109: */
110: public abstract void enable();
111:
112: /**
113: * Get the validity of this breakpoint.
114: * @return The breakpoint validity.
115: */
116: public final synchronized VALIDITY getValidity() {
117: return validity;
118: }
119:
120: /**
121: * Get the message describing the current validity. For invalid breakpoints
122: * this should describe the reason why it is invalid.<p>
123: * Intended for use by ui implementation code, NodeModel.getShortDescription(), for example.
124: * @return The validity message.
125: */
126: public final synchronized String getValidityMessage() {
127: return validityMessage;
128: }
129:
130: /**
131: * Set the validity of this breakpoint.
132: * @param validity The new breakpoint validity.
133: * @param reason The message describing why is this validity being set, or <code>null</code>.
134: */
135: protected final void setValidity(VALIDITY validity, String reason) {
136: VALIDITY old;
137: synchronized (this ) {
138: this .validityMessage = reason;
139: if (this .validity == validity)
140: return;
141: old = this .validity;
142: this .validity = validity;
143: }
144: firePropertyChange(PROP_VALIDITY, old, validity);
145: }
146:
147: /**
148: * Get the hit count filter.
149: * @return a positive hit count filter, or <code>zero</code> when no hit count filter is set.
150: */
151: public final synchronized int getHitCountFilter() {
152: return hitCountFilter;
153: }
154:
155: /**
156: * Get the style of hit count filtering.
157: * @return the style of hit count filtering, or <cpde>null</code> when no count filter is set.
158: */
159: public final synchronized HIT_COUNT_FILTERING_STYLE getHitCountFilteringStyle() {
160: return hitCountFilteringStyle;
161: }
162:
163: /**
164: * Set the hit count filter and the style of filtering.
165: * @param hitCountFilter a positive hit count filter, or <code>zero</code> to unset the filter.
166: * @param hitCountFilteringStyle the style of hit count filtering.
167: * Can be <code>null</code> only when <code>hitCountFilter == 0</code>.
168: */
169: public final void setHitCountFilter(int hitCountFilter,
170: HIT_COUNT_FILTERING_STYLE hitCountFilteringStyle) {
171: Object[] old;
172: Object[] newProp;
173: synchronized (this ) {
174: if (hitCountFilter == this .hitCountFilter
175: && hitCountFilteringStyle == this .hitCountFilteringStyle) {
176: return;
177: }
178: if (hitCountFilteringStyle == null && hitCountFilter > 0) {
179: throw new NullPointerException(
180: "hitCountFilteringStyle must not be null.");
181: }
182: if (hitCountFilter == 0) {
183: hitCountFilteringStyle = null;
184: }
185: if (this .hitCountFilter == 0) {
186: old = null;
187: } else {
188: old = new Object[] { this .hitCountFilter,
189: this .hitCountFilteringStyle };
190: }
191: if (hitCountFilter == 0) {
192: newProp = null;
193: } else {
194: newProp = new Object[] { hitCountFilter,
195: hitCountFilteringStyle };
196: }
197: this .hitCountFilter = hitCountFilter;
198: this .hitCountFilteringStyle = hitCountFilteringStyle;
199: }
200: firePropertyChange(PROP_HIT_COUNT_FILTER, old, newProp);
201: }
202:
203: public String getGroupName() {
204: return groupName;
205: }
206:
207: public void setGroupName(String newGroupName) {
208: if (groupName.equals(newGroupName))
209: return;
210: String old = groupName;
211: groupName = newGroupName.intern();
212: firePropertyChange(PROP_GROUP_NAME, old, newGroupName);
213: }
214:
215: /**
216: * Add a listener to property changes.
217: *
218: * @param listener the listener to add
219: */
220: public synchronized void addPropertyChangeListener(
221: PropertyChangeListener listener) {
222: pcs.addPropertyChangeListener(listener);
223: }
224:
225: /**
226: * Remove a listener to property changes.
227: *
228: * @param listener the listener to remove
229: */
230: public synchronized void removePropertyChangeListener(
231: PropertyChangeListener listener) {
232: pcs.removePropertyChangeListener(listener);
233: }
234:
235: /**
236: * Adds a property change listener.
237: *
238: * @param propertyName a name of property to listen on
239: * @param l the listener to add
240: */
241: public void addPropertyChangeListener(String propertyName,
242: PropertyChangeListener l) {
243: pcs.addPropertyChangeListener(propertyName, l);
244: }
245:
246: /**
247: * Removes a property change listener.
248: *
249: * @param propertyName a name of property to stop listening on
250: * @param l the listener to remove
251: */
252: public void removePropertyChangeListener(String propertyName,
253: PropertyChangeListener l) {
254: pcs.removePropertyChangeListener(propertyName, l);
255: }
256:
257: /**
258: * Fire property change.
259: *
260: * @param name name of property
261: * @param o old value of property
262: * @param n new value of property
263: */
264: protected void firePropertyChange(String name, Object o, Object n) {
265: pcs.firePropertyChange(name, o, n);
266: }
267:
268: /**
269: * Called when breakpoint is removed.
270: */
271: void disposeOut() {
272: dispose();
273: firePropertyChange(PROP_DISPOSED, Boolean.FALSE, Boolean.TRUE);
274: }
275: }
|