Package org.springframework.scripting
Interface ScriptFactory
- All Known Implementing Classes:
BshScriptFactory
,GroovyScriptFactory
,StandardScriptFactory
public interface ScriptFactory
Script definition interface, encapsulating the configuration
of a specific script as well as a factory method for
creating the actual scripted Java
Object
.- Since:
- 2.0
- Author:
- Juergen Hoeller, Rob Harrop
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetScriptedObject
(ScriptSource scriptSource, Class<?> @Nullable ... actualInterfaces) Factory method for creating the scripted Java object.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.boolean
Return whether the script requires a config interface to be generated for it.boolean
requiresScriptedObjectRefresh
(ScriptSource scriptSource) Determine whether a refresh is required (for example, through ScriptSource'sisModified()
method).
-
Method Details
-
getScriptSourceLocator
String getScriptSourceLocator()Return 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...").
- Returns:
- the script source locator
- See Also:
-
getScriptInterfaces
Return the business interfaces that the script is supposed to implement.Can return
null
if the script itself determines its Java interfaces (such as in the case of Groovy).- Returns:
- the interfaces for the script
-
requiresConfigInterface
boolean requiresConfigInterface()Return 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()
.- Returns:
- whether the script requires a generated config interface
- See Also:
-
getScriptedObject
@Nullable Object getScriptedObject(ScriptSource scriptSource, Class<?> @Nullable ... actualInterfaces) throws IOException, ScriptCompilationException Factory method for creating 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.
- 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
-
getScriptedObjectType
@Nullable Class<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException Determine 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.
- Parameters:
scriptSource
- the actual ScriptSource to retrieve the script source text from (nevernull
)- Returns:
- the type of the scripted Java object, or
null
if none could be determined - Throws:
IOException
- if script retrieval failedScriptCompilationException
- if script compilation failed- Since:
- 2.0.3
-
requiresScriptedObjectRefresh
Determine whether a refresh is required (for example, through ScriptSource'sisModified()
method).- Parameters:
scriptSource
- the actual ScriptSource to retrieve the script source text from (nevernull
)- Returns:
- whether a fresh
getScriptedObject(org.springframework.scripting.ScriptSource, java.lang.Class<?>...)
call is required - Since:
- 2.5.2
- See Also:
-