/**
* Clears the script engine of all previous state except, if it is a BeanShell interpreter,
* the engine is left
*
* @param scriptEngine ScriptEngine to clear
*/
private void clearEngine(String language, ScriptEngine scriptEngine) {
// Clear everything except the BeanShell engine ("bsh" in the binding)
// This will clear all imported class, methods, and variables
List<String> itemsToRemove = new ArrayList<String>();
for (Map.Entry<String, Object> bindingEntry : scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).entrySet()) {
if (language.equalsIgnoreCase(BEANSHELL) && bindingEntry.getKey().equalsIgnoreCase(BEANSHELL_ENGINE_NAME)) {
continue;
}
itemsToRemove.add(bindingEntry.getKey());
}
for (String value : itemsToRemove) {
scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).remove(value);
}
// Clear entire global scope
scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE).clear();
}
ScriptEnginePool.java 文件源码
java
阅读 16
收藏 0
点赞 0
评论 0
项目:jaffa-framework
作者:
评论列表
文章目录