KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > debugger > jpda > ExceptionBreakpoint


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.api.debugger.jpda;
21
22
23 /**
24  * Notifies about exceptions throw in debugged JVM.
25  *
26  * <br><br>
27  * <b>How to use it:</b>
28  * <pre style="background-color: rgb(255, 255, 153);">
29  * DebuggerManager.addBreakpoint (ExceptionBreakpoint.create (
30  * "java.lang.NullPointerException",
31  * ExceptionBreakpoint.TYPE_EXCEPTION_UNCATCHED
32  * ));</pre>
33  * This breakpoint stops when NullPointerException is throw and uncatched.
34  *
35  * @author Jan Jancura
36  */

37 public final class ExceptionBreakpoint extends JPDABreakpoint {
38
39     /** Property name constant */
40     public static final String JavaDoc PROP_EXCEPTION_CLASS_NAME = "exceptionClassName"; // NOI18N
41
/** Property name constant. */
42     public static final String JavaDoc PROP_CATCH_TYPE = "catchType"; // NOI18N
43
/** Property name constant. */
44     public static final String JavaDoc PROP_CONDITION = "condition"; // NOI18N
45

46     /** Catch type constant. */
47     public static final int TYPE_EXCEPTION_CATCHED = 1;
48     /** Catch type constant. */
49     public static final int TYPE_EXCEPTION_UNCATCHED = 2;
50     /** Catch type constant. */
51     public static final int TYPE_EXCEPTION_CATCHED_UNCATCHED = 3;
52
53     private String JavaDoc exceptionClassName = "";
54     private int catchType = TYPE_EXCEPTION_UNCATCHED;
55     private String JavaDoc condition = ""; // NOI18N
56

57     
58     private ExceptionBreakpoint () {
59     }
60     
61     /**
62      * Creates a new breakpoint for given parameters.
63      *
64      * @param exceptionClassName class name filter
65      * @param catchType one of constants: TYPE_EXCEPTION_CATCHED,
66      * TYPE_EXCEPTION_UNCATCHED, TYPE_EXCEPTION_CATCHED_UNCATCHED
67      * @return a new breakpoint for given parameters
68      */

69     public static ExceptionBreakpoint create (
70         String JavaDoc exceptionClassName,
71         int catchType
72     ) {
73         ExceptionBreakpoint b = new ExceptionBreakpoint ();
74         b.setExceptionClassName (exceptionClassName);
75         b.setCatchType (catchType);
76         return b;
77     }
78     
79     /**
80      * Get name of exception class to stop on.
81      *
82      * @return name of exception class to stop on
83      */

84     public String JavaDoc getExceptionClassName () {
85         return exceptionClassName;
86     }
87
88     /**
89      * Set name of exception class to stop on.
90      *
91      * @param cn a new name of exception class to stop on.
92      */

93     public void setExceptionClassName (String JavaDoc cn) {
94         if (cn != null) {
95             cn = cn.trim();
96         }
97         if ( (cn == exceptionClassName) ||
98              ((cn != null) && (exceptionClassName != null) && exceptionClassName.equals (cn))
99         ) return;
100         Object JavaDoc old = exceptionClassName;
101         exceptionClassName = cn;
102         firePropertyChange (PROP_EXCEPTION_CLASS_NAME, old, exceptionClassName);
103     }
104     
105     /**
106      * Returns condition.
107      *
108      * @return cond a condition
109      */

110     public String JavaDoc getCondition () {
111         return condition;
112     }
113
114     /**
115      * Sets condition.
116      *
117      * @param cond a c new condition
118      */

119     public void setCondition (String JavaDoc cond) {
120         if (cond != null) {
121             cond = cond.trim();
122         }
123         String JavaDoc old = condition;
124         condition = cond;
125         firePropertyChange (PROP_CONDITION, old, cond);
126     }
127
128     /**
129      * Returns breakpoint type property value.
130      *
131      * @return breakpoint type property value.
132      */

133     public int getCatchType () {
134         return catchType;
135     }
136
137     /**
138      * Sets breakpoint type property value.
139      *
140      * @param catchType a new value of breakpoint type property value
141      */

142     public void setCatchType (int catchType) {
143         if (catchType == this.catchType) return;
144         if ( (catchType & (TYPE_EXCEPTION_CATCHED | TYPE_EXCEPTION_UNCATCHED)) == 0
145            ) throw new IllegalArgumentException JavaDoc ();
146         int old = this.catchType;
147         this.catchType = catchType;
148         firePropertyChange (
149             PROP_CATCH_TYPE,
150             new Integer JavaDoc (old),
151             new Integer JavaDoc (catchType)
152         );
153     }
154
155     /**
156      * Returns a string representation of this object.
157      *
158      * @return a string representation of the object
159      */

160     public String JavaDoc toString () {
161         return "ExceptionBreakpoint" + exceptionClassName;
162     }
163 }
164
Popular Tags