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