1 19 package org.netbeans.modules.web.debug; 20 21 import java.io.File ; 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.util.List ; 25 import java.beans.PropertyChangeListener ; 26 import org.netbeans.api.debugger.DebuggerManager; 27 28 import org.netbeans.api.debugger.jpda.*; 29 import org.netbeans.spi.debugger.jpda.*; 30 31 import org.netbeans.modules.web.debug.breakpoints.JspLineBreakpoint; 32 33 37 public class Context { 38 39 private static EditorContext editorContext; 40 41 private static EditorContext getContext () { 42 if (editorContext == null) { 43 List l = DebuggerManager.getDebuggerManager().lookup(null, EditorContext.class); 44 if (!l.isEmpty()) { 45 editorContext = (EditorContext) l.get (0); 46 } 47 } 48 return editorContext; 49 } 50 51 53 59 public static boolean showSource ( 60 String url, 61 int lineNumber, 62 Object timeStamp 63 ) { 64 return getContext ().showSource (url, lineNumber, timeStamp); 65 } 66 67 77 public static Object annotate ( 78 String url, 79 int lineNumber, 80 String annotationType, 81 Object timeStamp 82 ) { 83 return getContext ().annotate (url, lineNumber, annotationType, timeStamp); 84 } 85 86 91 public static void removeAnnotation ( 92 Object annotation 93 ) { 94 getContext ().removeAnnotation (annotation); 95 } 96 97 public static int getLineNumber (Object annotation, Object timeStamp) { 98 return getContext ().getLineNumber (annotation, timeStamp); 99 } 100 101 106 public static int getCurrentLineNumber () { 107 return getContext ().getCurrentLineNumber (); 108 } 109 110 115 public static String getCurrentURL () { 116 return getContext ().getCurrentURL (); 117 } 118 119 public static void addPropertyChangeListener (PropertyChangeListener l) { 120 getContext ().addPropertyChangeListener (l); 121 } 122 123 public static void removePropertyChangeListener (PropertyChangeListener l) { 124 getContext ().removePropertyChangeListener (l); 125 } 126 127 132 public static void createTimeStamp (Object timeStamp) { 133 getContext ().createTimeStamp (timeStamp); 134 } 135 136 141 public static void disposeTimeStamp (Object timeStamp) { 142 getContext ().disposeTimeStamp (timeStamp); 143 } 144 145 147 public static String getFileName (JspLineBreakpoint b) { 148 try { 149 return new File (new URL (b.getURL()).getFile ()).getName (); 150 } catch (MalformedURLException e) { 151 return null; 152 } 153 } 154 155 public static boolean showSource(JspLineBreakpoint b) { 156 if (b.getLineNumber () < 1) 157 return Context.showSource ( 158 b.getURL (), 159 1, 160 null 161 ); 162 return Context.showSource ( 163 b.getURL (), 164 b.getLineNumber (), 165 null 166 ); 167 } 168 169 177 public static Object annotate(JspLineBreakpoint b) { 178 String url = b.getURL (); 179 int lineNumber = b.getLineNumber (); 180 if (lineNumber < 1) return null; 181 String condition = b.getCondition (); 182 boolean isConditional = (condition != null) && 183 !condition.trim ().equals (""); String annotationType = b.isEnabled () ? 185 (isConditional ? EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE : 186 EditorContext.BREAKPOINT_ANNOTATION_TYPE) : 187 (isConditional ? EditorContext.DISABLED_CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE : 188 EditorContext.DISABLED_BREAKPOINT_ANNOTATION_TYPE); 189 190 return annotate ( 191 url, 192 lineNumber, 193 annotationType, 194 null 195 ); 196 } 197 198 } 199 200 | Popular Tags |