Methods Summary |
---|
private org.apache.tools.ant.util.ReflectWrapper | createEngine()
if (engine != null) {
return engine;
}
ReflectWrapper manager = new ReflectWrapper(
getClass().getClassLoader(), "javax.script.ScriptEngineManager");
Object e = manager.invoke(
"getEngineByName", String.class, getLanguage());
if (e == null) {
return null;
}
ReflectWrapper ret = new ReflectWrapper(e);
if (getKeepEngine()) {
this.engine = ret;
}
return ret;
|
public java.lang.Object | evaluateScript(java.lang.String execName)Do the work to eval the script.
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
ReflectWrapper engine = createEngine();
if (engine == null) {
throw new BuildException(
"Unable to create javax script engine for "
+ getLanguage());
}
for (Iterator i = getBeans().keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
Object value = getBeans().get(key);
engine.invoke(
"put", String.class, key, Object.class, value);
}
// execute the script
return engine.invoke("eval", String.class, getScript());
} catch (Exception be) {
Throwable t = be;
Throwable te = (Throwable) ReflectUtil.invoke(be, "getCause");
if (te != null) {
if (te instanceof BuildException) {
throw (BuildException) te;
} else {
t = te;
}
}
throw new BuildException(t);
} finally {
restoreContextLoader(origLoader);
}
|
public void | executeScript(java.lang.String execName)Do the work to run the script.
evaluateScript(execName);
|
public java.lang.String | getManagerName()Get the name of the manager prefix.
return "javax";
|
public boolean | supportsLanguage(){@inheritDoc}.
if (engine != null) {
return true;
}
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
return createEngine() != null;
} catch (Exception ex) {
return false;
} finally {
restoreContextLoader(origLoader);
}
|