Package org.springframework.scripting.support

# Class StandardScriptEvaluator

java.lang.Object
org.springframework.scripting.support.StandardScriptEvaluator

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanClassLoaderAware`, `ScriptEvaluator`

public class StandardScriptEvaluator extends Object implements ScriptEvaluator, org.springframework.beans.factory.BeanClassLoaderAware
`javax.script` (JSR-223) based implementation of Spring's `ScriptEvaluator` strategy interface.

Since:
  4.0
Author:
  Juergen Hoeller, Costin Leau
See Also:
  - `ScriptEngine.eval(String)`

## Constructor Summary

Constructors
Constructor
Description
`StandardScriptEvaluator()`
Construct a new `StandardScriptEvaluator`.
`StandardScriptEvaluator(ClassLoader classLoader)`
Construct a new `StandardScriptEvaluator` for the given class loader.
`StandardScriptEvaluator(ScriptEngineManager scriptEngineManager)`
Construct a new `StandardScriptEvaluator` for the given JSR-223 `ScriptEngineManager` to obtain script engines from.

## Method Summary

Modifier and Type
Method
Description
`Object`
`evaluate(ScriptSource script)`
Evaluate the given script.
`Object`
`evaluate(ScriptSource script, Map<String,Object> argumentBindings)`
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)`
`void`
`setEngineName(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.
`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.
`void`
`setLanguage(String language)`
Set the name of the language meant for evaluating the scripts (for example, "Groovy").

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### StandardScriptEvaluator

public StandardScriptEvaluator()
Construct a new `StandardScriptEvaluator`.

### StandardScriptEvaluator

public StandardScriptEvaluator(ClassLoader classLoader)
Construct a new `StandardScriptEvaluator` for the given class loader.

Parameters:
  `classLoader` - the class loader to use for script engine detection

### StandardScriptEvaluator

public StandardScriptEvaluator(ScriptEngineManager scriptEngineManager)
Construct a new `StandardScriptEvaluator` for the given JSR-223 `ScriptEngineManager` to obtain script engines from.

Parameters:
  `scriptEngineManager` - the ScriptEngineManager (or subclass thereof) to use
Since:
  4.2.2

## Method Details

### setLanguage

public void setLanguage(String language)
Set 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:
  - `setEngineName(java.lang.String)`

### setEngineName

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

Since:
  4.2.2
See Also:
  - `setLanguage(java.lang.String)`

### setGlobalBindings

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)`
  - `ScriptEngineManager.setBindings(Bindings)`
  - `SimpleBindings`

### setBeanClassLoader

public void setBeanClassLoader(ClassLoader classLoader)

Specified by:
  `setBeanClassLoader` in interface `org.springframework.beans.factory.BeanClassLoaderAware`

### evaluate

@Nullable public Object evaluate(ScriptSource script)
Description copied from interface: `ScriptEvaluator`
Evaluate the given script.

Specified by:
  `evaluate` in 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: `ScriptEvaluator`
Evaluate the given script with the given arguments.

Specified by:
  `evaluate` in 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 `null` or empty)
Returns:
  the return value of the script, if any

### getScriptEngine

protected ScriptEngine getScriptEngine(ScriptSource script)
Obtain the JSR-223 ScriptEngine to use for the given script.

Parameters:
  `script` - the script to evaluate
Returns:
  the ScriptEngine (never `null`)