1 55 56 package org.apache.bsf.util; 57 58 import java.lang.reflect.*; 59 import java.util.*; 60 import java.io.*; 61 import java.beans.*; 62 63 import org.apache.bsf.*; 64 import org.apache.bsf.debug.*; 65 import org.apache.bsf.debug.serverImpl.*; 66 import org.apache.bsf.debug.util.DebugLog; 67 68 import java.rmi.RemoteException ; 69 70 import org.apache.bsf.debug.jsdi.*; 71 import org.apache.bsf.debug.util.*; 72 73 public class BSFDebugManagerImpl 74 extends Skeleton 75 implements BSFDebugManager, RemoteServiceListener { 76 77 static BSFDebugManagerImpl self; 78 79 private long m_fnOrScriptIdGenerator = 0x1; 80 private long m_documentIdGenerator = 0x100000000l; 81 82 private Hashtable m_langcells; 83 private Hashtable m_documents; 84 85 private ObjectServer m_server; 86 87 public BSFDebugManagerImpl() throws RemoteException { 88 89 super(DebugConstants.BSF_DEBUG_MANAGER_TID, 90 DebugConstants.BSF_DEBUG_MANAGER_UID); 91 self = this; 92 m_langcells = new Hashtable(); 93 m_documents = new Hashtable(); 94 95 Integer port = Integer.getInteger("org.apache.bsf.serverPort", -1); 96 m_server = new ObjectServer(this, port.intValue()); 97 } 98 99 113 public void revokedNotify(RemoteService service) { 114 Enumeration e; 115 LangCell cell; 116 117 e = m_langcells.elements(); 118 while (e.hasMoreElements()) { 119 cell = (LangCell)e.nextElement(); 120 DebugLog.stderrPrintln("Disconnecting the debugger", 121 DebugLog.BSF_LOG_L1); 122 cell.disconnectDebugger(); 123 DebugLog.stderrPrintln("Debugger disconnected.", 124 DebugLog.BSF_LOG_L1); 125 } 126 DebugLog.stderrPrintln("Dropping all breakpoints...", 127 DebugLog.BSF_LOG_L1); 128 removeAllBreakpoints(); 129 DebugLog.stderrPrintln("All breakpoints dropped.", 130 DebugLog.BSF_LOG_L1); 131 } 132 public void finalize() { 134 terminate(); 135 } 136 long generateDocumentId() { 137 long docid = m_documentIdGenerator; 138 m_documentIdGenerator += 0x100000000l; 139 return docid; 140 } 141 143 155 public String getLangFromFilename(String fileName) throws RemoteException { 156 try { 157 return BSFManager.getLangFromFilename(fileName); 158 } catch (BSFException ex) { 159 return null; 160 } 161 } 162 165 172 public boolean isLanguageRegistered(String lang) { 173 return BSFManager.isLanguageRegistered(lang); 174 } 175 180 public boolean supportBreakpointAtOffset(String lang) 181 throws RemoteException { 182 return false; 183 } 184 185 public boolean supportBreakpointAtLine(String lang) 186 throws RemoteException { 187 return true; 188 } 189 190 public synchronized void placeBreakpointAtLine( 192 int brkptid, 193 String docname, 194 int lineno) 195 throws RemoteException { 196 197 DocumentCell cell; 198 DebugLog.stdoutPrintln("Placing breakpoint in "+docname+" at "+lineno, DebugLog.BSF_LOG_L1); 199 cell = getDocumentCell(docname); 200 cell.addBreakpointAtLine(brkptid, lineno); 201 } 202 public synchronized void placeBreakpointAtOffset( 203 int brkptid, 204 String docname, 205 int offset) 206 throws RemoteException { 207 208 DocumentCell cell; 209 cell = getDocumentCell(docname); 210 cell.addBreakpointAtOffset(brkptid, offset); 211 } 212 213 public synchronized void removeBreakpoint(String docname, int brkptid) 214 throws RemoteException { 215 216 DocumentCell cell; 217 cell = (DocumentCell) m_documents.get(docname); 218 if (cell != null) 219 cell.removeBreakpoint(brkptid); 220 } 221 222 public synchronized void setEntryExit(String docname, boolean on) 223 throws RemoteException { 224 225 DocumentCell cell; 226 cell = getDocumentCell(docname); 227 if (cell != null) 228 cell.setEntryExit(on); 229 } 230 231 public synchronized void removeAllBreakpoints() { 232 String docname; 233 int bpid; 234 DocumentCell cell; 235 Enumeration e; 236 e = m_documents.elements(); 237 while (e.hasMoreElements()) { 238 cell = (DocumentCell) e.nextElement(); 239 cell.removeAllBreakpoints(); 240 } 241 } 242 244 255 256 public synchronized void registerDebugger(String lang, BSFDebugger debugger) 257 throws RemoteException { 258 259 BSFDebugger dbg; 260 DebugLog.stdoutPrintln("Registering debugger for "+lang, 261 DebugLog.BSF_LOG_L1); 262 try { 263 LangCell cell = (LangCell)m_langcells.get(lang); 264 if (cell == null) { 265 cell = new LangCell(lang); 266 m_langcells.put(lang,cell); 267 } else { 268 cell.disconnectDebugger(); 269 } 270 cell.setDebugger(debugger); 274 debugger.addListener(this); 275 276 } catch (Exception ex) { 277 DebugLog.stdoutPrintln("Error:", DebugLog.BSF_LOG_L0); 278 DebugLog.stdoutPrintln(ex.getMessage(), DebugLog.BSF_LOG_L0); 279 ex.printStackTrace(DebugLog.getDebugStream()); 280 } 281 } 282 283 286 public synchronized DocumentCell loadDocumentNotify(BSFEngine eng, 287 String name) { 288 DocumentCell cell; 289 cell = (DocumentCell) m_documents.get(name); 290 if (cell == null) { 291 cell = new DocumentCell(this, name); 292 m_documents.put(name, cell); 293 } 294 cell.loadNotify(eng); 295 return cell; 296 } 297 301 synchronized DocumentCell getDocumentCell(String name) { 302 DocumentCell cell; 303 cell = (DocumentCell) m_documents.get(name); 304 if (cell == null) { 305 cell = new DocumentCell(this, name); 306 m_documents.put(name, cell); 307 } 308 return cell; 309 } 310 314 public synchronized void registerEngine( 315 BSFManager mger, 316 BSFEngine eng, 317 String lang) { 318 319 LangCell cell = (LangCell)m_langcells.get(lang); 320 if (cell == null) { 321 cell = new LangCell(lang); 322 m_langcells.put(lang,cell); 323 } 324 cell.addEngine(eng); 327 } 328 331 public synchronized void registerManager(BSFManager mger) { 332 } 333 336 public synchronized void terminateManagerNotify(BSFManager mger) { 337 } 338 339 public void terminate() { 340 Enumeration e; 341 LangCell cell; 342 e = m_langcells.elements(); 343 while (e.hasMoreElements()) { 344 cell = (LangCell) e.nextElement(); 345 cell.terminateNotify(); 346 } 347 m_langcells = new Hashtable(); 348 } 349 public synchronized void unregisterDebugger(String lang) 350 throws RemoteException { 351 352 LangCell cell; 353 cell = (LangCell)m_langcells.get(lang); 354 if (cell==null) 355 return; 357 cell.disconnectDebugger(); 358 } 359 362 public synchronized void terminateEngineNotify( 363 BSFManager mger, 364 BSFEngine eng, 365 String lang) { 366 367 LangCell cell; 368 cell = (LangCell)m_langcells.get(lang); 369 if (cell==null) 370 return; 372 cell.removeEngine(eng); 373 374 Enumeration e; 377 DocumentCell doccell; 378 e = m_documents.elements(); 379 while (e.hasMoreElements()) { 380 doccell = (DocumentCell) e.nextElement(); 381 doccell.terminateEngineNotify(eng); 382 } 383 } 384 } 385 | Popular Tags |