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

public Class StandardScriptFactory

extends Object
implements ScriptFactory, BeanClassLoaderAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.Aware, org.springframework.scripting.ScriptFactory
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, javax.script.Invocable, .ScriptEngine, .ScriptEngineManager, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.lang.Nullable, org.springframework.scripting.ScriptCompilationException, .ScriptFactory, .ScriptSource, org.springframework.util.Assert, .ClassUtils, .ObjectUtils, .ReflectionUtils, .StringUtils

org.springframework.scripting.ScriptFactory implementation based on the JSR-223 script engine abstraction (as included in Java). Supports JavaScript, Groovy, JRuby, and other JSR-223 compliant engines.

Typically used in combination with a org.springframework.scripting.support.ScriptFactoryPostProcessor; see the latter's javadoc for a configuration example.

Author
Juergen Hoeller
Since
4.2
See Also
ScriptFactoryPostProcessor

Field Summary

Modifier and TypeField and Description
private ClassLoader
private volatile ScriptEngine
private final String
private final Class<?>[]
private final String

Constructor Summary

AccessConstructor and Description
public
StandardScriptFactory(String
a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
scriptSourceLocator
)

Create a new StandardScriptFactory for the given script source.

public
StandardScriptFactory(String
a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
scriptSourceLocator
,
Class<?>...
the Java interfaces that the scripted object is supposed to implement
scriptInterfaces
)

Create a new StandardScriptFactory for the given script source.

public
StandardScriptFactory(String
the name of the JSR-223 ScriptEngine to use (explicitly given instead of inferred from the script source)
scriptEngineName
,
String
a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
scriptSourceLocator
)

Create a new StandardScriptFactory for the given script source.

public
StandardScriptFactory(String
the name of the JSR-223 ScriptEngine to use (explicitly given instead of inferred from the script source)
scriptEngineName
,
String
a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
scriptSourceLocator
,
Class<?>...
the Java interfaces that the scripted object is supposed to implement
scriptInterfaces
)

Create a new StandardScriptFactory for the given script source.

Method Summary

Modifier and TypeMethod and Description
protected Object
adaptToInterfaces(Object script, ScriptSource scriptSource, Class<?>... actualInterfaces)

protected Object
public Object
getScriptedObject(ScriptSource
the actual ScriptSource to retrieve the script source text from (never null)
scriptSource
,
Class<?>...
the actual interfaces to expose, including script interfaces as well as a generated config interface (if applicable; may be null)
actualInterfaces
)

Implements org.springframework.scripting.ScriptFactory.getScriptedObject.

Load and parse the script via JSR-223's ScriptEngine.

public Class<?>
getScriptedObjectType(ScriptSource
the actual ScriptSource to retrieve the script source text from (never null)
scriptSource
)

Implements org.springframework.scripting.ScriptFactory.getScriptedObjectType.

Determine the type of the scripted Java object.

public Class<?>[]
getScriptInterfaces()

Implements org.springframework.scripting.ScriptFactory.getScriptInterfaces.

Return the business interfaces that the script is supposed to implement.

public String
getScriptSourceLocator()

Implements org.springframework.scripting.ScriptFactory.getScriptSourceLocator.

Return a locator that points to the source of the script.

public boolean
requiresConfigInterface()

Implements org.springframework.scripting.ScriptFactory.requiresConfigInterface.

Return whether the script requires a config interface to be generated for it.

public boolean
requiresScriptedObjectRefresh(ScriptSource
the actual ScriptSource to retrieve the script source text from (never null)
scriptSource
)

Implements org.springframework.scripting.ScriptFactory.requiresScriptedObjectRefresh.

Determine whether a refresh is required (e.g. through ScriptSource's isModified() method).

protected ScriptEngine
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 String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

beanClassLoaderback to summary
private ClassLoader beanClassLoader
Annotations
@Nullable
scriptEngineback to summary
private volatile ScriptEngine scriptEngine
Annotations
@Nullable
scriptEngineNameback to summary
private final String scriptEngineName
Annotations
@Nullable
scriptInterfacesback to summary
private final Class<?>[] scriptInterfaces
Annotations
@Nullable
scriptSourceLocatorback to summary
private final String scriptSourceLocator

Constructor Detail

StandardScriptFactoryback to summary
public StandardScriptFactory(String scriptSourceLocator)

Create a new StandardScriptFactory for the given script source.

Parameters
scriptSourceLocator:String

a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.

StandardScriptFactoryback to summary
public StandardScriptFactory(String scriptSourceLocator, Class<?>... scriptInterfaces)

Create a new StandardScriptFactory for the given script source.

Parameters
scriptSourceLocator:String

a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.

scriptInterfaces:Class<?>[]

the Java interfaces that the scripted object is supposed to implement

StandardScriptFactoryback to summary
public StandardScriptFactory(String scriptEngineName, String scriptSourceLocator)

Create a new StandardScriptFactory for the given script source.

Parameters
scriptEngineName:String

the name of the JSR-223 ScriptEngine to use (explicitly given instead of inferred from the script source)

scriptSourceLocator:String

a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.

StandardScriptFactoryback to summary
public StandardScriptFactory(String scriptEngineName, String scriptSourceLocator, Class<?>... scriptInterfaces)

Create a new StandardScriptFactory for the given script source.

Parameters
scriptEngineName:String

the name of the JSR-223 ScriptEngine to use (explicitly given instead of inferred from the script source)

scriptSourceLocator:String

a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.

scriptInterfaces:Class<?>[]

the Java interfaces that the scripted object is supposed to implement

Method Detail

adaptToInterfacesback to summary
protected Object adaptToInterfaces(Object script, ScriptSource scriptSource, Class<?>... actualInterfaces)
Annotations
@Nullable
evaluateScriptback to summary
protected Object evaluateScript(ScriptSource scriptSource)
getScriptedObjectback to summary
public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces) throws IOException, ScriptCompilationException

