public class GroovyScriptEngine extends Object implements ResourceConnector
Constructor and Description |
---|
GroovyScriptEngine(ResourceConnector rc) |
GroovyScriptEngine(ResourceConnector rc,
ClassLoader parentClassLoader) |
GroovyScriptEngine(String url) |
GroovyScriptEngine(String[] urls) |
GroovyScriptEngine(String[] urls,
ClassLoader parentClassLoader) |
GroovyScriptEngine(String url,
ClassLoader parentClassLoader) |
GroovyScriptEngine(URL[] roots) |
GroovyScriptEngine(URL[] roots,
ClassLoader parentClassLoader) |
Modifier and Type | Method and Description |
---|---|
Script |
createScript(String scriptName,
Binding binding)
Creates a Script with a given scriptName and binding.
|
CompilerConfiguration |
getConfig() |
protected long |
getCurrentTime() |
GroovyClassLoader |
getGroovyClassLoader()
Returns the GroovyClassLoader associated with this script engine instance.
|
ClassLoader |
getParentClassLoader()
Get the
ClassLoader that will serve as the parent ClassLoader of the
GroovyClassLoader in which scripts will be executed. |
URLConnection |
getResourceConnection(String resourceName)
Get a resource connection as a
URLConnection to retrieve a script
from the ResourceConnector . |
protected boolean |
isSourceNewer(groovy.util.GroovyScriptEngine.ScriptCacheEntry entry) |
Class |
loadScriptByName(String scriptName)
Get the class of the scriptName in question, so that you can instantiate
Groovy objects with caching and reloading.
|
static void |
main(String[] urls)
Simple testing harness for the GSE.
|
Object |
run(String scriptName,
Binding binding)
Run a script identified by name with a given binding.
|
String |
run(String scriptName,
String argument)
Run a script identified by name with a single argument.
|
void |
setConfig(CompilerConfiguration config)
sets a compiler configuration
|
public GroovyScriptEngine(URL[] roots)
public GroovyScriptEngine(URL[] roots, ClassLoader parentClassLoader)
public GroovyScriptEngine(String[] urls) throws IOException
IOException
public GroovyScriptEngine(String[] urls, ClassLoader parentClassLoader) throws IOException
IOException
public GroovyScriptEngine(String url) throws IOException
IOException
public GroovyScriptEngine(String url, ClassLoader parentClassLoader) throws IOException
IOException
public GroovyScriptEngine(ResourceConnector rc)
public GroovyScriptEngine(ResourceConnector rc, ClassLoader parentClassLoader)
public static void main(String[] urls) throws Exception
urls
- an array of URLsException
- if something goes wrongpublic URLConnection getResourceConnection(String resourceName) throws ResourceException
URLConnection
to retrieve a script
from the ResourceConnector
.getResourceConnection
in interface ResourceConnector
resourceName
- name of the resource to be retrievedResourceException
public ClassLoader getParentClassLoader()
ClassLoader
that will serve as the parent ClassLoader of the
GroovyClassLoader
in which scripts will be executed. By default, this is the
ClassLoader that loaded the GroovyScriptEngine
class.public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException
scriptName
- resource name pointing to the scriptResourceException
- if there is a problem accessing the scriptScriptException
- if there is a problem parsing the scriptpublic String run(String scriptName, String argument) throws ResourceException, ScriptException
scriptName
- name of the script to runargument
- a single argument passed as a variable named arg
in the bindingtoString()
representation of the result of the execution of the scriptResourceException
- if there is a problem accessing the scriptScriptException
- if there is a problem parsing the scriptpublic Object run(String scriptName, Binding binding) throws ResourceException, ScriptException
scriptName
- name of the script to runbinding
- the binding to pass to the scriptResourceException
- if there is a problem accessing the scriptScriptException
- if there is a problem parsing the scriptpublic Script createScript(String scriptName, Binding binding) throws ResourceException, ScriptException
scriptName
- name of the script to runbinding
- the binding to pass to the scriptResourceException
- if there is a problem accessing the scriptScriptException
- if there is a problem parsing the scriptprotected boolean isSourceNewer(groovy.util.GroovyScriptEngine.ScriptCacheEntry entry) throws ResourceException
ResourceException
public GroovyClassLoader getGroovyClassLoader()
public CompilerConfiguration getConfig()
public void setConfig(CompilerConfiguration config)
config
- - the compiler configurationNullPointerException
- if config is nullprotected long getCurrentTime()