protected Object executeBeanShellScript(String beanShellScript, Map context) throws EvalError {
// Ensure there is something to execute.
if (beanShellScript == null || beanShellScript.trim().equals("")) return null;
// Initialize the BeanShell interpreter.
Interpreter bshInterpreter = (Interpreter) _bshIntepreterThread.get();
if (bshInterpreter == null) {
bshInterpreter = new Interpreter();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader != null) bshInterpreter.setClassLoader(loader);
_bshIntepreterThread.set(bshInterpreter);
}
// Set context.
Iterator contextIt = context.keySet().iterator();
while (contextIt.hasNext()) {
String contextVar = (String) contextIt.next();
bshInterpreter.set(contextVar, context.get(contextVar));
}
// Launch the BeanShell script.
return bshInterpreter.eval(beanShellScript);
}