public class GroovyScriptFactory extends java.lang.Object implements ScriptFactory, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanClassLoaderAware
ScriptFactory implementation
for a Groovy script.
Typically used in combination with a
ScriptFactoryPostProcessor;
see the latter's javadoc} for a configuration example.
Note: Spring 4.0 supports Groovy 1.8 and higher.
GroovyClassLoader,
ScriptFactoryPostProcessor| Constructor and Description |
|---|
GroovyScriptFactory(java.lang.String scriptSourceLocator)
Create a new GroovyScriptFactory for the given script source.
|
GroovyScriptFactory(java.lang.String scriptSourceLocator,
GroovyObjectCustomizer groovyObjectCustomizer)
Create a new GroovyScriptFactory for the given script source,
specifying a strategy interface that can create a custom MetaClass
to supply missing methods and otherwise change the behavior of the object.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
executeScript(ScriptSource scriptSource,
java.lang.Class<?> scriptClass)
Instantiate the given Groovy script class and run it if necessary.
|
groovy.lang.GroovyClassLoader |
getGroovyClassLoader()
Return the GroovyClassLoader used by this script factory.
|
java.lang.Object |
getScriptedObject(ScriptSource scriptSource,
java.lang.Class<?>... actualInterfaces)
Loads and parses the Groovy script via the GroovyClassLoader.
|
java.lang.Class<?> |
getScriptedObjectType(ScriptSource scriptSource)
Determine the type of the scripted Java object.
|
java.lang.Class<?>[] |
getScriptInterfaces()
Groovy scripts determine their interfaces themselves,
hence we don't need to explicitly expose interfaces here.
|
java.lang.String |
getScriptSourceLocator()
Return a locator that points to the source of the script.
|
boolean |
requiresConfigInterface()
Groovy scripts do not need a config interface,
since they expose their setters as public methods.
|
boolean |
requiresScriptedObjectRefresh(ScriptSource scriptSource)
Determine whether a refresh is required (e.g.
|
void |
setBeanClassLoader(java.lang.ClassLoader classLoader) |
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
java.lang.String |
toString() |
public GroovyScriptFactory(java.lang.String scriptSourceLocator)
We don't need to specify script interfaces here, since a Groovy script defines its Java interfaces itself.
scriptSourceLocator - a locator that points to the source of the script.
Interpreted by the post-processor that actually creates the script.public GroovyScriptFactory(java.lang.String scriptSourceLocator,
GroovyObjectCustomizer groovyObjectCustomizer)
We don't need to specify script interfaces here, since a Groovy script defines its Java interfaces itself.
scriptSourceLocator - a locator that points to the source of the script.
Interpreted by the post-processor that actually creates the script.groovyObjectCustomizer - a customizer that can set a custom metaclass
or make other changes to the GroovyObject created by this factory
(may be null)public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
throws org.springframework.beans.BeansException
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwareorg.springframework.beans.BeansExceptionpublic void setBeanClassLoader(java.lang.ClassLoader classLoader)
setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAwarepublic groovy.lang.GroovyClassLoader getGroovyClassLoader()
public java.lang.String getScriptSourceLocator()
ScriptFactoryTypical supported locators are Spring resource locations (such as "file:C:/myScript.bsh" or "classpath:myPackage/myScript.bsh") and inline scripts ("inline:myScriptText...").
getScriptSourceLocator in interface ScriptFactoryScriptFactoryPostProcessor.convertToScriptSource(java.lang.String, java.lang.String, org.springframework.core.io.ResourceLoader),
ResourceLoaderpublic java.lang.Class<?>[] getScriptInterfaces()
getScriptInterfaces in interface ScriptFactorynull alwayspublic boolean requiresConfigInterface()
requiresConfigInterface in interface ScriptFactoryScriptFactory.getScriptInterfaces()public java.lang.Object getScriptedObject(ScriptSource scriptSource, java.lang.Class<?>... actualInterfaces) throws java.io.IOException, ScriptCompilationException
getScriptedObject in interface ScriptFactoryscriptSource - the actual ScriptSource to retrieve
the script source text from (never null)actualInterfaces - the actual interfaces to expose,
including script interfaces as well as a generated config interface
(if applicable; may be null)java.io.IOException - if script retrieval failedScriptCompilationException - if script compilation failedGroovyClassLoaderpublic java.lang.Class<?> getScriptedObjectType(ScriptSource scriptSource) throws java.io.IOException, ScriptCompilationException
ScriptFactoryImplementations 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.
getScriptedObjectType in interface ScriptFactoryscriptSource - the actual ScriptSource to retrieve
the script source text from (never null)null
if none could be determinedjava.io.IOException - if script retrieval failedScriptCompilationException - if script compilation failedpublic boolean requiresScriptedObjectRefresh(ScriptSource scriptSource)
ScriptFactoryisModified() method).requiresScriptedObjectRefresh in interface ScriptFactoryscriptSource - the actual ScriptSource to retrieve
the script source text from (never null)ScriptFactory.getScriptedObject(org.springframework.scripting.ScriptSource, java.lang.Class<?>...) call is requiredScriptSource.isModified()protected java.lang.Object executeScript(ScriptSource scriptSource, java.lang.Class<?> scriptClass) throws ScriptCompilationException
scriptSource - the source for the underlying scriptscriptClass - the Groovy script classScriptCompilationException - in case of instantiation failurepublic java.lang.String toString()
toString in class java.lang.Object