public Object execute(final Map<Object, Object> iArgs) {
final String language = request.getLanguage();
final String script = request.getText();
if (language == null)
throw new OCommandScriptException("No language was specified");
if (!engines.containsKey(language))
throw new OCommandScriptException("Unsupported language: " + language + ". Supported languages are: " + engines);
if (script == null)
throw new OCommandScriptException("Invalid script: " + script);
final ScriptEngine scriptEngine = engines.get(language);
if (scriptEngine == null)
throw new OCommandScriptException("Cannot find script engine: " + language);
final Bindings binding = scriptEngine.createBindings();
// BIND FIXED VARIABLES
binding.put("db", database);
// BIND PARAMETERS INTO THE SCRIPT
if (iArgs != null)
for (int i = 0; i < iArgs.size(); ++i) {
binding.put("$" + i, iArgs.get(i));
}
try {
Object result = null;
result = scriptEngine.eval(script, binding);
return result;
} catch (ScriptException e) {
throw new OCommandScriptException("Error on execution of the script", request.getText(), 0, e);
}
}