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.jpda;
043:
044: /**
045: * Notifies about exceptions throw in debugged JVM.
046: *
047: * <br><br>
048: * <b>How to use it:</b>
049: * <pre style="background-color: rgb(255, 255, 153);">
050: * DebuggerManager.addBreakpoint (ExceptionBreakpoint.create (
051: * "java.lang.NullPointerException",
052: * ExceptionBreakpoint.TYPE_EXCEPTION_UNCATCHED
053: * ));</pre>
054: * This breakpoint stops when NullPointerException is throw and uncatched.
055: *
056: * @author Jan Jancura
057: */
058: public final class ExceptionBreakpoint extends JPDABreakpoint {
059:
060: /** Property name constant */
061: public static final String PROP_EXCEPTION_CLASS_NAME = "exceptionClassName"; // NOI18N
062: /** Property name constant */
063: public static final String PROP_CLASS_FILTERS = "classFilters"; // NOI18N
064: /** Property name constant */
065: public static final String PROP_CLASS_EXCLUSION_FILTERS = "classExclusionFilters"; // NOI18N
066: /** Property name constant. */
067: public static final String PROP_CATCH_TYPE = "catchType"; // NOI18N
068: /** Property name constant. */
069: public static final String PROP_CONDITION = "condition"; // NOI18N
070:
071: /** Catch type constant. */
072: public static final int TYPE_EXCEPTION_CATCHED = 1;
073: /** Catch type constant. */
074: public static final int TYPE_EXCEPTION_UNCATCHED = 2;
075: /** Catch type constant. */
076: public static final int TYPE_EXCEPTION_CATCHED_UNCATCHED = 3;
077:
078: private String exceptionClassName = "";
079: private String[] classFilters = new String[0];
080: private String[] classExclusionFilters = new String[0];
081: private int catchType = TYPE_EXCEPTION_UNCATCHED;
082: private String condition = ""; // NOI18N
083:
084: private ExceptionBreakpoint() {
085: }
086:
087: /**
088: * Creates a new breakpoint for given parameters.
089: *
090: * @param exceptionClassName class name filter
091: * @param catchType one of constants: TYPE_EXCEPTION_CATCHED,
092: * TYPE_EXCEPTION_UNCATCHED, TYPE_EXCEPTION_CATCHED_UNCATCHED
093: * @return a new breakpoint for given parameters
094: */
095: public static ExceptionBreakpoint create(String exceptionClassName,
096: int catchType) {
097: ExceptionBreakpoint b = new ExceptionBreakpoint();
098: b.setExceptionClassName(exceptionClassName);
099: b.setCatchType(catchType);
100: return b;
101: }
102:
103: /**
104: * Get name of exception class to stop on.
105: *
106: * @return name of exception class to stop on
107: */
108: public String getExceptionClassName() {
109: return exceptionClassName;
110: }
111:
112: /**
113: * Set name of exception class to stop on.
114: *
115: * @param cn a new name of exception class to stop on.
116: */
117: public void setExceptionClassName(String cn) {
118: if (cn != null) {
119: cn = cn.trim();
120: }
121: if ((cn == exceptionClassName)
122: || ((cn != null) && (exceptionClassName != null) && exceptionClassName
123: .equals(cn)))
124: return;
125: Object old = exceptionClassName;
126: exceptionClassName = cn;
127: firePropertyChange(PROP_EXCEPTION_CLASS_NAME, old,
128: exceptionClassName);
129: }
130:
131: /**
132: * Get list of class filters to stop on.
133: *
134: * @return list of class filters to stop on
135: */
136: public String[] getClassFilters() {
137: return classFilters;
138: }
139:
140: /**
141: * Set list of class filters to stop on.
142: *
143: * @param classFilters a new value of class filters property
144: */
145: public void setClassFilters(String[] classFilters) {
146: if (classFilters == this .classFilters)
147: return;
148: Object old = this .classFilters;
149: this .classFilters = classFilters;
150: firePropertyChange(PROP_CLASS_FILTERS, old, classFilters);
151: }
152:
153: /**
154: * Get list of class exclusion filters to stop on.
155: *
156: * @return list of class exclusion filters to stop on
157: */
158: public String[] getClassExclusionFilters() {
159: return classExclusionFilters;
160: }
161:
162: /**
163: * Set list of class exclusion filters to stop on.
164: *
165: * @param classExclusionFilters a new value of class exclusion filters property
166: */
167: public void setClassExclusionFilters(String[] classExclusionFilters) {
168: if (classExclusionFilters == this .classExclusionFilters)
169: return;
170: Object old = this .classExclusionFilters;
171: this .classExclusionFilters = classExclusionFilters;
172: firePropertyChange(PROP_CLASS_EXCLUSION_FILTERS, old,
173: classExclusionFilters);
174: }
175:
176: /**
177: * Returns condition.
178: *
179: * @return cond a condition
180: */
181: public String getCondition() {
182: return condition;
183: }
184:
185: /**
186: * Sets condition.
187: *
188: * @param cond a c new condition
189: */
190: public void setCondition(String cond) {
191: if (cond != null) {
192: cond = cond.trim();
193: }
194: String old = condition;
195: condition = cond;
196: firePropertyChange(PROP_CONDITION, old, cond);
197: }
198:
199: /**
200: * Returns breakpoint type property value.
201: *
202: * @return breakpoint type property value.
203: */
204: public int getCatchType() {
205: return catchType;
206: }
207:
208: /**
209: * Sets breakpoint type property value.
210: *
211: * @param catchType a new value of breakpoint type property value
212: */
213: public void setCatchType(int catchType) {
214: if (catchType == this .catchType)
215: return;
216: if ((catchType & (TYPE_EXCEPTION_CATCHED | TYPE_EXCEPTION_UNCATCHED)) == 0)
217: throw new IllegalArgumentException();
218: int old = this .catchType;
219: this .catchType = catchType;
220: firePropertyChange(PROP_CATCH_TYPE, new Integer(old),
221: new Integer(catchType));
222: }
223:
224: /**
225: * Returns a string representation of this object.
226: *
227: * @return a string representation of the object
228: */
229: public String toString() {
230: return "ExceptionBreakpoint" + exceptionClassName;
231: }
232: }
|