KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > actions > SmartSteppingFilterImpl


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 package org.netbeans.modules.debugger.jpda.actions;
20
21 import java.beans.PropertyChangeListener JavaDoc;
22 import java.beans.PropertyChangeSupport JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Set JavaDoc;
28 import org.netbeans.api.debugger.Properties;
29 import org.netbeans.api.debugger.jpda.SmartSteppingFilter;
30
31
32 /**
33  *
34  * @author Jan Jancura
35  */

36 public class SmartSteppingFilterImpl implements SmartSteppingFilter {
37
38     private HashSet JavaDoc<String JavaDoc> filter = new HashSet JavaDoc<String JavaDoc>();
39     private ArrayList JavaDoc<String JavaDoc> exact = new ArrayList JavaDoc<String JavaDoc>();
40     private ArrayList JavaDoc<String JavaDoc> start = new ArrayList JavaDoc<String JavaDoc>();
41     private ArrayList JavaDoc<String JavaDoc> end = new ArrayList JavaDoc<String JavaDoc>();
42     private PropertyChangeSupport JavaDoc pcs;
43     {pcs = new PropertyChangeSupport JavaDoc (this);}
44
45     {
46         addExclusionPatterns (
47             (Set JavaDoc) Properties.getDefault ().getProperties ("debugger").
48                 getProperties ("sources").getProperties ("class_filters").
49                 getCollection (
50                     "enabled",
51                     Collections.EMPTY_SET
52                 )
53         );
54     }
55     
56     
57     /**
58      * Adds a set of new class exclusion filters. Filter is
59      * {@link java.lang.String} containing full class name. Filter can
60      * begin or end with '*' to define more than one class, for example
61      * "*.Ted", or "examples.texteditor.*".
62      *
63      * @param patterns a set of class exclusion filters to be added
64      */

65     public void addExclusionPatterns (Set JavaDoc<String JavaDoc> patterns) {
66         Set JavaDoc<String JavaDoc> reallyNew = new HashSet JavaDoc<String JavaDoc>(patterns);
67         reallyNew.removeAll (filter);
68         if (reallyNew.size () < 1) return;
69
70         filter.addAll (reallyNew);
71         refreshFilters (reallyNew);
72
73         pcs.firePropertyChange (PROP_EXCLUSION_PATTERNS, null, reallyNew);
74     }
75
76     /**
77      * Removes given set of class exclusion filters from filter.
78      *
79      * @param patterns a set of class exclusion filters to be added
80      */

81     public void removeExclusionPatterns (Set JavaDoc<String JavaDoc> patterns) {
82         filter.removeAll (patterns);
83         exact = new ArrayList JavaDoc<String JavaDoc>();
84         start = new ArrayList JavaDoc<String JavaDoc>();
85         end = new ArrayList JavaDoc<String JavaDoc>();
86         refreshFilters (filter);
87
88         pcs.firePropertyChange (PROP_EXCLUSION_PATTERNS, patterns, null);
89     }
90     
91     /**
92      * Returns list of all exclusion patterns.
93      */

94     public String JavaDoc[] getExclusionPatterns () {
95         String JavaDoc[] ef = new String JavaDoc [filter.size ()];
96         return filter.toArray (ef);
97     }
98
99     public boolean stopHere (String JavaDoc className) {
100         int i, k = exact.size ();
101         for (i = 0; i < k; i++) {
102             if (exact.get (i).equals (className)) return false;
103         }
104         k = start.size ();
105         for (i = 0; i < k; i++) {
106             if (className.startsWith (start.get (i))) return false;
107         }
108         k = end.size ();
109         for (i = 0; i < k; i++) {
110             if (className.endsWith (end.get (i))) return false;
111         }
112         return true;
113     }
114     
115     /**
116      * Adds property change listener.
117      *
118      * @param l new listener.
119      */

120     public void addPropertyChangeListener (PropertyChangeListener JavaDoc l) {
121         pcs.addPropertyChangeListener (l);
122     }
123
124     /**
125      * Removes property change listener.
126      *
127      * @param l removed listener.
128      */

129     public void removePropertyChangeListener (
130         PropertyChangeListener JavaDoc l
131     ) {
132         pcs.removePropertyChangeListener (l);
133     }
134
135     /**
136      * Updates exact, start and end filter lists.
137      */

138     private void refreshFilters (Set JavaDoc<String JavaDoc> newFilters) {
139         Iterator JavaDoc<String JavaDoc> i = newFilters.iterator ();
140         while (i.hasNext ()) {
141             String JavaDoc p = i.next ();
142             if (p.startsWith ("*"))
143                 end.add (p.substring (1));
144             else
145             if (p.endsWith ("*"))
146                 start.add (p.substring (0, p.length () - 1));
147             else
148                 exact.add (p);
149         }
150     }
151 }
152
Popular Tags