KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.swing.event.ChangeEvent JavaDoc;
23 import javax.swing.event.ChangeListener JavaDoc;
24 import org.netbeans.api.debugger.Breakpoint;
25
26 /**
27  * Notifies about method entry events.
28  *
29  * <br><br>
30  * <b>How to use it:</b>
31  * <pre style="background-color: rgb(255, 255, 153);">
32  * DebuggerManager.addBreakpoint (MethodBreakpoint.create (
33  * "examples.texteditor.Ted*",
34  * "<init>
35  * ));</pre>
36  * This breakpoint stops when some initializer of class Ted or innercalsses is
37  * called.
38  *
39  * @author Jan Jancura
40  */

41 public class MethodBreakpoint extends JPDABreakpoint {
42
43     /** Property name constant */
44     public static final String JavaDoc PROP_METHOD_NAME = "methodName"; // NOI18N
45
/** Property name constant. */
46     public static final String JavaDoc PROP_BREAKPOINT_TYPE = "breakpointtType"; // NOI18N
47
/** Property name constant. */
48     public static final String JavaDoc PROP_CONDITION = "condition"; // NOI18N
49
/** Property name constant */
50     public static final String JavaDoc PROP_CLASS_FILTERS = "classFilters"; // NOI18N
51
/** Property name constant */
52     public static final String JavaDoc PROP_CLASS_EXCLUSION_FILTERS = "classExclusionFilters"; // NOI18N
53

54     /** Breakpoint type property value constant. */
55     public static final int TYPE_METHOD_ENTRY = 1;
56     /** Breakpoint type property value constant. */
57     public static final int TYPE_METHOD_EXIT = 2;
58
59     /** Property variable. */
60     private String JavaDoc[] classFilters = new String JavaDoc [0];
61     private String JavaDoc[] classExclusionFilters = new String JavaDoc [0];
62     private String JavaDoc methodName = "";
63     private int breakpointType = TYPE_METHOD_ENTRY;
64     private String JavaDoc condition = "";
65     
66     
67     private MethodBreakpoint () {
68     }
69     
70     /**
71      * Creates a new method breakpoint for given parameters.
72      *
73      * @param className a class name filter
74      * @param methodName a name of method
75      * @return a new breakpoint for given parameters
76      */

77     public static MethodBreakpoint create (
78         String JavaDoc className,
79         String JavaDoc methodName
80     ) {
81         MethodBreakpoint b = new MethodBreakpointImpl ();
82         b.setClassFilters (new String JavaDoc[] {className});
83         b.setMethodName (methodName);
84         return b;
85     }
86     
87     /**
88      * Creates a new method breakpoint.
89      *
90      * @return a new method breakpoint
91      */

92     public static MethodBreakpoint create (
93     ) {
94         MethodBreakpoint b = new MethodBreakpointImpl ();
95         return b;
96     }
97
98     /**
99      * Get name of method to stop on.
100      *
101      * @return name of method to stop on
102      */

103     public String JavaDoc getMethodName () {
104         return methodName;
105     }
106
107     /**
108      * Set name of method to stop on.
109      *
110      * @param mn a name of method to stop on
111      */

112     public void setMethodName (String JavaDoc mn) {
113         if (mn != null) {
114             mn = mn.trim();
115         }
116         if ( (mn == methodName) ||
117              ((mn != null) && (methodName != null) && methodName.equals (mn))
118         ) return;
119         String JavaDoc old = methodName;
120         methodName = mn;
121         firePropertyChange (PROP_METHOD_NAME, old, mn);
122     }
123     
124     /**
125      * Returns condition.
126      *
127      * @return cond a condition
128      */

129     public String JavaDoc getCondition () {
130         return condition;
131     }
132     
133     /**
134      * Sets condition.
135      *
136      * @param cond a c new condition
137      */

138     public void setCondition (String JavaDoc cond) {
139         if (cond != null) {
140             cond = cond.trim();
141         }
142         String JavaDoc old = condition;
143         condition = cond;
144         firePropertyChange (PROP_CONDITION, old, cond);
145     }
146
147     /**
148      * Returns type of this breakpoint.
149      *
150      * @return type of this breakpoint
151      */

152     public int getBreakpointType () {
153         return breakpointType;
154     }
155
156     /**
157      * Sets type of this breakpoint (TYPE_METHOD_ENTRY or TYPE_METHOD_EXIT).
158      *
159      * @param breakpointType a new value of breakpoint type property
160      */

161     public void setBreakpointType (int breakpointType) {
162         if (breakpointType == this.breakpointType) return;
163         if ((breakpointType & (TYPE_METHOD_ENTRY | TYPE_METHOD_EXIT)) == 0)
164             throw new IllegalArgumentException JavaDoc ();
165         int old = this.breakpointType;
166         this.breakpointType = breakpointType;
167         firePropertyChange (PROP_BREAKPOINT_TYPE, new Integer JavaDoc (old), new Integer JavaDoc (breakpointType));
168     }
169
170     /**
171      * Get list of class filters to stop on.
172      *
173      * @return list of class filters to stop on
174      */

175     public String JavaDoc[] getClassFilters () {
176         return classFilters;
177     }
178
179     /**
180      * Set list of class filters to stop on.
181      *
182      * @param classFilters a new value of class filters property
183      */

184     public void setClassFilters (String JavaDoc[] classFilters) {
185         if (classFilters == this.classFilters) return;
186         Object JavaDoc old = this.classFilters;
187         this.classFilters = classFilters;
188         firePropertyChange (PROP_CLASS_FILTERS, old, classFilters);
189     }
190
191     /**
192      * Get list of class exclusion filters to stop on.
193      *
194      * @return list of class exclusion filters to stop on
195      */

196     public String JavaDoc[] getClassExclusionFilters () {
197         return classExclusionFilters;
198     }
199
200     /**
201      * Set list of class exclusion filters to stop on.
202      *
203      * @param classExclusionFilters a new value of class exclusion filters property
204      */

205     public void setClassExclusionFilters (String JavaDoc[] classExclusionFilters) {
206         if (classExclusionFilters == this.classExclusionFilters) return;
207         Object JavaDoc old = this.classExclusionFilters;
208         this.classExclusionFilters = classExclusionFilters;
209         firePropertyChange (PROP_CLASS_EXCLUSION_FILTERS, old, classExclusionFilters);
210     }
211
212     /**
213      * Returns a string representation of this object.
214      *
215      * @return a string representation of the object
216      */

217     public String JavaDoc toString () {
218         return "MethodBreakpoint " + java.util.Arrays.asList(classFilters).toString() + "." + methodName;
219     }
220     
221     private static final class MethodBreakpointImpl extends MethodBreakpoint implements ChangeListener JavaDoc {
222         
223         public void stateChanged(ChangeEvent JavaDoc chev) {
224             Object JavaDoc source = chev.getSource();
225             if (source instanceof Breakpoint.VALIDITY) {
226                 setValidity((Breakpoint.VALIDITY) source, chev.toString());
227             } else {
228                 throw new UnsupportedOperationException JavaDoc(chev.toString());
229             }
230         }
231     }
232 }
233
Popular Tags