public class StandardScriptEvaluator extends Object implements ScriptEvaluator, BeanClassLoaderAware
javax.script
(JSR-223) based implementation of Spring's ScriptEvaluator
strategy interface.ScriptEngine.eval(String)
Constructor and Description |
---|
StandardScriptEvaluator()
Construct a new StandardScriptEvaluator.
|
StandardScriptEvaluator(ClassLoader classLoader)
Construct a new StandardScriptEvaluator.
|
Modifier and Type | Method and Description |
---|---|
Object |
evaluate(ScriptSource script)
Evaluate the given script.
|
Object |
evaluate(ScriptSource script,
Map<String,Object> arguments)
Evaluate the given script with the given arguments.
|
protected ScriptEngine |
getScriptEngine(ScriptSource script)
Obtain the JSR-223 ScriptEngine to use for the given script.
|
void |
setBeanClassLoader(ClassLoader classLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setLanguage(String language)
Set the name of language meant for evaluation the scripts (e.g.
|
public StandardScriptEvaluator()
public StandardScriptEvaluator(ClassLoader classLoader)
classLoader
- the class loader to use for script engine detectionpublic void setBeanClassLoader(ClassLoader classLoader)
BeanClassLoaderAware
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.
setBeanClassLoader
in interface BeanClassLoaderAware
classLoader
- the owning class loader; may be null
in
which case a default ClassLoader
must be used, for example
the ClassLoader
obtained via
ClassUtils.getDefaultClassLoader()
public void setLanguage(String language)
public Object evaluate(ScriptSource script)
ScriptEvaluator
evaluate
in interface ScriptEvaluator
script
- the ScriptSource for the script to evaluatepublic Object evaluate(ScriptSource script, Map<String,Object> arguments)
ScriptEvaluator
evaluate
in interface ScriptEvaluator
script
- the ScriptSource for the script to evaluatearguments
- the key-value pairs to expose to the script,
typically as script variables (may be null
or empty)protected ScriptEngine getScriptEngine(ScriptSource script)
script
- the script to evaluatenull
)