use of org.ow2.proactive.scripting.InvalidScriptException in project scheduling by ow2-proactive.
the class ProbablisticSelectionManager method replaceBindings.
private SelectionScript replaceBindings(SelectionScript script, Map<String, Serializable> bindings) {
String scriptContent = script.fetchScript();
if (scriptContent != null && bindings != null) {
for (Map.Entry<String, Serializable> entry : bindings.entrySet()) {
String reservedKeyword = entry.getKey();
Serializable binding = entry.getValue();
if (binding instanceof Map) {
scriptContent = replaceBindingKeysByTheirValue(scriptContent, (Map<String, Serializable>) binding);
} else {
if (binding != null) {
scriptContent = scriptContent.replace(reservedKeyword, binding.toString());
}
}
}
}
try {
if (scriptContent != null) {
return new SelectionScript(scriptContent, script.getEngineName(), script.getParameters(), script.isDynamic());
} else {
return script;
}
} catch (InvalidScriptException e) {
logger.warn("Error when replacing bindings of script (revert to use original script):" + System.lineSeparator() + script.toString(), e);
return script;
}
}
Aggregations