1 19 20 package org.netbeans.modules.debugger.jpda.breakpoints; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 28 import org.netbeans.api.debugger.Breakpoint; 29 import org.netbeans.api.debugger.DebuggerEngine; 30 import org.netbeans.api.debugger.DebuggerManager; 31 import org.netbeans.api.debugger.DebuggerManagerListener; 32 import org.netbeans.api.debugger.LazyDebuggerManagerListener; 33 import org.netbeans.api.debugger.Properties; 34 import org.netbeans.api.debugger.Properties.Reader; 35 import org.netbeans.api.debugger.Session; 36 import org.netbeans.api.debugger.Watch; 37 import org.netbeans.api.debugger.jpda.JPDABreakpoint; 38 import org.netbeans.api.debugger.jpda.LineBreakpoint; 39 40 import org.openide.ErrorManager; 41 import org.openide.filesystems.FileObject; 42 import org.openide.filesystems.URLMapper; 43 44 51 public class PersistenceManager implements LazyDebuggerManagerListener { 52 53 public synchronized Breakpoint[] initBreakpoints () { 54 Properties p = Properties.getDefault ().getProperties ("debugger"). 55 getProperties (DebuggerManager.PROP_BREAKPOINTS); 56 Breakpoint[] breakpoints = (Breakpoint[]) p.getArray ( 57 "jpda", 58 new Breakpoint [0] 59 ); 60 for (int i = 0; i < breakpoints.length; i++) { 61 if (breakpoints[i] instanceof LineBreakpoint) { 62 LineBreakpoint lb = (LineBreakpoint) breakpoints[i]; 63 try { 64 FileObject fo = URLMapper.findFileObject(new URL (lb.getURL())); 65 if (fo == null) { 66 Breakpoint[] breakpoints2 = new Breakpoint[breakpoints.length - 1]; 68 if (i > 0) { 69 System.arraycopy(breakpoints, 0, breakpoints2, 0, i); 70 } 71 if (i < breakpoints2.length) { 72 System.arraycopy(breakpoints, i + 1, breakpoints2, i, breakpoints2.length - i); 73 } 74 breakpoints = breakpoints2; 75 i--; 76 continue; 77 } 78 } catch (MalformedURLException ex) { 79 ErrorManager.getDefault().notify(ex); 80 } 81 } 82 breakpoints[i].addPropertyChangeListener(this); 83 } 84 return breakpoints; 85 } 86 87 public void initWatches () { 88 } 89 90 public String [] getProperties () { 91 return new String [] { 92 DebuggerManager.PROP_BREAKPOINTS_INIT, 93 DebuggerManager.PROP_BREAKPOINTS, 94 }; 95 } 96 97 public void breakpointAdded (Breakpoint breakpoint) { 98 if (breakpoint instanceof JPDABreakpoint && 99 !((JPDABreakpoint) breakpoint).isHidden ()) { 100 101 storeBreakpoints(); 102 breakpoint.addPropertyChangeListener(this); 103 } 104 } 105 106 public void breakpointRemoved (Breakpoint breakpoint) { 107 if (breakpoint instanceof JPDABreakpoint && 108 !((JPDABreakpoint) breakpoint).isHidden ()) { 109 110 storeBreakpoints(); 111 breakpoint.removePropertyChangeListener(this); 112 } 113 } 114 public void watchAdded (Watch watch) { 115 } 116 117 public void watchRemoved (Watch watch) { 118 } 119 120 public void propertyChange (PropertyChangeEvent evt) { 121 if (evt.getSource() instanceof JPDABreakpoint) { 122 if (LineBreakpoint.PROP_LINE_NUMBER.equals(evt.getPropertyName())) { 123 BreakpointsReader r = findBreakpointsReader(); 124 if (r != null) { 125 r.storeCachedClassName((JPDABreakpoint) evt.getSource(), null); 127 } 128 } 129 storeBreakpoints(); 130 } 131 } 132 133 static BreakpointsReader findBreakpointsReader() { 134 BreakpointsReader breakpointsReader = null; 135 Iterator i = DebuggerManager.getDebuggerManager().lookup (null, Reader.class).iterator (); 136 while (i.hasNext ()) { 137 Reader r = (Reader) i.next (); 138 String [] ns = r.getSupportedClassNames (); 139 if (ns.length == 1 && JPDABreakpoint.class.getName().equals(ns[0])) { 140 breakpointsReader = (BreakpointsReader) r; 141 break; 142 } 143 } 144 return breakpointsReader; 145 } 146 147 static void storeBreakpoints() { 148 Properties.getDefault ().getProperties ("debugger"). 149 getProperties (DebuggerManager.PROP_BREAKPOINTS).setArray ( 150 "jpda", 151 getBreakpoints () 152 ); 153 } 154 155 public void sessionAdded (Session session) {} 156 public void sessionRemoved (Session session) {} 157 public void engineAdded (DebuggerEngine engine) {} 158 public void engineRemoved (DebuggerEngine engine) {} 159 160 161 private static Breakpoint[] getBreakpoints () { 162 Breakpoint[] bs = DebuggerManager.getDebuggerManager (). 163 getBreakpoints (); 164 int i, k = bs.length; 165 ArrayList <Breakpoint> bb = new ArrayList <Breakpoint>(); 166 for (i = 0; i < k; i++) 167 if ( bs[i] instanceof JPDABreakpoint && 169 !((JPDABreakpoint) bs [i]).isHidden () 170 ) 171 bb.add (bs [i]); 172 bs = new Breakpoint [bb.size ()]; 173 return bb.toArray (bs); 174 } 175 176 } 177 | Popular Tags |