@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
resultLog.debug("Checking expression [{}], language extension=[{}]", expression, languageExtension);
try {
final ScriptEngine engine = scriptEngineManager.getEngineByExtension(languageExtension);
if (engine == null) {
resultLog.healthCheckError("No ScriptEngine available for extension {}", languageExtension);
} else {
// Set Bindings, with our ResultLog as a binding first, so that other bindings can use it
final Bindings b = engine.createBindings();
b.put(FormattingResultLog.class.getName(), resultLog);
synchronized (bindingsValuesProviders) {
for(BindingsValuesProvider bvp : bindingsValuesProviders) {
log.debug("Adding Bindings provided by {}", bvp);
bvp.addBindings(b);
}
}
log.debug("All Bindings added: {}", b.keySet());
final Object value = engine.eval(expression, b);
if(value!=null && "true".equals(value.toString().toLowerCase())) {
resultLog.debug("Expression [{}] evaluates to true as expected", expression);
} else {
resultLog.warn("Expression [{}] does not evaluate to true as expected, value=[{}]", expression, value);
}