Top Description Fields Constructors Methods
org.springframework.scripting.support

public Class StandardScriptEvaluator

extends Object
implements ScriptEvaluator, BeanClassLoaderAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.Aware, org.springframework.scripting.ScriptEvaluator
Imports
java.io.IOException, java.util.Map, javax.script.Bindings, .ScriptEngine, .ScriptEngineManager, .ScriptException, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.scripting.ScriptCompilationException, .ScriptEvaluator, .ScriptSource, org.springframework.util.CollectionUtils, .StringUtils

javax.script (JSR-223) based implementation of Spring's ScriptEvaluator strategy interface.
Authors
Juergen Hoeller, Costin Leau
Since
4.0
See Also
ScriptEngine#eval(String)

Field Summary

Modifier and TypeField and Description
private String
private volatile Bindings
private volatile ScriptEngineManager

Constructor Summary

AccessConstructor and Description
public
StandardScriptEvaluator()

Construct a new StandardScriptEvaluator.

public
StandardScriptEvaluator(ClassLoader
the class loader to use for script engine detection
classLoader
)

Construct a new StandardScriptEvaluator for the given class loader.

public
StandardScriptEvaluator(ScriptEngineManager
the ScriptEngineManager (or subclass thereof) to use
scriptEngineManager
)

Construct a new StandardScriptEvaluator for the given JSR-223 ScriptEngineManager to obtain script engines from.

Method Summary

Modifier and TypeMethod and Description
public Object
evaluate(ScriptSource
the ScriptSource for the script to evaluate
script
)

Implements org.springframework.scripting.ScriptEvaluator.evaluate.

Evaluate the given script.
public Object
evaluate(ScriptSource
the ScriptSource for the script to evaluate
script
,
Map<String, Object>
the key-value pairs to expose to the script, typically as script variables (may be null or empty)
argumentBindings
)

Implements org.springframework.scripting.ScriptEvaluator.evaluate.

Evaluate the given script with the given arguments.
protected ScriptEngine

Returns:

the ScriptEngine (never null)
getScriptEngine
(ScriptSource
the script to evaluate
script
)

Obtain the JSR-223 ScriptEngine to use for the given script.

public void
setBeanClassLoader(ClassLoader
the owning class loader
classLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.
public void
setEngineName(String engineName)

Set the name of the script engine for evaluating the scripts (e.g. "Groovy"), as exposed by the JSR-223 script engine factory.

public void
setGlobalBindings(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.

public void
setLanguage(String language)

Set the name of the language meant for evaluating the scripts (e.g. "Groovy").

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

engineNameback to summary
private String engineName
Annotations
@Nullable
globalBindingsback to summary
private volatile Bindings globalBindings
Annotations
@Nullable
scriptEngineManagerback to summary
private volatile ScriptEngineManager scriptEngineManager
Annotations
@Nullable

Constructor Detail

StandardScriptEvaluatorback to summary
public StandardScriptEvaluator()

Construct a new StandardScriptEvaluator.

StandardScriptEvaluatorback to summary
public StandardScriptEvaluator(ClassLoader classLoader)

Construct a new StandardScriptEvaluator for the given class loader.

Parameters
classLoader:ClassLoader

the class loader to use for script engine detection

StandardScriptEvaluatorback to summary
public StandardScriptEvaluator(ScriptEngineManager scriptEngineManager)

Construct a new StandardScriptEvaluator for the given JSR-223 ScriptEngineManager to obtain script engines from.

Parameters
scriptEngineManager:ScriptEngineManager

the ScriptEngineManager (or subclass thereof) to use

Since
4.2.2

Method Detail

evaluateback to summary
public Object evaluate(ScriptSource script)

Implements org.springframework.scripting.ScriptEvaluator.evaluate.

Doc from org.springframework.scripting.ScriptEvaluator.evaluate.

Evaluate the given script.

Parameters
script:ScriptSource

the ScriptSource for the script to evaluate

Returns:Object

the return value of the script, if any

Annotations
@Override
@Nullable
evaluateback to summary
public Object evaluate(ScriptSource script, Map<String, Object> argumentBindings)

Implements org.springframework.scripting.ScriptEvaluator.evaluate.

Doc from org.springframework.scripting.ScriptEvaluator.evaluate.

Evaluate the given script with the given arguments.

Parameters
script:ScriptSource

the ScriptSource for the script to evaluate

argumentBindings:Map<String, Object>

the key-value pairs to expose to the script, typically as script variables (may be null or empty)

Returns:Object

the return value of the script, if any

Annotations
@Override
@Nullable
getScriptEngineback to summary
protected ScriptEngine getScriptEngine(ScriptSource script)

Obtain the JSR-223 ScriptEngine to use for the given script.

Parameters
script:ScriptSource

the script to evaluate

Returns:ScriptEngine

the ScriptEngine (never null)

setBeanClassLoaderback to summary
public void setBeanClassLoader(ClassLoader classLoader)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Doc from org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's InitializingBean#afterPropertiesSet() method or a custom init-method.

Parameters
classLoader:ClassLoader

the owning class loader

Annotations
@Override
setEngineNameback to summary
public void setEngineName(String engineName)

Set the name of the script engine for evaluating the scripts (e.g. "Groovy"), as exposed by the JSR-223 script engine factory.

Since
4.2.2
See Also
setLanguage
setGlobalBindingsback to summary
public void setGlobalBindings(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.

Since
4.2.2
See Also
evaluate(ScriptSource, Map), javax.script.ScriptEngineManager#setBindings(Bindings), javax.script.SimpleBindings
setLanguageback to summary
public void setLanguage(String language)

Set the name of the language meant for evaluating the scripts (e.g. "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
setEngineName