KickJava   Java API By Example, From Geeks To Geeks.

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


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 class load and class unload events.
25  *
26  * <br><br>
27  * <b>How to use it:</b>
28  * <pre style="background-color: rgb(255, 255, 153);">
29  * DebuggerManager.addBreakpoint (ClassLoadUnloadBreakpoint.create (
30  * "org.netbeans.modules.editor.*",
31  * false,
32  * ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED
33  * ));</pre>
34  * This breakpoint stops when some class from org.netbeans.modules.editor
35  * package is loaded.
36  *
37  * @author Jan Jancura
38  */

39 public final class ClassLoadUnloadBreakpoint extends JPDABreakpoint {
40
41     /** Property name constant */
42     public static final String JavaDoc PROP_CLASS_FILTERS = "classFilters"; // NOI18N
43
/** Property name constant */
44     public static final String JavaDoc PROP_CLASS_EXCLUSION_FILTERS = "classExclusionFilters"; // NOI18N
45
/** Name of property for breakpoint type. */
46     public static final String JavaDoc PROP_BREAKPOINT_TYPE = "breakpointType"; // NOI18N
47

48     /** Catch type property value constant. */
49     public static final int TYPE_CLASS_LOADED = 1;
50     /** Catch type property value constant. */
51     public static final int TYPE_CLASS_UNLOADED = 2;
52     /** Catch type property value constant. */
53     public static final int TYPE_CLASS_LOADED_UNLOADED = 3;
54
55     /** Property variable. */
56     private int type = TYPE_CLASS_LOADED;
57     private String JavaDoc[] classFilters = new String JavaDoc [0];
58     private String JavaDoc[] classExclusionFilters = new String JavaDoc [0];
59
60     
61     private ClassLoadUnloadBreakpoint () {
62     }
63     
64     /**
65      * Creates a new breakpoint for given parameters.
66      *
67      * @param classNameFilter class name filter
68      * @param isExclusionFilter if true filter is used as exclusion filter
69      * @param breakpointType one of constants: TYPE_CLASS_LOADED,
70      * TYPE_CLASS_UNLOADED, TYPE_CLASS_LOADED_UNLOADED
71      * @return a new breakpoint for given parameters
72      */

73     public static ClassLoadUnloadBreakpoint create (
74         String JavaDoc classNameFilter,
75         boolean isExclusionFilter,
76         int breakpointType
77     ) {
78         ClassLoadUnloadBreakpoint b = new ClassLoadUnloadBreakpoint ();
79         if (isExclusionFilter)
80             b.setClassExclusionFilters (new String JavaDoc[] {classNameFilter});
81         else
82             b.setClassFilters (new String JavaDoc[] {classNameFilter});
83         b.setBreakpointType (breakpointType);
84         return b;
85     }
86     
87     /**
88      * Creates a new breakpoint for given parameters.
89      *
90      * @param breakpointType one of constants: TYPE_CLASS_LOADED,
91      * TYPE_CLASS_UNLOADED, TYPE_CLASS_LOADED_UNLOADED
92      * @return a new breakpoint for given parameters
93      */

94     public static ClassLoadUnloadBreakpoint create (
95         int breakpointType
96     ) {
97         ClassLoadUnloadBreakpoint b = new ClassLoadUnloadBreakpoint ();
98         b.setBreakpointType (breakpointType);
99         return b;
100     }
101
102     /**
103      * Returns type of breakpoint.
104      *
105      * @return type of breakpoint
106      */

107     public int getBreakpointType () {
108         return type;
109     }
110
111     /**
112      * Sets type of breakpoint.
113      *
114      * @param type a new value of breakpoint type property
115      */

116     public void setBreakpointType (int type) {
117         if (type == this.type) return;
118         if ((type & (TYPE_CLASS_LOADED | TYPE_CLASS_UNLOADED)) == 0)
119             throw new IllegalArgumentException JavaDoc ();
120         int old = this.type;
121         this.type = type;
122         firePropertyChange (PROP_BREAKPOINT_TYPE, new Integer JavaDoc (old), new Integer JavaDoc (type));
123     }
124
125     /**
126      * Get list of class filters to stop on.
127      *
128      * @return list of class filters to stop on
129      */

130     public String JavaDoc[] getClassFilters () {
131         return classFilters;
132     }
133
134     /**
135      * Set list of class filters to stop on.
136      *
137      * @param classFilters a new value of class filters property
138      */

139     public void setClassFilters (String JavaDoc[] classFilters) {
140         if (classFilters == this.classFilters) return;
141         Object JavaDoc old = this.classFilters;
142         this.classFilters = classFilters;
143         firePropertyChange (PROP_CLASS_FILTERS, old, classFilters);
144     }
145
146     /**
147      * Get list of class exclusion filters to stop on.
148      *
149      * @return list of class exclusion filters to stop on
150      */

151     public String JavaDoc[] getClassExclusionFilters () {
152         return classExclusionFilters;
153     }
154
155     /**
156      * Set list of class exclusion filters to stop on.
157      *
158      * @param classExclusionFilters a new value of class exclusion filters property
159      */

160     public void setClassExclusionFilters (String JavaDoc[] classExclusionFilters) {
161         if (classExclusionFilters == this.classExclusionFilters) return;
162         Object JavaDoc old = this.classExclusionFilters;
163         this.classExclusionFilters = classExclusionFilters;
164         firePropertyChange (PROP_CLASS_EXCLUSION_FILTERS, old, classExclusionFilters);
165     }
166
167     /**
168      * Returns a string representation of this object.
169      *
170      * @return a string representation of the object
171      */

172     public String JavaDoc toString () {
173         return "ClassLoadUnloadBreakpoint " + classFilters;
174     }
175 }
176
Popular Tags