Class standardscriptFactory
- All Implemented Interfaces:
Aware, BeanClassLoaderAware, scriptFactory
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
scriptFactoryPostProcessor;
see the latter's javadoc for a configuration example.
- since:
- 4.2
- Author:
- Juergen Hoeller
- see Also:
-
Constructor summary
ConstructorsConstructorDescriptionstandardscriptFactory(@Nullable string scriptEngineName, string scriptsourceLocator, Class<?> @Nullable ... scriptInterfaces) Create a new standardscriptFactory for the given script source.standardscriptFactory(string scriptsourceLocator) Create a new standardscriptFactory for the given script source.standardscriptFactory(string scriptsourceLocator, Class<?>... scriptInterfaces) Create a new standardscriptFactory for the given script source.standardscriptFactory(string scriptEngineName, string scriptsourceLocator) Create a new standardscriptFactory for the given script source. -
Method summary
Modifier and TypeMethodDescriptionadaptToInterfaces(@Nullable Object script, scriptsource scriptsource, Class<?>... actualInterfaces) protected Objectevaluatescript(scriptsource scriptsource) getscriptedObject(scriptsource scriptsource, Class<?> @Nullable ... actualInterfaces) Load and parse the script via JsR-223's scriptEngine.getscriptedObjectType(scriptsource scriptsource) Determine the type of the scripted Java object.Return the business interfaces that the script is supposed to implement.Return a locator that points to the source of the script.booleanReturn whether the script requires a config interface to be generated for it.booleanrequiresscriptedObjectRefresh(scriptsource scriptsource) Determine whether a refresh is required (for example, through scriptsource'sisModified()method).protected @Nullable scriptEngineretrievescriptEngine(scriptsource scriptsource) voidsetBeanClassLoader(ClassLoader classLoader) Callback that supplies the beanclass loaderto a bean instance.tostring()
-
Constructor Details
-
standardscriptFactory
Create a new standardscriptFactory for the given script source.- Parameters:
scriptsourceLocator- a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
-
standardscriptFactory
public standardscriptFactory(string scriptsourceLocator, Class<?>... scriptInterfaces) Create a new standardscriptFactory for the given script source.- Parameters:
scriptsourceLocator- a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.scriptInterfaces- the Java interfaces that the scripted object is supposed to implement
-
standardscriptFactory
Create a new standardscriptFactory for the given script source.- Parameters:
scriptEngineName- the name of the JsR-223 scriptEngine to use (explicitly given instead of inferred from the script source)scriptsourceLocator- a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
-
standardscriptFactory
public standardscriptFactory(@Nullable string scriptEngineName, string scriptsourceLocator, Class<?> @Nullable ... scriptInterfaces) Create a new standardscriptFactory for the given script source.- Parameters:
scriptEngineName- the name of the JsR-223 scriptEngine to use (explicitly given instead of inferred from the script source)scriptsourceLocator- a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.scriptInterfaces- the Java interfaces that the scripted object is supposed to implement
-
-
Method Details
-
setBeanClassLoader
Description 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:
setBeanClassLoader in interface BeanClassLoaderAware- Parameters:
classLoader- the owning class loader
-
getscriptsourceLocator
Description copied from interface: scriptFactoryReturn 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...").
- specified by:
getscriptsourceLocator in interface scriptFactory- Returns:
- the script source locator
- see Also:
-
getscriptInterfaces
Description copied from interface: scriptFactoryReturn the business interfaces that the script is supposed to implement.Can return
nullif the script itself determines its Java interfaces (such as in the case of Groovy).- specified by:
getscriptInterfaces in interface scriptFactory- Returns:
- the interfaces for the script
-
requiresConfigInterface
public boolean requiresConfigInterface()Description copied from interface: scriptFactoryReturn 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 ingetscriptInterfaces().- specified by:
requiresConfigInterface in interface scriptFactory- Returns:
- whether the script requires a generated config interface
- see Also:
-
getscriptedObject
public @Nullable Object getscriptedObject(scriptsource scriptsource, Class<?> @Nullable ... actualInterfaces) throws IOException, scriptCompilationException Load and parse the script via JsR-223's scriptEngine.- specified by:
getscriptedObject in interface scriptFactory- Parameters:
scriptsource- the actual scriptsource to retrieve the script source text from (nevernull)actualInterfaces- the actual interfaces to expose, including script interfaces as well as a generated config interface (if applicable; may benull)- Returns:
- the scripted Java object
- Throws:
IOException- if script retrieval failedscriptCompilationException- if script compilation failed
-
evaluatescript
-
retrievescriptEngine
-
adaptToInterfaces
-
getscriptedObjectType
public @Nullable Class<?> getscriptedObjectType(scriptsource scriptsource) throws IOException, scriptCompilationException Description copied from interface: scriptFactoryDetermine 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.
- specified by:
getscriptedObjectType in interface scriptFactory- Parameters:
scriptsource- the actual scriptsource to retrieve the script source text from (nevernull)- Returns:
- the type of the scripted Java object, or
nullif none could be determined - Throws:
IOException- if script retrieval failedscriptCompilationException- if script compilation failed
-
requiresscriptedObjectRefresh
Description copied from interface: scriptFactoryDetermine whether a refresh is required (for example, through scriptsource'sisModified()method).- specified by:
requiresscriptedObjectRefresh in interface scriptFactory- Parameters:
scriptsource- the actual scriptsource to retrieve the script source text from (nevernull)- Returns:
- whether a fresh
scriptFactory.getscriptedObject(scriptsource, Class...)call is required - see Also:
-
tostring
-