|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.scripting.groovy.GroovyScriptFactory
public class GroovyScriptFactory
ScriptFactory
implementation
for a Groovy script.
Typically used in combination with a
ScriptFactoryPostProcessor
;
see the latter's javadoc} for a configuration example.
groovy.lang.GroovyClassLoader
,
ScriptFactoryPostProcessor
Nested Class Summary | |
---|---|
private static class |
GroovyScriptFactory.CachedResultHolder
Wrapper that holds a temporarily cached result object. |
Field Summary | |
---|---|
private GroovyScriptFactory.CachedResultHolder |
cachedResult
|
private GroovyClassLoader |
groovyClassLoader
|
private GroovyObjectCustomizer |
groovyObjectCustomizer
|
private java.lang.Class |
scriptClass
|
private java.lang.Object |
scriptClassMonitor
|
private java.lang.Class |
scriptResultClass
|
private java.lang.String |
scriptSourceLocator
|
private boolean |
wasModifiedForTypeCheck
|
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
protected java.lang.Object |
executeScript(ScriptSource scriptSource,
java.lang.Class scriptClass)
Instantiate the given Groovy script class and run it if necessary. |
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)
Callback that supplies the bean class loader to
a bean instance. |
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final java.lang.String scriptSourceLocator
private final GroovyObjectCustomizer groovyObjectCustomizer
private GroovyClassLoader groovyClassLoader
private java.lang.Class scriptClass
private java.lang.Class scriptResultClass
private GroovyScriptFactory.CachedResultHolder cachedResult
private final java.lang.Object scriptClassMonitor
private boolean wasModifiedForTypeCheck
Constructor Detail |
---|
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
)Method Detail |
---|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
BeanFactoryAware
Invoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.
BeansException
- in case of initialization errorsBeanInitializationException
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
BeanClassLoaderAware
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.
setBeanClassLoader
in interface BeanClassLoaderAware
classLoader
- 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 GroovyClassLoader getGroovyClassLoader()
public java.lang.String getScriptSourceLocator()
ScriptFactory
Typical 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 ScriptFactory
ScriptFactoryPostProcessor.convertToScriptSource(java.lang.String, java.lang.String, org.springframework.core.io.ResourceLoader)
,
ResourceLoader
public java.lang.Class[] getScriptInterfaces()
getScriptInterfaces
in interface ScriptFactory
null
alwayspublic boolean requiresConfigInterface()
requiresConfigInterface
in interface ScriptFactory
ScriptFactory.getScriptInterfaces()
public java.lang.Object getScriptedObject(ScriptSource scriptSource, java.lang.Class[] actualInterfaces) throws java.io.IOException, ScriptCompilationException
getScriptedObject
in interface ScriptFactory
scriptSource
- 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 failed
ScriptCompilationException
- if script compilation failedgroovy.lang.GroovyClassLoader
public java.lang.Class getScriptedObjectType(ScriptSource scriptSource) throws java.io.IOException, ScriptCompilationException
ScriptFactory
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.
getScriptedObjectType
in interface ScriptFactory
scriptSource
- the actual ScriptSource to retrieve
the script source text from (never null
)
null
if none could be determined
java.io.IOException
- if script retrieval failed
ScriptCompilationException
- if script compilation failedpublic boolean requiresScriptedObjectRefresh(ScriptSource scriptSource)
ScriptFactory
isModified()
method).
requiresScriptedObjectRefresh
in interface ScriptFactory
scriptSource
- 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 class
ScriptCompilationException
- in case of instantiation failurepublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |