Search in sources :

Example 1 with ResultProcessor

use of eu.esdihumboldt.util.groovy.sandbox.GroovyService.ResultProcessor in project hale by halestudio.

the class GroovyScript method evaluate.

/**
 * @see Script#evaluate(String, Iterable, ServiceProvider)
 */
@Override
public Object evaluate(String script, Iterable<PropertyValue> variables, ServiceProvider provider) throws ScriptException {
    Binding binding = createGroovyBinding(variables, true);
    GroovyService service = provider.getService(GroovyService.class);
    Object result;
    try {
        result = service.evaluate(service.parseScript(script, binding), new ResultProcessor<Object>() {

            @Override
            public Object process(groovy.lang.Script script, Object returnValue) throws Exception {
                return returnValue;
            }
        });
    } catch (Exception e) {
        throw new ScriptException(e);
    } catch (Throwable t) {
        throw new ScriptException(t.toString());
    }
    if (result == null) {
        // XXX throw new NoResultException(); ? as cause for SE?
        throw new ScriptException("no result");
    }
    return result;
}
Also used : Binding(groovy.lang.Binding) Script(eu.esdihumboldt.hale.common.scripting.Script) ScriptException(javax.script.ScriptException) ResultProcessor(eu.esdihumboldt.util.groovy.sandbox.GroovyService.ResultProcessor) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) ConversionException(org.springframework.core.convert.ConversionException) MissingPropertyException(groovy.lang.MissingPropertyException) ScriptException(javax.script.ScriptException)

Aggregations

Script (eu.esdihumboldt.hale.common.scripting.Script)1 GroovyService (eu.esdihumboldt.util.groovy.sandbox.GroovyService)1 ResultProcessor (eu.esdihumboldt.util.groovy.sandbox.GroovyService.ResultProcessor)1 Binding (groovy.lang.Binding)1 MissingPropertyException (groovy.lang.MissingPropertyException)1 ScriptException (javax.script.ScriptException)1 ConversionException (org.springframework.core.convert.ConversionException)1