public class GroovyScriptFactory extends Object implements ScriptFactory, BeanFactoryAware, 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(String scriptSourceLocator)Create a new GroovyScriptFactory for the given script source. | 
| GroovyScriptFactory(String scriptSourceLocator,
                   org.codehaus.groovy.control.customizers.CompilationCustomizer... compilationCustomizers)Create a new GroovyScriptFactory for the given script source,
 specifying a strategy interface that can customize Groovy's compilation
 process within the underlying GroovyClassLoader. | 
| GroovyScriptFactory(String scriptSourceLocator,
                   org.codehaus.groovy.control.CompilerConfiguration compilerConfiguration)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. | 
| GroovyScriptFactory(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 groovy.lang.GroovyClassLoader | buildGroovyClassLoader(ClassLoader classLoader)Build a  GroovyClassLoaderfor the givenClassLoader. | 
| protected Object | executeScript(ScriptSource scriptSource,
             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. | 
| Object | getScriptedObject(ScriptSource scriptSource,
                 Class<?>... actualInterfaces)Loads and parses the Groovy script via the GroovyClassLoader. | 
| Class<?> | getScriptedObjectType(ScriptSource scriptSource)Determine the type of the scripted Java object. | 
| Class<?>[] | getScriptInterfaces()Groovy scripts determine their interfaces themselves,
 hence we don't need to explicitly expose interfaces here. | 
| 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(ClassLoader classLoader)Callback that supplies the bean  class loaderto
 a bean instance. | 
| void | setBeanFactory(BeanFactory beanFactory)Callback that supplies the owning factory to a bean instance. | 
| String | toString() | 
public GroovyScriptFactory(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(String scriptSourceLocator, GroovyObjectCustomizer groovyObjectCustomizer)
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)GroovyObjectCustomizer.customize(groovy.lang.GroovyObject)public GroovyScriptFactory(String scriptSourceLocator, org.codehaus.groovy.control.CompilerConfiguration compilerConfiguration)
scriptSourceLocator - a locator that points to the source of the script.
 Interpreted by the post-processor that actually creates the script.compilerConfiguration - a custom compiler configuration to be applied
 to the GroovyClassLoader (may be null)GroovyClassLoader.GroovyClassLoader(ClassLoader, CompilerConfiguration)public GroovyScriptFactory(String scriptSourceLocator, org.codehaus.groovy.control.customizers.CompilationCustomizer... compilationCustomizers)
scriptSourceLocator - a locator that points to the source of the script.
 Interpreted by the post-processor that actually creates the script.compilationCustomizers - one or more customizers to be applied to the
 GroovyClassLoader compiler configurationCompilerConfiguration.addCompilationCustomizers(org.codehaus.groovy.control.customizers.CompilationCustomizer...), 
ImportCustomizerpublic void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAwareInvoked after the population of normal bean properties
 but before an initialization callback such as
 InitializingBean.afterPropertiesSet() or a custom init-method.
setBeanFactory in interface BeanFactoryAwarebeanFactory - owning BeanFactory (never null).
 The bean can immediately call methods on the factory.BeanInitializationExceptionpublic void setBeanClassLoader(ClassLoader classLoader)
BeanClassLoaderAwareclass 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 BeanClassLoaderAwareclassLoader - 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 groovy.lang.GroovyClassLoader getGroovyClassLoader()
protected groovy.lang.GroovyClassLoader buildGroovyClassLoader(ClassLoader classLoader)
GroovyClassLoader for the given ClassLoader.classLoader - the ClassLoader to build a GroovyClassLoader forpublic 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 Class<?>[] getScriptInterfaces()
getScriptInterfaces in interface ScriptFactorynull alwayspublic boolean requiresConfigInterface()
requiresConfigInterface in interface ScriptFactoryScriptFactory.getScriptInterfaces()public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces) throws 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)IOException - if script retrieval failedScriptCompilationException - if script compilation failedGroovyClassLoaderpublic Class<?> getScriptedObjectType(ScriptSource scriptSource) throws 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 determinedIOException - 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 Object executeScript(ScriptSource scriptSource, Class<?> scriptClass) throws ScriptCompilationException
scriptSource - the source for the underlying scriptscriptClass - the Groovy script classScriptCompilationException - in case of instantiation failure