1 19 20 package org.netbeans.modules.ant.debugger.breakpoints; 21 22 import java.lang.IllegalArgumentException ; 23 import java.lang.IndexOutOfBoundsException ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import org.netbeans.api.debugger.Breakpoint; 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.netbeans.api.debugger.Properties; 29 import org.openide.cookies.LineCookie; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileStateInvalidException; 32 import org.openide.filesystems.URLMapper; 33 import org.openide.loaders.DataObject; 34 import org.openide.loaders.DataObjectNotFoundException; 35 import org.openide.text.Line; 36 37 38 42 public class BreakpointsReader implements Properties.Reader { 43 44 45 public String [] getSupportedClassNames () { 46 return new String [] { 47 AntBreakpoint.class.getName (), 48 }; 49 } 50 51 public Object read (String typeID, Properties properties) { 52 if (!(typeID.equals (AntBreakpoint.class.getName ()))) 53 return null; 54 55 Line line = getLine ( 56 properties.getString ("url", null), 57 properties.getInt ("lineNumber", 1)); 58 if (line == null) return null; 59 return new AntBreakpoint (line); 60 } 61 62 public void write (Object object, Properties properties) { 63 AntBreakpoint b = (AntBreakpoint) object; 64 FileObject fo = (FileObject) b.getLine ().getLookup (). 65 lookup (FileObject.class); 66 try { 67 properties.setString ("url", fo.getURL ().toString ()); 68 properties.setInt ( 69 "lineNumber", 70 b.getLine ().getLineNumber () 71 ); 72 } catch (FileStateInvalidException ex) { 73 ex.printStackTrace (); 74 } 75 } 76 77 78 private Line getLine (String url, int lineNumber) { 79 FileObject file; 80 try { 81 file = URLMapper.findFileObject (new URL (url)); 82 } catch (MalformedURLException e) { 83 return null; 84 } 85 if (file == null) return null; 86 DataObject dataObject = null; 87 try { 88 dataObject = DataObject.find (file); 89 } catch (DataObjectNotFoundException ex) { 90 return null; 91 } 92 if (dataObject == null) return null; 93 LineCookie lineCookie = (LineCookie) dataObject.getCookie 94 (LineCookie.class); 95 if (lineCookie == null) return null; 96 Line.Set ls = lineCookie.getLineSet (); 97 if (ls == null) return null; 98 try { 99 return ls.getCurrent (lineNumber); 100 } catch (IndexOutOfBoundsException e) { 101 } catch (IllegalArgumentException e) { 102 } 103 return null; 104 } 105 } 106 | Popular Tags |