Search in sources :

Example 1 with GroovyScriptFactory

use of org.springframework.scripting.groovy.GroovyScriptFactory in project spring-integration by spring-projects.

the class GroovyCommandMessageProcessor method executeScript.

@Override
protected Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) throws Exception {
    Assert.notNull(scriptSource, "scriptSource must not be null");
    VariableBindingGroovyObjectCustomizerDecorator customizerDecorator = this.binding != null ? new BindingOverwriteGroovyObjectCustomizerDecorator(this.binding) : new VariableBindingGroovyObjectCustomizerDecorator();
    if (this.customizer != null) {
        customizerDecorator.setCustomizer(this.customizer);
    }
    if (!CollectionUtils.isEmpty(variables)) {
        customizerDecorator.setVariables(variables);
    }
    GroovyScriptFactory factory = new GroovyScriptFactory(this.getClass().getSimpleName(), customizerDecorator);
    if (this.beanClassLoader != null) {
        factory.setBeanClassLoader(this.beanClassLoader);
    }
    if (this.beanFactory != null) {
        factory.setBeanFactory(this.beanFactory);
    }
    Object result = factory.getScriptedObject(scriptSource);
    return (result instanceof GString) ? result.toString() : result;
}
Also used : GroovyScriptFactory(org.springframework.scripting.groovy.GroovyScriptFactory) GString(groovy.lang.GString)

Aggregations

GString (groovy.lang.GString)1 GroovyScriptFactory (org.springframework.scripting.groovy.GroovyScriptFactory)1