Overview | Package | Class | Deprecated | Index | Help
| Groovy 1.7.0
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.util
Class GroovyScriptEngine

    java.lang.Object
      groovy.util.GroovyScriptEngine

All Implemented Interfaces:
  ResourceConnector

    class GroovyScriptEngine
    extends Object

Specific script engine able to reload modified scripts as well as dealing properly with dependent scripts.

author:
  sam

author:
  Marc Palmer

author:
  Guillaume Laforge

author:
  Jochen Theodorou

Nested Class Summary
`class` | `GroovyScriptEngine.ScriptCacheEntry`
`class` | `GroovyScriptEngine.ScriptClassLoader`

Constructor Summary
`GroovyScriptEngine()`

Method Summary
`def` | `GroovyScriptEngine(URL[] roots)`
`def` | `GroovyScriptEngine(URL[] roots, ClassLoader parentClassLoader)`
`def` | `GroovyScriptEngine(String[] urls)`
`def` | `GroovyScriptEngine(String[] urls, ClassLoader parentClassLoader)`
`def` | `GroovyScriptEngine(String url)`
`def` | `GroovyScriptEngine(String url, ClassLoader parentClassLoader)`
`def` | `GroovyScriptEngine(ResourceConnector rc)`
`def` | `GroovyScriptEngine(ResourceConnector rc, ClassLoader parentClassLoader)`
`Script` | `createScript(String scriptName, Binding binding)` Creates a Script with a given scriptName and binding.
`CompilerConfiguration` | `getConfig()`
`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 {
`URLConnection` | `getResourceConnection(String resourceName)` Get a resource connection as a `URLConnection` to retrieve a script from the `ResourceConnector`.
`protected boolean` | `isSourceNewer(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.
`Class` | `loadScriptByName(String scriptName, ClassLoader parentClassLoader)` 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.
`String` | `run(String scriptName, String argument)` Run a script identified by name with a single argument.
`Object` | `run(String scriptName, Binding binding)` Run a script identified by name with a given binding.
`void` | `setConfig(CompilerConfiguration config)` sets a compiler configuration
`void` | `setParentClassLoader(ClassLoader parentClassLoader)` for scripts executed by the engine

Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll

Constructor Detail

### GroovyScriptEngine

    GroovyScriptEngine()

Method Detail

### GroovyScriptEngine

    public def GroovyScriptEngine(URL[] roots)

### GroovyScriptEngine

    public def GroovyScriptEngine(URL[] roots, ClassLoader parentClassLoader)

### GroovyScriptEngine

    public def GroovyScriptEngine(String[] urls)

### GroovyScriptEngine

    public def GroovyScriptEngine(String[] urls, ClassLoader parentClassLoader)

### GroovyScriptEngine

    public def GroovyScriptEngine(String url)

### GroovyScriptEngine

    public def GroovyScriptEngine(String url, ClassLoader parentClassLoader)

### GroovyScriptEngine

    public def GroovyScriptEngine(ResourceConnector rc)

### GroovyScriptEngine

    public def GroovyScriptEngine(ResourceConnector rc, ClassLoader parentClassLoader)

### createScript

    public Script createScript(String scriptName, Binding binding)

  Creates a Script with a given scriptName and binding.
  param:
    scriptName name of the script to run
  param:
    binding the binding to pass to the script
  return:
    the script object
  throws:
    ResourceException if there is a problem accessing the script
  throws:
    ScriptException if there is a problem parsing the script

### getConfig

    public CompilerConfiguration getConfig()

  return:
    a non null compiler configuration

### getGroovyClassLoader

    public GroovyClassLoader getGroovyClassLoader()

  Returns the GroovyClassLoader associated with this script engine instance. Useful if you need to pass the class loader to another library.
  return:
    the GroovyClassLoader

### getParentClassLoader

    public ClassLoader getParentClassLoader()

  Get the `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.
  return:
    the parent classloader used to load scripts

### getResourceConnection

    public URLConnection getResourceConnection(String resourceName)

  Get a resource connection as a `URLConnection` to retrieve a script from the `ResourceConnector`.
  param:
    resourceName name of the resource to be retrieved
  return:
    a URLConnection to the resource
  throws:
    ResourceException

### isSourceNewer

    protected boolean isSourceNewer(ScriptCacheEntry entry)

### loadScriptByName

    public Class loadScriptByName(String scriptName)

  Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading.
  param:
    scriptName resource name pointing to the script
  return:
    the loaded scriptName as a compiled class
  throws:
    ResourceException if there is a problem accessing the script
  throws:
    ScriptException if there is a problem parsing the script

### loadScriptByName

    public Class loadScriptByName(String scriptName, ClassLoader parentClassLoader)

  Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading.
  param:
    scriptName resource name pointing to the script
  param:
    parentClassLoader the class loader to use when loading the script
  return:
    the loaded scriptName as a compiled class
  throws:
    ResourceException if there is a problem accessing the script
  throws:
    ScriptException if there is a problem parsing the script
  deprecated:

### main

    public static void main(String[] urls)

  Simple testing harness for the GSE. Enter script roots as arguments and then input script names to run them.
  param:
    urls an array of URLs
  throws:
    Exception if something goes wrong

### run

    public String run(String scriptName, String argument)

  Run a script identified by name with a single argument.
  param:
    scriptName name of the script to run
  param:
    argument a single argument passed as a variable named `arg` in the binding
  return:
    a `toString()` representation of the result of the execution of the script
  throws:
    ResourceException if there is a problem accessing the script
  throws:
    ScriptException if there is a problem parsing the script

### run

    public Object run(String scriptName, Binding binding)

  Run a script identified by name with a given binding.
  param:
    scriptName name of the script to run
  param:
    binding the binding to pass to the script
  return:
    an object
  throws:
    ResourceException if there is a problem accessing the script
  throws:
    ScriptException if there is a problem parsing the script

### setConfig

    public void setConfig(CompilerConfiguration config)

  sets a compiler configuration
  param:
    config - the compiler configuration
  throws:
    NullPointerException if config is null

### setParentClassLoader

    public void setParentClassLoader(ClassLoader parentClassLoader)

  param:
    parentClassLoader ClassLoader to be used as the parent ClassLoader for scripts executed by the engine
  deprecated:

Copyright © 2003-2009 The Codehaus. All rights reserved.