~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to debuggerjpda/api/src/org/netbeans/api/debugger/jpda/ExceptionBreakpoint.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.api.debugger.jpda;
 
43
 
 
44
 
 
45
/**
 
46
 * Notifies about exceptions throw in debugged JVM.
 
47
 *
 
48
 * <br><br>
 
49
 * <b>How to use it:</b>
 
50
 * <pre style="background-color: rgb(255, 255, 153);">
 
51
 *    DebuggerManager.addBreakpoint (ExceptionBreakpoint.create (
 
52
 *        "java.lang.NullPointerException",
 
53
 *        ExceptionBreakpoint.TYPE_EXCEPTION_UNCATCHED
 
54
 *    ));</pre>
 
55
 * This breakpoint stops when NullPointerException is throw and uncatched.
 
56
 *
 
57
 * @author Jan Jancura
 
58
 */
 
59
public final class ExceptionBreakpoint extends JPDABreakpoint {
 
60
 
 
61
    /** Property name constant */
 
62
    public static final String          PROP_EXCEPTION_CLASS_NAME = "exceptionClassName"; // NOI18N
 
63
    /** Property name constant */
 
64
    public static final String          PROP_CLASS_FILTERS = "classFilters"; // NOI18N
 
65
    /** Property name constant */
 
66
    public static final String          PROP_CLASS_EXCLUSION_FILTERS = "classExclusionFilters"; // NOI18N
 
67
    /** Property name constant. */
 
68
    public static final String          PROP_CATCH_TYPE = "catchType"; // NOI18N
 
69
    /** Property name constant. */
 
70
    public static final String          PROP_CONDITION = "condition"; // NOI18N
 
71
 
 
72
    /** Catch type constant. */
 
73
    public static final int             TYPE_EXCEPTION_CATCHED = 1;
 
74
    /** Catch type constant. */
 
75
    public static final int             TYPE_EXCEPTION_UNCATCHED = 2;
 
76
    /** Catch type constant. */
 
77
    public static final int             TYPE_EXCEPTION_CATCHED_UNCATCHED = 3;
 
78
 
 
79
    private String                      exceptionClassName = "";
 
80
    private String[]                    classFilters = new String [0];
 
81
    private String[]                    classExclusionFilters = new String [0];
 
82
    private int                         catchType = TYPE_EXCEPTION_UNCATCHED;
 
83
    private String                      condition = ""; // NOI18N
 
84
 
 
85
    
 
86
    private ExceptionBreakpoint () {
 
87
    }
 
88
    
 
89
    /**
 
90
     * Creates a new breakpoint for given parameters.
 
91
     *
 
92
     * @param exceptionClassName class name filter
 
93
     * @param catchType one of constants: TYPE_EXCEPTION_CATCHED, 
 
94
     *   TYPE_EXCEPTION_UNCATCHED, TYPE_EXCEPTION_CATCHED_UNCATCHED
 
95
     * @return a new breakpoint for given parameters
 
96
     */
 
97
    public static ExceptionBreakpoint create (
 
98
        String exceptionClassName,
 
99
        int catchType
 
100
    ) {
 
101
        ExceptionBreakpoint b = new ExceptionBreakpoint ();
 
102
        b.setExceptionClassName (exceptionClassName);
 
103
        b.setCatchType (catchType);
 
104
        return b;
 
105
    }
 
106
    
 
107
    /**
 
108
     * Get name of exception class to stop on.
 
109
     *
 
110
     * @return name of exception class to stop on
 
111
     */
 
112
    public String getExceptionClassName () {
 
113
        return exceptionClassName;
 
114
    }
 
115
 
 
116
    /**
 
117
     * Set name of exception class to stop on.
 
118
     *
 
119
     * @param cn a new name of exception class to stop on.
 
120
     */
 
121
    public void setExceptionClassName (String cn) {
 
122
        if (cn != null) {
 
123
            cn = cn.trim();
 
124
        }
 
125
        if ( (cn == exceptionClassName) ||
 
126
             ((cn != null) && (exceptionClassName != null) && exceptionClassName.equals (cn))
 
127
        ) return;
 
128
        Object old = exceptionClassName;
 
129
        exceptionClassName = cn;
 
130
        firePropertyChange (PROP_EXCEPTION_CLASS_NAME, old, exceptionClassName);
 
131
    }
 
132
    
 
133
    /**
 
134
     * Get list of class filters to stop on.
 
135
     *
 
136
     * @return list of class filters to stop on
 
137
     */
 
138
    public String[] getClassFilters () {
 
139
        return classFilters;
 
140
    }
 
141
 
 
142
    /**
 
143
     * Set list of class filters to stop on.
 
144
     *
 
145
     * @param classFilters a new value of class filters property
 
146
     */
 
147
    public void setClassFilters (String[] classFilters) {
 
148
        if (classFilters == this.classFilters) return;
 
149
        Object old = this.classFilters;
 
150
        this.classFilters = classFilters;
 
151
        firePropertyChange (PROP_CLASS_FILTERS, old, classFilters);
 
152
    }
 
153
 
 
154
    /**
 
155
     * Get list of class exclusion filters to stop on.
 
156
     *
 
157
     * @return list of class exclusion filters to stop on
 
158
     */
 
159
    public String[] getClassExclusionFilters () {
 
160
        return classExclusionFilters;
 
161
    }
 
162
 
 
163
    /**
 
164
     * Set list of class exclusion filters to stop on.
 
165
     *
 
166
     * @param classExclusionFilters a new value of class exclusion filters property
 
167
     */
 
168
    public void setClassExclusionFilters (String[] classExclusionFilters) {
 
169
        if (classExclusionFilters == this.classExclusionFilters) return;
 
170
        Object old = this.classExclusionFilters;
 
171
        this.classExclusionFilters = classExclusionFilters;
 
172
        firePropertyChange (PROP_CLASS_EXCLUSION_FILTERS, old, classExclusionFilters);
 
173
    }
 
174
    
 
175
    /**
 
176
     * Returns condition.
 
177
     *
 
178
     * @return cond a condition
 
179
     */
 
180
    public String getCondition () {
 
181
        return condition;
 
182
    }
 
183
 
 
184
    /**
 
185
     * Sets condition.
 
186
     *
 
187
     * @param cond a c new condition
 
188
     */
 
189
    public void setCondition (String cond) {
 
190
        if (cond != null) {
 
191
            cond = cond.trim();
 
192
        }
 
193
        String old = condition;
 
194
        condition = cond;
 
195
        firePropertyChange (PROP_CONDITION, old, cond);
 
196
    }
 
197
 
 
198
    /**
 
199
     * Returns breakpoint type property value.
 
200
     *
 
201
     * @return breakpoint type property value.
 
202
     */
 
203
    public int getCatchType () {
 
204
        return catchType;
 
205
    }
 
206
 
 
207
    /**
 
208
     * Sets breakpoint type property value.
 
209
     *
 
210
     * @param catchType a new value of breakpoint type property value
 
211
     */
 
212
    public void setCatchType (int catchType) {
 
213
        if (catchType == this.catchType) return;
 
214
        if ( (catchType & (TYPE_EXCEPTION_CATCHED | TYPE_EXCEPTION_UNCATCHED)) == 0
 
215
           ) throw new IllegalArgumentException  ();
 
216
        int old = this.catchType;
 
217
        this.catchType = catchType;
 
218
        firePropertyChange (
 
219
            PROP_CATCH_TYPE, 
 
220
            new Integer (old), 
 
221
            new Integer (catchType)
 
222
        );
 
223
    }
 
224
 
 
225
    /**
 
226
     * Returns a string representation of this object.
 
227
     *
 
228
     * @return  a string representation of the object
 
229
     */
 
230
    public String toString () {
 
231
        return "ExceptionBreakpoint" + exceptionClassName;
 
232
    }
 
233
}