Class GroovyScriptFactory

java.lang.Object
org.springframework.scripting.groovy.GroovyScriptFactory
All Implemented Interfaces:
Aware, BeanClassLoaderAware, BeanFactoryAware, ScriptFactory

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.

Since:
2.0
Author:
Juergen Hoeller, Rob Harrop, Rod Johnson
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    GroovyScriptFactory(String scriptSourceLocator)
    Create a new GroovyScriptFactory for the given script source.
    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, 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, 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.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected groovy.lang.GroovyClassLoader
    Build a GroovyClassLoader for the given ClassLoader.
    protected Object
    executeScript(ScriptSource scriptSource, Class<?> scriptClass)
    Instantiate the given Groovy script class and run it if necessary.
    groovy.lang.GroovyClassLoader
    Return the GroovyClassLoader used by this script factory.
    getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces)
    Loads and parses the Groovy script via the GroovyClassLoader.
    Determine the type of the scripted Java object.
    Class<?>[]
    Groovy scripts determine their interfaces themselves, hence we don't need to explicitly expose interfaces here.
    Return a locator that points to the source of the script.
    boolean
    Groovy scripts do not need a config interface, since they expose their setters as public methods.
    boolean
    Determine whether a refresh is required (for example, through ScriptSource's isModified() method).
    void
    Callback that supplies the bean class loader to a bean instance.
    void
    Callback that supplies the owning factory to a bean instance.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • GroovyScriptFactory

      public GroovyScriptFactory(String scriptSourceLocator)
      Create a new GroovyScriptFactory for the given script source.

      We don't need to specify script interfaces here, since a Groovy script defines its Java interfaces itself.

      Parameters:
      scriptSourceLocator - a locator that points to the source of the script. Interpreted by the post-processor that actually creates the script.
    • GroovyScriptFactory

      public GroovyScriptFactory(String scriptSourceLocator, @Nullable 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.
      Parameters:
      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)
      See Also:
    • GroovyScriptFactory

      public GroovyScriptFactory(String scriptSourceLocator, @Nullable 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.
      Parameters:
      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)
      Since:
      4.3.3
      See Also:
      • GroovyClassLoader(ClassLoader, CompilerConfiguration)
    • GroovyScriptFactory

      public 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.
      Parameters:
      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 configuration
      Since:
      4.3.3
      See Also:
      • CompilerConfiguration.addCompilationCustomizers(org.codehaus.groovy.control.customizers.CompilationCustomizer...)
      • ImportCustomizer
  • Method Details