Implements org.springframework.scripting.ScriptFactory.getScriptedObject.

Load and parse the script via JSR-223's ScriptEngine.

Parameters
scriptSource:ScriptSource

Doc from org.springframework.scripting.ScriptFactory.getScriptedObject.

the actual ScriptSource to retrieve the script source text from (never null)

actualInterfaces:Class<?>[]

Doc from org.springframework.scripting.ScriptFactory.getScriptedObject.

the actual interfaces to expose, including script interfaces as well as a generated config interface (if applicable; may be null)

Returns:Object

Doc from org.springframework.scripting.ScriptFactory.getScriptedObject.

the scripted Java object

Annotations
@Override
@Nullable
Exceptions
IOException:

Doc from org.springframework.scripting.ScriptFactory.getScriptedObject.

if script retrieval failed

ScriptCompilationException:

Doc from org.springframework.scripting.ScriptFactory.getScriptedObject.

if script compilation failed

getScriptedObjectTypeback to summary
public Class<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException

Implements org.springframework.scripting.ScriptFactory.getScriptedObjectType.

Doc from org.springframework.scripting.ScriptFactory.getScriptedObjectType.

Determine the type of the scripted Java object.

Implementations are encouraged to cache script metadata such as a generated script class. Note that this method may be invoked concurrently and must be implemented in a thread-safe fashion.

Parameters
scriptSource:ScriptSource

the actual ScriptSource to retrieve the script source text from (never null)

Returns:Class<?>

the type of the scripted Java object, or null if none could be determined

Annotations
@Override
@Nullable
Exceptions
IOException:
if script retrieval failed
ScriptCompilationException:
if script compilation failed
getScriptInterfacesback to summary
public Class<?>[] getScriptInterfaces()

Implements org.springframework.scripting.ScriptFactory.getScriptInterfaces.

Doc from org.springframework.scripting.ScriptFactory.getScriptInterfaces.

Return the business interfaces that the script is supposed to implement.

Can return null if the script itself determines its Java interfaces (such as in the case of Groovy).

Returns:Class<?>[]

the interfaces for the script

Annotations
@Override
@Nullable
getScriptSourceLocatorback to summary
public String getScriptSourceLocator()

Implements org.springframework.scripting.ScriptFactory.getScriptSourceLocator.

Doc from org.springframework.scripting.ScriptFactory.getScriptSourceLocator.

Return a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.

Typical supported locators are Spring resource locations (such as "file:C:/myScript.bsh" or "classpath:myPackage/myScript.bsh") and inline scripts ("inline:myScriptText...").

Returns:String

the script source locator

Annotations
@Override
requiresConfigInterfaceback to summary
public boolean requiresConfigInterface()

Implements org.springframework.scripting.ScriptFactory.requiresConfigInterface.

Doc from org.springframework.scripting.ScriptFactory.requiresConfigInterface.

Return whether the script requires a config interface to be generated for it. This is typically the case for scripts that do not determine Java signatures themselves, with no appropriate config interface specified in getScriptInterfaces().

Returns:boolean

whether the script requires a generated config interface

Annotations
@Override
requiresScriptedObjectRefreshback to summary
public boolean requiresScriptedObjectRefresh(ScriptSource scriptSource)

Implements org.springframework.scripting.ScriptFactory.requiresScriptedObjectRefresh.

Doc from org.springframework.scripting.ScriptFactory.requiresScriptedObjectRefresh.

Determine whether a refresh is required (e.g. through ScriptSource's isModified() method).

Parameters
scriptSource:ScriptSource

the actual ScriptSource to retrieve the script source text from (never null)

Returns:boolean

whether a fresh getScriptedObject call is required

Annotations
@Override
retrieveScriptEngineback to summary
protected ScriptEngine retrieveScriptEngine(ScriptSource scriptSource)
Annotations
@Nullable
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
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override