1 19 package org.netbeans.modules.web.debug; 20 21 import java.beans.*; 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 25 import org.netbeans.api.debugger.*; 26 import org.netbeans.api.debugger.jpda.*; 27 28 import org.netbeans.modules.web.debug.breakpoints.*; 29 30 38 public class JspBreakpointAnnotationListener extends DebuggerManagerAdapter { 39 40 private HashMap breakpointToAnnotation = new HashMap (); 41 private boolean listen = true; 42 43 public String [] getProperties () { 44 return new String [] {DebuggerManager.PROP_BREAKPOINTS}; 45 } 46 47 50 public void propertyChange (PropertyChangeEvent e) { 51 String propertyName = e.getPropertyName (); 52 if (propertyName == null) return; 53 if (!listen) return; 54 if ( (!propertyName.equals (JspLineBreakpoint.PROP_CONDITION)) && 55 (!propertyName.equals (JspLineBreakpoint.PROP_URL)) && 56 (!propertyName.equals (JspLineBreakpoint.PROP_LINE_NUMBER)) && 57 (!propertyName.equals (JspLineBreakpoint.PROP_ENABLED)) 58 ) return; 59 JspLineBreakpoint b = (JspLineBreakpoint) e.getSource (); 60 annotate (b); 61 } 62 63 68 public void breakpointAdded (Breakpoint b) { 69 if (b instanceof JspLineBreakpoint) { 70 ((JspLineBreakpoint) b).addPropertyChangeListener (this); 71 annotate ((JspLineBreakpoint) b); 72 } 73 } 74 75 80 public void breakpointRemoved (Breakpoint b) { 81 if (b instanceof JspLineBreakpoint) { 82 ((JspLineBreakpoint) b).removePropertyChangeListener (this); 83 removeAnnotation ((JspLineBreakpoint) b); 84 } 85 } 86 87 public JspLineBreakpoint findBreakpoint (String url, int lineNumber) { 88 Iterator i = breakpointToAnnotation.keySet ().iterator (); 89 while (i.hasNext ()) { 90 JspLineBreakpoint lb = (JspLineBreakpoint) i.next (); 91 if (!lb.getURL ().equals (url)) continue; 92 Object annotation = breakpointToAnnotation.get (lb); 93 int ln = Context.getLineNumber (annotation, null); 94 if (ln == lineNumber) return lb; 95 } 96 return null; 97 } 98 99 101 private void annotate (JspLineBreakpoint b) { 102 Object annotation = breakpointToAnnotation.get (b); 104 if (annotation != null) 105 Context.removeAnnotation (annotation); 106 if (b.isHidden ()) return; 107 108 annotation = Context.annotate (b); 110 if (annotation == null) 111 return; 112 113 breakpointToAnnotation.put (b, annotation); 114 115 DebuggerEngine de = DebuggerManager.getDebuggerManager (). 116 getCurrentEngine (); 117 Object timeStamp = null; 118 if (de != null) 119 timeStamp = de.lookupFirst (null, JPDADebugger.class); 120 update (b, timeStamp); 121 } 122 123 public void updateJspLineBreakpoints () { 124 Iterator it = breakpointToAnnotation.keySet ().iterator (); 125 while (it.hasNext ()) { 126 JspLineBreakpoint lb = (JspLineBreakpoint) it.next (); 127 update (lb, null); 128 } 129 } 130 131 private void update (JspLineBreakpoint b, Object timeStamp) { 132 Object annotation = breakpointToAnnotation.get (b); 133 if (annotation == null) 134 return; 135 int ln = Context.getLineNumber (annotation, timeStamp); 136 listen = false; 137 b.setLineNumber (ln); 138 listen = true; 139 } 140 141 private void removeAnnotation(JspLineBreakpoint b) { 142 Object annotation = breakpointToAnnotation.remove (b); 143 if (annotation != null) 144 Context.removeAnnotation (annotation); 145 } 146 } 147 | Popular Tags |