1 55 56 package org.apache.bsf.util; 57 58 import java.io.StringReader ; 59 import java.io.InputStream ; 60 import java.io.IOException ; 61 import java.lang.reflect.InvocationTargetException ; 62 import java.util.Vector ; 63 import java.util.Enumeration ; 64 65 import org.apache.bsf.*; 66 import org.apache.bsf.util.BSFEngineImpl; 67 import org.apache.bsf.util.BSFFunctions; 68 import org.apache.bsf.debug.util.DebugLog; 69 70 import java.util.Hashtable ; 71 import org.apache.bsf.debug.jsdi.*; 72 73 import java.io.Reader ; 74 75 87 88 public class DocumentCell { 89 90 BSFDebugManagerImpl m_mger; 91 92 String m_docName; 93 Vector m_fnOrScripts; 94 Vector m_breakpoints; 95 Vector m_engines; 96 97 Hashtable m_functionMap; 98 private boolean m_entryexit; 99 100 public DocumentCell(BSFDebugManagerImpl mger, String name) { 102 m_mger = mger; 103 m_docName = name; 104 m_breakpoints = new Vector (); 105 m_functionMap = new Hashtable (); 106 m_fnOrScripts = new Vector (); 107 m_engines = new Vector (); 108 m_entryexit = false; 109 } 110 public String getName() { 112 return m_docName; 113 } 114 public void loadNotify(BSFEngine eng) { 123 m_engines.addElement(eng); 124 propagateBreakpoints(eng); 125 propagateEntryExit(eng); 126 } 127 public void terminateEngineNotify(BSFEngine eng) { 133 m_engines.removeElement(eng); 134 } 135 private void propagateBreakpoints(BSFEngine eng) { 140 Enumeration e; 141 BreakPoint bp; 142 int id; 143 int lineno, offset; 144 145 e = m_breakpoints.elements(); 146 while (e.hasMoreElements()) { 147 bp = (BreakPoint) e.nextElement(); 148 id = bp.getId(); 149 try { 150 if (bp.isLineDefined()) { 151 lineno = bp.getLineNo(); 152 eng.placeBreakpointAtLine(id, m_docName, lineno); 153 } else { 154 offset = bp.getOffset(); 155 eng.placeBreakpointAtOffset(id, m_docName, offset); 156 } 157 } catch (BSFException ex) { 158 } 159 } 160 } 161 private void propagateBreakpoint(BreakPoint bp) { 166 Enumeration e; 167 BSFEngine eng; 168 int id; 169 int lineno, offset; 170 171 e = m_engines.elements(); 172 while (e.hasMoreElements()) { 173 eng = (BSFEngine) e.nextElement(); 174 id = bp.getId(); 175 try { 176 if (bp.isLineDefined()) { 177 lineno = bp.getLineNo(); 178 eng.placeBreakpointAtLine(id, m_docName, lineno); 179 } else { 180 offset = bp.getOffset(); 181 eng.placeBreakpointAtOffset(id, m_docName, offset); 182 } 183 } catch (BSFException ex) { 184 } 185 } 186 } 187 private void propagateBreakPointRemove(BreakPoint bp) { 192 Enumeration e; 193 BSFEngine eng; 194 int id; 195 int lineno, offset; 196 197 e = m_engines.elements(); 198 while (e.hasMoreElements()) { 199 eng = (BSFEngine) e.nextElement(); 200 id = bp.getId(); 201 try { 202 eng.removeBreakpoint(m_docName,id); 203 } catch (BSFException ex) { 204 } 205 } 206 } 207 public void addBreakpointAtLine(int brkptId, int lineno) { 209 BreakPoint bp = new BreakPoint(this, brkptId); 210 bp.setLineNo(lineno); 211 m_breakpoints.addElement(bp); 212 propagateBreakpoint(bp); 213 } 214 public void addBreakpointAtOffset(int brkptId, int offset) { 216 BreakPoint bp = new BreakPoint(this, brkptId); 217 bp.setOffset(offset); 218 m_breakpoints.addElement(bp); 219 propagateBreakpoint(bp); 220 } 221 public void removeBreakpoint(int brkptId) { 223 Enumeration e; 224 BreakPoint bp; 225 226 e = m_breakpoints.elements(); 227 while (e.hasMoreElements()) { 228 bp = (BreakPoint) e.nextElement(); 229 if (brkptId == bp.getId()) { 230 m_breakpoints.removeElement(bp); 231 propagateBreakPointRemove(bp); 232 break; 233 } 234 } 235 } 236 237 public void setEntryExit(boolean on_value) { 238 Enumeration e; 239 240 m_entryexit = on_value; 241 242 e = m_engines.elements(); 243 while (e.hasMoreElements()) { 244 propagateEntryExit((BSFEngine) e.nextElement()); 245 } 246 } 247 248 private void propagateEntryExit(BSFEngine eng) { 249 try { 250 eng.setEntryExit(m_docName, m_entryexit); 251 } 252 catch (BSFException ex) { 253 } 254 } 255 256 public boolean getEntryExit() { 257 return m_entryexit; 258 } 259 260 public void removeAllBreakpoints() { 262 263 Enumeration e; 264 BreakPoint bp; 265 266 DebugLog.stdoutPrintln("Drop breakpoints for "+m_docName, 267 DebugLog.BSF_LOG_L3); 268 e = m_breakpoints.elements(); 269 while (e.hasMoreElements()) { 270 bp = (BreakPoint) e.nextElement(); 271 DebugLog.stdoutPrintln(" Breakpoints "+bp, 272 DebugLog.BSF_LOG_L3); 273 propagateBreakPointRemove(bp); 274 } 275 m_breakpoints = new Vector (); 276 } 277 278 public BreakPoint findBreakpointAtLine(int lineno) { 280 Enumeration e; 281 BreakPoint bp; 282 283 e = m_breakpoints.elements(); 284 while (e.hasMoreElements()) { 285 bp = (BreakPoint) e.nextElement(); 286 if (lineno == bp.getLineNo()) 287 return bp; 288 } 289 return null; 290 } 291 public BreakPoint findBreakpointAtOffset(int offset) { 293 Enumeration e; 294 BreakPoint bp; 295 296 e = m_breakpoints.elements(); 297 while (e.hasMoreElements()) { 298 bp = (BreakPoint) e.nextElement(); 299 if (offset == bp.getOffset()) 300 return bp; 301 } 302 return null; 303 } 304 } 305 | Popular Tags |