Class StandardScriptEvaluator
java.lang.Object
org.springframework.scripting.support.StandardScriptEvaluator
- All Implemented Interfaces:
- Aware,- BeanClassLoaderAware,- ScriptEvaluator
public class StandardScriptEvaluator
extends Object
implements ScriptEvaluator, BeanClassLoaderAware
javax.script (JSR-223) based implementation of Spring's ScriptEvaluator
 strategy interface.- Since:
- 4.0
- Author:
- Juergen Hoeller, Costin Leau
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a newStandardScriptEvaluator.StandardScriptEvaluator(ClassLoader classLoader) Construct a newStandardScriptEvaluatorfor the given class loader.StandardScriptEvaluator(ScriptEngineManager scriptEngineManager) Construct a newStandardScriptEvaluatorfor the given JSR-223ScriptEngineManagerto obtain script engines from.
- 
Method SummaryModifier and TypeMethodDescriptionevaluate(ScriptSource script) Evaluate the given script.evaluate(ScriptSource script, Map<String, Object> argumentBindings) Evaluate the given script with the given arguments.protected ScriptEnginegetScriptEngine(ScriptSource script) Obtain the JSR-223 ScriptEngine to use for the given script.voidsetBeanClassLoader(ClassLoader classLoader) Callback that supplies the beanclass loaderto a bean instance.voidsetEngineName(String engineName) Set the name of the script engine for evaluating the scripts (for example, "Groovy"), as exposed by the JSR-223 script engine factory.voidsetGlobalBindings(Map<String, Object> globalBindings) Set the globally scoped bindings on the underlying script engine manager, shared by all scripts, as an alternative to script argument bindings.voidsetLanguage(String language) Set the name of the language meant for evaluating the scripts (for example, "Groovy").
- 
Constructor Details- 
StandardScriptEvaluatorpublic StandardScriptEvaluator()Construct a newStandardScriptEvaluator.
- 
StandardScriptEvaluatorConstruct a newStandardScriptEvaluatorfor the given class loader.- Parameters:
- classLoader- the class loader to use for script engine detection
 
- 
StandardScriptEvaluatorConstruct a newStandardScriptEvaluatorfor the given JSR-223ScriptEngineManagerto obtain script engines from.- Parameters:
- scriptEngineManager- the ScriptEngineManager (or subclass thereof) to use
- Since:
- 4.2.2
 
 
- 
- 
Method Details- 
setLanguageSet the name of the language meant for evaluating the scripts (for example, "Groovy").This is effectively an alias for "engineName", potentially (but not yet) providing common abbreviations for certain languages beyond what the JSR-223 script engine factory exposes.- See Also:
 
- 
setEngineNameSet the name of the script engine for evaluating the scripts (for example, "Groovy"), as exposed by the JSR-223 script engine factory.- Since:
- 4.2.2
- See Also:
 
- 
setGlobalBindingsSet the globally scoped bindings on the underlying script engine manager, shared by all scripts, as an alternative to script argument bindings.- Since:
- 4.2.2
- See Also:
 
- 
setBeanClassLoaderDescription copied from interface:BeanClassLoaderAwareCallback that supplies the beanclass loaderto a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean'sInitializingBean.afterPropertiesSet()method or a custom init-method.- Specified by:
- setBeanClassLoaderin interface- BeanClassLoaderAware
- Parameters:
- classLoader- the owning class loader
 
- 
evaluateDescription copied from interface:ScriptEvaluatorEvaluate the given script.- Specified by:
- evaluatein interface- ScriptEvaluator
- Parameters:
- script- the ScriptSource for the script to evaluate
- Returns:
- the return value of the script, if any
 
- 
evaluate@Nullable public Object evaluate(ScriptSource script, @Nullable Map<String, Object> argumentBindings) Description copied from interface:ScriptEvaluatorEvaluate the given script with the given arguments.- Specified by:
- evaluatein interface- ScriptEvaluator
- Parameters:
- script- the ScriptSource for the script to evaluate
- argumentBindings- the key-value pairs to expose to the script, typically as script variables (may be- nullor empty)
- Returns:
- the return value of the script, if any
 
- 
getScriptEngineObtain the JSR-223 ScriptEngine to use for the given script.- Parameters:
- script- the script to evaluate
- Returns:
- the ScriptEngine (never null)
 
 
-