1 19 20 package org.netbeans.modules.debugger.jpda.breakpoints; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.Map ; 25 import java.util.WeakHashMap ; 26 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.netbeans.api.debugger.Properties; 29 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint; 30 import org.netbeans.api.debugger.jpda.ExceptionBreakpoint; 31 import org.netbeans.api.debugger.jpda.FieldBreakpoint; 32 import org.netbeans.api.debugger.jpda.JPDABreakpoint; 33 import org.netbeans.api.debugger.jpda.LineBreakpoint; 34 import org.netbeans.api.debugger.jpda.MethodBreakpoint; 35 import org.netbeans.api.debugger.jpda.ThreadBreakpoint; 36 37 38 42 public class BreakpointsReader implements Properties.Reader, PropertyChangeListener { 43 44 private Map <JPDABreakpoint, String > cachedClassNames = new WeakHashMap <JPDABreakpoint, String >(); 45 private Map <JPDABreakpoint, String > cachedSourceRoots = new WeakHashMap <JPDABreakpoint, String >(); 46 47 48 public String [] getSupportedClassNames () { 49 return new String [] { 50 JPDABreakpoint.class.getName (), 51 }; 52 } 53 54 synchronized String findCachedClassName(JPDABreakpoint b) { 55 return cachedClassNames.get(b); 56 } 57 58 synchronized String findCachedSourceRoot(JPDABreakpoint b) { 59 return cachedSourceRoots.get(b); 60 } 61 62 void storeCachedClassName(JPDABreakpoint b, String className) { 63 synchronized (this) { 64 if (b instanceof LineBreakpoint && !cachedClassNames.containsKey(b)) { 65 b.addPropertyChangeListener(LineBreakpoint.PROP_URL, this); 68 } 69 cachedClassNames.put(b, className); 70 } 71 PersistenceManager.storeBreakpoints(); 72 } 73 74 void storeCachedSourceRoot(JPDABreakpoint b, String sourceRoot) { 75 synchronized (this) { 76 cachedSourceRoots.put(b, sourceRoot); 77 } 78 PersistenceManager.storeBreakpoints(); 79 } 80 81 public Object read (String typeID, Properties properties) { 82 JPDABreakpoint b = null; 83 if (typeID.equals (LineBreakpoint.class.getName ()) || 85 typeID.equals (LineBreakpoint.class.getName ()+"$LineBreakpointImpl")) { 86 LineBreakpoint lb = LineBreakpoint.create ( 87 properties.getString (LineBreakpoint.PROP_URL, null), 88 properties.getInt (LineBreakpoint.PROP_LINE_NUMBER, 1) 89 ); 90 lb.setCondition ( 91 properties.getString (LineBreakpoint.PROP_CONDITION, "") 92 ); 93 lb.setPreferredClassName( 94 properties.getString(LineBreakpoint.PROP_PREFERRED_CLASS_NAME, null) 95 ); 96 synchronized (this) { 97 cachedClassNames.put(lb, properties.getString("className", null)); 98 lb.addPropertyChangeListener(LineBreakpoint.PROP_URL, this); 100 cachedSourceRoots.put(lb, properties.getString("sourceRoot", null)); 101 } 102 b = lb; 103 } 104 if (typeID.equals (MethodBreakpoint.class.getName ()) || 105 typeID.equals (MethodBreakpoint.class.getName ()+"$MethodBreakpointImpl")) { 106 MethodBreakpoint mb = MethodBreakpoint.create (); 107 mb.setClassFilters ( 108 (String []) properties.getArray ( 109 MethodBreakpoint.PROP_CLASS_FILTERS, 110 new String [0] 111 ) 112 ); 113 mb.setClassExclusionFilters ( 114 (String []) properties.getArray ( 115 MethodBreakpoint.PROP_CLASS_EXCLUSION_FILTERS, 116 new String [0] 117 ) 118 ); 119 mb.setMethodName ( 120 properties.getString (MethodBreakpoint.PROP_METHOD_NAME, "") 121 ); 122 mb.setCondition ( 123 properties.getString (MethodBreakpoint.PROP_CONDITION, "") 124 ); 125 mb.setBreakpointType ( 126 properties.getInt ( 127 MethodBreakpoint.PROP_BREAKPOINT_TYPE, 128 MethodBreakpoint.TYPE_METHOD_ENTRY 129 ) 130 ); 131 synchronized (this) { 132 cachedSourceRoots.put(mb, properties.getString("sourceRoot", null)); 133 } 134 b = mb; 135 } 136 if (typeID.equals (ClassLoadUnloadBreakpoint.class.getName ())) { 137 ClassLoadUnloadBreakpoint cb = ClassLoadUnloadBreakpoint.create ( 138 properties.getInt ( 139 ClassLoadUnloadBreakpoint.PROP_BREAKPOINT_TYPE, 140 ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED 141 ) 142 ); 143 cb.setClassFilters ( 144 (String []) properties.getArray ( 145 ClassLoadUnloadBreakpoint.PROP_CLASS_FILTERS, 146 new String [0] 147 ) 148 ); 149 cb.setClassExclusionFilters ( 150 (String []) properties.getArray ( 151 ClassLoadUnloadBreakpoint.PROP_CLASS_EXCLUSION_FILTERS, 152 new String [0] 153 ) 154 ); 155 synchronized (this) { 156 cachedSourceRoots.put(cb, properties.getString("sourceRoot", null)); 157 } 158 b = cb; 159 } 160 if (typeID.equals (ExceptionBreakpoint.class.getName ())) { 161 ExceptionBreakpoint eb = ExceptionBreakpoint.create ( 162 properties.getString ( 163 ExceptionBreakpoint.PROP_EXCEPTION_CLASS_NAME, 164 null 165 ), 166 properties.getInt ( 167 ExceptionBreakpoint.PROP_CATCH_TYPE, 168 ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED_UNCATCHED 169 ) 170 ); 171 eb.setCondition ( 172 properties.getString (ExceptionBreakpoint.PROP_CONDITION, "") 173 ); 174 synchronized (this) { 175 cachedSourceRoots.put(eb, properties.getString("sourceRoot", null)); 176 } 177 b = eb; 178 } 179 if (typeID.equals (FieldBreakpoint.class.getName ()) || 180 typeID.equals (FieldBreakpoint.class.getName ()+"$FieldBreakpointImpl")) { 181 FieldBreakpoint fb = FieldBreakpoint.create ( 182 properties.getString (FieldBreakpoint.PROP_CLASS_NAME, null), 183 properties.getString (FieldBreakpoint.PROP_FIELD_NAME, null), 184 properties.getInt ( 185 FieldBreakpoint.PROP_BREAKPOINT_TYPE, 186 FieldBreakpoint.TYPE_ACCESS 187 ) 188 ); 189 fb.setCondition ( 190 properties.getString (FieldBreakpoint.PROP_CONDITION, "") 191 ); 192 synchronized (this) { 193 cachedSourceRoots.put(fb, properties.getString("sourceRoot", null)); 194 } 195 b = fb; 196 } 197 if (typeID.equals (ThreadBreakpoint.class.getName ())) { 198 ThreadBreakpoint tb = ThreadBreakpoint.create ( 199 ); 200 tb.setBreakpointType ( 201 properties.getInt ( 202 ThreadBreakpoint.PROP_BREAKPOINT_TYPE, 203 ThreadBreakpoint.TYPE_THREAD_STARTED_OR_DEATH 204 ) 205 ); 206 b = tb; 207 } 208 assert b != null: "Unknown breakpoint type: \""+typeID+"\""; 209 b.setPrintText ( 210 properties.getString (JPDABreakpoint.PROP_PRINT_TEXT, "") 211 ); 212 b.setGroupName( 213 properties.getString (JPDABreakpoint.PROP_GROUP_NAME, "") 214 ); 215 b.setSuspend ( 216 properties.getInt ( 217 JPDABreakpoint.PROP_SUSPEND, 218 JPDABreakpoint.SUSPEND_ALL 219 ) 220 ); 221 if (properties.getBoolean (JPDABreakpoint.PROP_ENABLED, true)) 222 b.enable (); 223 else 224 b.disable (); 225 return b; 226 } 227 228 public void write (Object object, Properties properties) { 229 JPDABreakpoint b = (JPDABreakpoint) object; 230 properties.setString ( 231 JPDABreakpoint.PROP_PRINT_TEXT, 232 b.getPrintText () 233 ); 234 properties.setString ( 235 JPDABreakpoint.PROP_GROUP_NAME, 236 b.getGroupName () 237 ); 238 properties.setInt (JPDABreakpoint.PROP_SUSPEND, b.getSuspend ()); 239 properties.setBoolean (JPDABreakpoint.PROP_ENABLED, b.isEnabled ()); 240 241 if (object instanceof LineBreakpoint) { 242 LineBreakpoint lb = (LineBreakpoint) object; 243 properties.setString (LineBreakpoint.PROP_URL, lb.getURL ()); 244 properties.setInt ( 245 LineBreakpoint.PROP_LINE_NUMBER, 246 lb.getLineNumber () 247 ); 248 properties.setString ( 249 LineBreakpoint.PROP_CONDITION, 250 lb.getCondition () 251 ); 252 properties.setString( 253 LineBreakpoint.PROP_PREFERRED_CLASS_NAME, 254 lb.getPreferredClassName() 255 ); 256 properties.setString("className", findCachedClassName(lb)); 257 properties.setString("sourceRoot", findCachedSourceRoot(lb)); 258 return; 259 } else 260 if (object instanceof MethodBreakpoint) { 261 MethodBreakpoint mb = (MethodBreakpoint) object; 262 properties.setArray ( 263 MethodBreakpoint.PROP_CLASS_FILTERS, 264 mb.getClassFilters () 265 ); 266 properties.setArray ( 267 MethodBreakpoint.PROP_CLASS_EXCLUSION_FILTERS, 268 mb.getClassExclusionFilters () 269 ); 270 properties.setString ( 271 MethodBreakpoint.PROP_METHOD_NAME, 272 mb.getMethodName () 273 ); 274 properties.setString ( 275 MethodBreakpoint.PROP_CONDITION, 276 mb.getCondition () 277 ); 278 properties.setInt ( 279 MethodBreakpoint.PROP_BREAKPOINT_TYPE, 280 mb.getBreakpointType () 281 ); 282 properties.setString("sourceRoot", findCachedSourceRoot(mb)); 283 return; 284 } else 285 if (object instanceof ClassLoadUnloadBreakpoint) { 286 ClassLoadUnloadBreakpoint cb = (ClassLoadUnloadBreakpoint) object; 287 properties.setArray ( 288 ClassLoadUnloadBreakpoint.PROP_CLASS_FILTERS, 289 cb.getClassFilters () 290 ); 291 properties.setArray ( 292 ClassLoadUnloadBreakpoint.PROP_CLASS_EXCLUSION_FILTERS, 293 cb.getClassExclusionFilters () 294 ); 295 properties.setInt ( 296 ClassLoadUnloadBreakpoint.PROP_BREAKPOINT_TYPE, 297 cb.getBreakpointType () 298 ); 299 properties.setString("sourceRoot", findCachedSourceRoot(cb)); 300 return; 301 } else 302 if (object instanceof ExceptionBreakpoint) { 303 ExceptionBreakpoint eb = (ExceptionBreakpoint) object; 304 properties.setString ( 305 ExceptionBreakpoint.PROP_EXCEPTION_CLASS_NAME, 306 eb.getExceptionClassName () 307 ); 308 properties.setInt ( 309 ExceptionBreakpoint.PROP_CATCH_TYPE, 310 eb.getCatchType () 311 ); 312 properties.setString ( 313 ExceptionBreakpoint.PROP_CONDITION, 314 eb.getCondition () 315 ); 316 properties.setString("sourceRoot", findCachedSourceRoot(eb)); 317 return; 318 } else 319 if (object instanceof FieldBreakpoint) { 320 FieldBreakpoint fb = (FieldBreakpoint) object; 321 properties.setString ( 322 FieldBreakpoint.PROP_CLASS_NAME, 323 fb.getClassName () 324 ); 325 properties.setString ( 326 FieldBreakpoint.PROP_FIELD_NAME, 327 fb.getFieldName () 328 ); 329 properties.setString ( 330 FieldBreakpoint.PROP_CONDITION, 331 fb.getCondition () 332 ); 333 properties.setInt ( 334 FieldBreakpoint.PROP_BREAKPOINT_TYPE, 335 fb.getBreakpointType () 336 ); 337 properties.setString("sourceRoot", findCachedSourceRoot(fb)); 338 return; 339 } else 340 if (object instanceof ThreadBreakpoint) { 341 ThreadBreakpoint tb = (ThreadBreakpoint) object; 342 properties.setInt ( 343 ThreadBreakpoint.PROP_BREAKPOINT_TYPE, 344 tb.getBreakpointType () 345 ); 346 return; 347 } 348 return; 349 } 350 351 public void propertyChange(PropertyChangeEvent evt) { 352 if (LineBreakpoint.PROP_URL.equals(evt.getPropertyName())) { 353 LineBreakpoint lb = (LineBreakpoint) evt.getSource(); 354 storeCachedClassName(lb, null); 355 } 356 } 357 358 } 359 | Popular Tags |