1 55 56 package org.apache.bsf.util; 57 58 import java.rmi.RemoteException ; 59 import java.util.*; 60 import java.io.*; 61 import java.beans.*; 62 import org.apache.bsf.*; 63 64 73 74 public abstract class BSFEngineImpl implements BSFEngine { 75 76 protected BSFManager mgr; protected BSFDebugManagerImpl dbgmgr; protected String lang; protected Vector declaredBeans; protected String classPath; 81 protected String tempDir; 82 protected ClassLoader classLoader; 83 84 90 public Object getSpecificDebuggingInterface() { 91 return null; 92 } 93 94 98 public void disconnectedDebuggerNotify() { 99 } 100 101 public void placeBreakpointAtLine(int brkptid, String docname, 102 int lineno) throws BSFException { 103 throw new BSFException (BSFException.REASON_UNSUPPORTED_FEATURE, 104 "BSF:" + lang + 105 "engine does not yet support debugging."); 106 } 107 108 public void placeBreakpointAtOffset(int brkptid, String docname, 109 int offset) throws BSFException { 110 throw new BSFException (BSFException.REASON_UNSUPPORTED_FEATURE, 111 "BSF:" + lang + 112 "engine does not yet support debugging."); 113 } 114 115 public void removeBreakpoint(String docname, int brkptid) 116 throws BSFException { 117 throw new BSFException (BSFException.REASON_UNSUPPORTED_FEATURE, 118 "BSF:" + lang + 119 "engine does not yet support debugging."); 120 } 121 122 public void setEntryExit(String docname, boolean on) 123 throws BSFException { 124 throw new BSFException (BSFException.REASON_UNSUPPORTED_FEATURE, 125 "BSF:" + lang + 126 "engine does not yet support debugging."); 127 } 128 129 133 public Object apply(String source, int lineNo, int columnNo, 134 Object funcBody, Vector paramNames, Vector arguments) 135 throws BSFException { 136 return eval(source, lineNo, columnNo, funcBody); 137 } 138 139 142 public void compileApply(String source, int lineNo, int columnNo, 143 Object funcBody, Vector paramNames, 144 Vector arguments, CodeBuffer cb) 145 throws BSFException { 146 compileExpr(source, lineNo, columnNo, funcBody, cb); 147 } 148 149 153 public void compileExpr(String source, int lineNo, int columnNo, 154 Object expr, CodeBuffer cb) throws BSFException { 155 ObjInfo bsfInfo = cb.getSymbol("bsf"); 156 157 if (bsfInfo == null) { 158 bsfInfo = new ObjInfo(BSFManager.class, "bsf"); 159 cb.addFieldDeclaration("org.apache.bsf.BSFManager bsf = " + 160 "new org.apache.bsf.BSFManager();"); 161 cb.putSymbol("bsf", bsfInfo); 162 } 163 164 String evalString = bsfInfo.objName + ".eval(\"" + lang + "\", "; 165 evalString += "request.getRequestURI(), " + lineNo + ", " + columnNo; 166 evalString += "," + StringUtils.lineSeparator; 167 evalString += StringUtils.getSafeString(expr.toString()) + ")"; 168 169 ObjInfo oldRet = cb.getFinalServiceMethodStatement(); 170 171 if (oldRet != null && oldRet.isExecutable()) { 172 cb.addServiceMethodStatement(oldRet.objName + ";"); 173 } 174 175 cb.setFinalServiceMethodStatement(new ObjInfo(Object .class, 176 evalString)); 177 178 cb.addServiceMethodException("org.apache.bsf.BSFException"); 179 } 180 181 185 public void compileScript(String source, int lineNo, int columnNo, 186 Object script, CodeBuffer cb) 187 throws BSFException { 188 ObjInfo bsfInfo = cb.getSymbol("bsf"); 189 190 if (bsfInfo == null) { 191 bsfInfo = new ObjInfo(BSFManager.class, "bsf"); 192 cb.addFieldDeclaration("org.apache.bsf.BSFManager bsf = " + 193 "new org.apache.bsf.BSFManager();"); 194 cb.putSymbol("bsf", bsfInfo); 195 } 196 197 String execString = bsfInfo.objName + ".exec(\"" + lang + "\", "; 198 execString += "request.getRequestURI(), " + lineNo + ", " + columnNo; 199 execString += "," + StringUtils.lineSeparator; 200 execString += StringUtils.getSafeString(script.toString()) + ")"; 201 202 ObjInfo oldRet = cb.getFinalServiceMethodStatement(); 203 204 if (oldRet != null && oldRet.isExecutable()) { 205 cb.addServiceMethodStatement(oldRet.objName + ";"); 206 } 207 208 cb.setFinalServiceMethodStatement(new ObjInfo(void.class, execString)); 209 210 cb.addServiceMethodException("org.apache.bsf.BSFException"); 211 } 212 213 public void declareBean(BSFDeclaredBean bean) throws BSFException { 214 throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, 215 "language " + lang + 216 " does not support declareBean(...)."); 217 } 218 219 222 public void exec(String source, int lineNo, int columnNo, Object script) 223 throws BSFException { 224 eval(source, lineNo, columnNo, script); 225 } 226 227 233 public BSFEngineImpl() { 234 this.dbgmgr = (BSFDebugManagerImpl) BSFManager.getDebugManager(); 235 } 236 237 242 public void initialize(BSFManager mgr, String lang, Vector declaredBeans) 243 throws BSFException { 244 245 this.mgr = mgr; 246 this.lang = lang; 247 this.declaredBeans = declaredBeans; 248 249 this.classPath = mgr.getClassPath(); 252 this.tempDir = mgr.getTempDir(); 253 this.classLoader = mgr.getClassLoader(); 254 255 if (dbgmgr != null) { 266 dbgmgr.registerEngine(mgr, this, lang); 267 } 268 } 269 270 276 public void propertyChange(PropertyChangeEvent e) { 277 String name = e.getPropertyName(); 278 Object value = e.getNewValue(); 279 280 if (name.equals("classPath")) { 281 classPath = (String ) value; 282 } 283 else if (name.equals("tempDir")) { 284 tempDir = (String ) value; 285 } 286 else if (name.equals("classLoader")) { 287 classLoader = (ClassLoader ) value; 288 } 289 } 290 291 public void terminate() { 292 mgr = null; 293 declaredBeans = null; 294 classLoader = null; 295 296 if (dbgmgr != null) { 300 dbgmgr.terminateEngineNotify(mgr, this, lang); 301 } 302 } 303 304 public void undeclareBean(BSFDeclaredBean bean) throws BSFException { 305 throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, 306 "language " + lang + 307 " does not support undeclareBean(...)."); 308 } 309 } 310 | Popular Tags |