1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import javax.swing.event.ChangeEvent ; 25 import javax.swing.event.ChangeListener ; 26 import org.netbeans.api.debugger.Breakpoint; 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.openide.ErrorManager; 29 import org.openide.filesystems.FileAttributeEvent; 30 import org.openide.filesystems.FileChangeListener; 31 import org.openide.filesystems.FileEvent; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileRenameEvent; 34 import org.openide.filesystems.FileStateInvalidException; 35 import org.openide.filesystems.URLMapper; 36 import org.openide.util.WeakListeners; 37 38 39 53 public class LineBreakpoint extends JPDABreakpoint { 54 55 56 public static final String PROP_LINE_NUMBER = "lineNumber"; 58 public static final String PROP_URL = "url"; 60 public static final String PROP_CONDITION = "condition"; 62 public static final String PROP_SOURCE_NAME = "sourceName"; 64 public static final String PROP_SOURCE_PATH = "sourcePath"; 66 public static final String PROP_STRATUM = "stratum"; 68 public static final String PROP_PREFERRED_CLASS_NAME = "classNamePreferred"; 70 private String url = ""; private int lineNumber; 72 private String condition = ""; private String sourceName = null; 74 private String sourcePath = null; 75 private String stratum = "Java"; private String className = null; 77 78 79 private LineBreakpoint (String url) { 80 this.url = url; 81 } 82 83 90 public static LineBreakpoint create ( 91 String url, 92 int lineNumber 93 ) { 94 LineBreakpoint b = new LineBreakpointImpl (url); 95 b.setLineNumber (lineNumber); 96 return b; 97 } 98 99 105 public String getURL () { 106 return url; 107 } 108 109 115 public void setURL (String url) { 116 String old; 117 synchronized (this) { 118 if (url == null) url = ""; 119 if ( (url == this.url) || 120 ((url != null) && (this.url != null) && url.equals (this.url)) 121 ) return; 122 old = this.url; 123 this.url = url; 124 } 125 firePropertyChange (PROP_URL, old, url); 126 } 127 128 133 public int getLineNumber () { 134 return lineNumber; 135 } 136 137 142 public void setLineNumber (int ln) { 143 int old; 144 synchronized (this) { 145 if (ln == lineNumber) return; 146 old = lineNumber; 147 lineNumber = ln; 148 } 149 firePropertyChange ( 150 PROP_LINE_NUMBER, 151 new Integer (old), 152 new Integer (ln) 153 ); 154 } 155 156 161 public String getCondition () { 162 return condition; 163 } 164 165 170 public void setCondition (String c) { 171 String old; 172 synchronized (this) { 173 if (c == null) c = ""; 174 c = c.trim (); 175 if ( (c == condition) || 176 ((c != null) && (condition != null) && condition.equals (c)) 177 ) return; 178 old = condition; 179 condition = c; 180 } 181 firePropertyChange (PROP_CONDITION, old, c); 182 } 183 184 189 public String getStratum () { 190 return stratum; 191 } 192 193 198 public void setStratum (String s) { 199 String old; 200 synchronized (this) { 201 if (s == null) s = ""; 202 s = s.trim (); 203 if ( (s == stratum) || 204 ((s != null) && (stratum != null) && stratum.equals (s)) 205 ) return; 206 old = stratum; 207 stratum = s; 208 } 209 firePropertyChange (PROP_CONDITION, old, s); 210 } 211 212 217 public String getSourceName () { 218 return sourceName; 219 } 220 221 226 public void setSourceName (String sn) { 227 String old; 228 synchronized (this) { 229 if (sn != null) sn = sn.trim (); 230 if ( (sn == sourceName) || 231 ((sn != null) && (sourceName != null) && sourceName.equals (sn)) 232 ) return; 233 old = sourceName; 234 sourceName = sn; 235 } 236 firePropertyChange (PROP_SOURCE_NAME, old, sn); 237 } 238 239 246 public String getSourcePath() { 247 return sourcePath; 248 } 249 250 257 public void setSourcePath (String sp) { 258 String old; 259 synchronized (this) { 260 if (sp != null) sp = sp.trim(); 261 if (sp == sourcePath || (sp != null && sp.equals(sourcePath))) { 262 return ; 263 } 264 old = sourcePath; 265 sourcePath = sp; 266 } 267 firePropertyChange (PROP_SOURCE_PATH, old, sp); 268 } 269 270 276 public void setPreferredClassName(String className) { 277 String old; 278 synchronized (this) { 279 if (this.className == className || (className != null && className.equals(this.className))) { 280 return ; 281 } 282 old = className; 283 this.className = className; 284 } 285 firePropertyChange (PROP_PREFERRED_CLASS_NAME, old, className); 286 } 287 288 295 public String getPreferredClassName() { 296 return className; 297 } 298 299 304 public String toString () { 305 String fileName = null; 306 try { 307 FileObject fo = URLMapper.findFileObject(new URL (url)); 308 if (fo != null) { 309 fileName = fo.getNameExt(); 310 } 311 } catch (MalformedURLException ex) { 312 ErrorManager.getDefault().notify(ex); 313 } 314 if (fileName == null) fileName = url; 315 return "LineBreakpoint " + fileName + " : " + lineNumber; 316 } 317 318 private static class LineBreakpointImpl extends LineBreakpoint 319 implements Comparable , FileChangeListener, ChangeListener { 320 321 private FileObject fo; 323 324 public LineBreakpointImpl(String url) { 325 super(url); 326 try { 327 fo = URLMapper.findFileObject(new URL (url)); 328 if (fo != null) { 329 fo.addFileChangeListener(WeakListeners.create(FileChangeListener.class, this, fo)); 330 } 331 } catch (MalformedURLException ex) { 332 ErrorManager.getDefault().notify(ex); 333 } 334 } 335 336 public int compareTo(Object o) { 337 if (o instanceof LineBreakpointImpl) { 338 LineBreakpoint lbthis = this; 339 LineBreakpoint lb = (LineBreakpoint) o; 340 int uc = lbthis.url.compareTo(lb.url); 341 if (uc != 0) { 342 return uc; 343 } else { 344 return lbthis.lineNumber - lb.lineNumber; 345 } 346 } else { 347 return -1; 348 } 349 } 350 351 public void fileFolderCreated(FileEvent fe) { 352 } 353 354 public void fileDataCreated(FileEvent fe) { 355 } 356 357 public void fileChanged(FileEvent fe) { 358 } 359 360 public void fileDeleted(FileEvent fe) { 361 DebuggerManager.getDebuggerManager().removeBreakpoint(this); 362 fo = null; 363 } 364 365 public void fileRenamed(FileRenameEvent fe) { 366 try { 367 this.setURL(((FileObject) fe.getSource()).getURL().toString()); 368 } catch (FileStateInvalidException ex) { 369 ErrorManager.getDefault().notify(ex); 370 } 371 } 372 373 public void fileAttributeChanged(FileAttributeEvent fe) { 374 } 375 376 public void stateChanged(ChangeEvent chev) { 377 Object source = chev.getSource(); 378 if (source instanceof Breakpoint.VALIDITY) { 379 setValidity((Breakpoint.VALIDITY) source, chev.toString()); 380 } else { 381 throw new UnsupportedOperationException (chev.toString()); 382 } 383 } 384 385 } 386 } | Popular Tags |