Methods Summary |
---|
private org.apache.bsf.BSFManager | createManager()
if (manager != null) {
return manager;
}
BSFManager m = new BSFManager();
m.setClassLoader(getScriptClassLoader());
if (getKeepEngine()) {
BSFEngine e = manager.loadScriptingEngine(getLanguage());
this.manager = m;
this.engine = e;
}
return m;
|
private void | declareBeans(org.apache.bsf.BSFManager m)
for (Iterator i = getBeans().keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
Object value = getBeans().get(key);
if (value != null) {
m.declareBean(key, value, value.getClass());
} else {
// BSF uses a hashtable to store values
// so cannot declareBean with a null value
// So need to remove any bean of this name as
// that bean should not be visible
m.undeclareBean(key);
}
}
|
public java.lang.Object | evaluateScript(java.lang.String execName)Do the work.
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
BSFManager m = createManager();
declareBeans(m);
// execute the script
if (engine == null) {
return m.eval(getLanguage(), execName, 0, 0, getScript());
} else {
return engine.eval(execName, 0, 0, getScript());
}
} catch (BSFException be) {
throwBuildException(be);
// NotReached
return null;
} finally {
restoreContextLoader(origLoader);
}
|
public void | executeScript(java.lang.String execName)Do the work.
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
BSFManager m = createManager();
declareBeans(m);
// execute the script
if (engine == null) {
m.exec(getLanguage(), execName, 0, 0, getScript());
} else {
engine.exec(execName, 0, 0, getScript());
}
} catch (BSFException be) {
throwBuildException(be);
} finally {
restoreContextLoader(origLoader);
}
|
public java.lang.String | getManagerName()Get the name of the manager prefix.
return "bsf";
|
public boolean | supportsLanguage()Check if bsf supports the language.
Hashtable table = (Hashtable) ReflectUtil.getField(
new BSFManager(), "registeredEngines");
String engineClassName = (String) table.get(getLanguage());
if (engineClassName == null) {
getProject().log(
"This is no BSF engine class for language '"
+ getLanguage() + "'",
Project.MSG_VERBOSE);
return false;
}
try {
getScriptClassLoader().loadClass(engineClassName);
return true;
} catch (Throwable ex) {
getProject().log(
"unable to create BSF engine class for language '"
+ getLanguage() + "'",
ex,
Project.MSG_VERBOSE);
return false;
}
|
private void | throwBuildException(org.apache.bsf.BSFException be)Throw a buildException in place of a BSFException.
Throwable t = be;
Throwable te = be.getTargetException();
if (te != null) {
if (te instanceof BuildException) {
throw (BuildException) te;
} else {
t = te;
}
}
throw new BuildException(t);
|