| Method from org.apache.bsf.util.BSFEngineImpl Detail: |
public Object apply(String source,
int lineNo,
int columnNo,
Object funcBody,
Vector paramNames,
Vector arguments) throws BSFException {
return eval(source, lineNo, columnNo, funcBody);
}
Default impl of apply - calls eval ignoring parameters and returns
the result. |
public void compileApply(String source,
int lineNo,
int columnNo,
Object funcBody,
Vector paramNames,
Vector arguments,
CodeBuffer cb) throws BSFException {
compileExpr(source, lineNo, columnNo, funcBody, cb);
}
Default impl of compileApply - calls compileExpr ignoring parameters. |
public void compileExpr(String source,
int lineNo,
int columnNo,
Object expr,
CodeBuffer cb) throws BSFException {
ObjInfo bsfInfo = cb.getSymbol("bsf");
if (bsfInfo == null) {
bsfInfo = new ObjInfo(BSFManager.class, "bsf");
cb.addFieldDeclaration("org.apache.bsf.BSFManager bsf = " +
"new org.apache.bsf.BSFManager();");
cb.putSymbol("bsf", bsfInfo);
}
String evalString = bsfInfo.objName + ".eval(\"" + lang + "\", ";
evalString += "request.getRequestURI(), " + lineNo + ", " + columnNo;
evalString += "," + StringUtils.lineSeparator;
evalString += StringUtils.getSafeString(expr.toString()) + ")";
ObjInfo oldRet = cb.getFinalServiceMethodStatement();
if (oldRet != null && oldRet.isExecutable()) {
cb.addServiceMethodStatement(oldRet.objName + ";");
}
cb.setFinalServiceMethodStatement(new ObjInfo(Object.class,
evalString));
cb.addServiceMethodException("org.apache.bsf.BSFException");
}
Default impl of compileExpr - generates code that'll create a new
manager, evaluate the expression, and return the value. |
public void compileScript(String source,
int lineNo,
int columnNo,
Object script,
CodeBuffer cb) throws BSFException {
ObjInfo bsfInfo = cb.getSymbol("bsf");
if (bsfInfo == null) {
bsfInfo = new ObjInfo(BSFManager.class, "bsf");
cb.addFieldDeclaration("org.apache.bsf.BSFManager bsf = " +
"new org.apache.bsf.BSFManager();");
cb.putSymbol("bsf", bsfInfo);
}
String execString = bsfInfo.objName + ".exec(\"" + lang + "\", ";
execString += "request.getRequestURI(), " + lineNo + ", " + columnNo;
execString += "," + StringUtils.lineSeparator;
execString += StringUtils.getSafeString(script.toString()) + ")";
ObjInfo oldRet = cb.getFinalServiceMethodStatement();
if (oldRet != null && oldRet.isExecutable()) {
cb.addServiceMethodStatement(oldRet.objName + ";");
}
cb.setFinalServiceMethodStatement(new ObjInfo(void.class, execString));
cb.addServiceMethodException("org.apache.bsf.BSFException");
}
Default impl of compileScript - generates code that'll create a new
manager, and execute the script. |
public void declareBean(BSFDeclaredBean bean) throws BSFException {
throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
"language " + lang +
" does not support declareBean(...).");
}
|
public void exec(String source,
int lineNo,
int columnNo,
Object script) throws BSFException {
eval(source, lineNo, columnNo, script);
}
Default impl of execute - calls eval and ignores the result. |
public void iexec(String source,
int lineNo,
int columnNo,
Object script) throws BSFException {
eval(source, lineNo, columnNo, script);
}
Default impl of interactive execution - calls eval and ignores the result. |
public void initialize(BSFManager mgr,
String lang,
Vector declaredBeans) throws BSFException {
this.mgr = mgr;
this.lang = lang;
this.declaredBeans = declaredBeans;
// initialize my properties from those of the manager. It'll send
// propagate change events to me
this.classPath = mgr.getClassPath();
this.tempDir = mgr.getTempDir();
this.classLoader = mgr.getClassLoader();
}
initialize the engine; called right after construction by
the manager. Declared beans are simply kept in a vector and
that's it. Subclasses must do whatever they want with it. |
public void propertyChange(PropertyChangeEvent e) {
String name = e.getPropertyName();
Object value = e.getNewValue();
if (name.equals("classPath")) {
classPath = (String) value;
}
else if (name.equals("tempDir")) {
tempDir = (String) value;
}
else if (name.equals("classLoader")) {
classLoader = (ClassLoader) value;
}
}
Receive property change events from the manager and update my fields
as needed. |
public void terminate() {
mgr = null;
declaredBeans = null;
classLoader = null;
}
|
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
"language " + lang +
" does not support undeclareBean(...).");
}
|