org.norther.tammi.core.scripter.groovy
Class GroovyInterpreter

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by org.norther.tammi.core.scripter.groovy.GroovyInterpreter
All Implemented Interfaces:
GroovyObject, Interpreter

public class GroovyInterpreter
extends GroovyObjectSupport
implements Interpreter

A Groovy interpreter.

Version:
$Id: GroovyInterpreter.java,v 1.14 2009/11/04 18:04:01 cvsimp Exp $
Author:
Ilkka Priha

Field Summary
 
Fields inherited from interface org.norther.tammi.core.scripter.lang.Interpreter
JAVA_LANGUAGE
 
Constructor Summary
GroovyInterpreter()
          Constructs a new interpreter.
GroovyInterpreter(Binding context)
          Constructs a new interpreter with a context.
GroovyInterpreter(ClassLoader loader)
          Constructs a new interpreter with a class loader.
GroovyInterpreter(ClassLoader loader, Binding context)
          Constructs a new interpreter with a class loader and context.
GroovyInterpreter(GroovyInterpreter interpreter)
          Constructs a new child interpreter.
 
Method Summary
 void addClassPath(String path)
          Adds a class search path.
 void addClassURL(URL url)
          Adds a class search URL.
 Class<?> defineClass(String name, byte[] code)
          Converts an array of bytes into a class.
 void defineVariable(String name, Object value)
          Defines a variable in the interpreter environment.
 void defineVariable(String name, Object value, Class<?> c)
          Defines a variable of the specified class.
 ClassLoader getClassLoader()
          Gets the class loader.
 Set<String> getClassNames()
          Gets the defined class names.
 Binding getContext()
          Gets the context.
 String getEncoding()
          Gets the encoding.
 Object getVariable(String name)
          Gets the value of a variable.
 Class<?> getVariableClass(String name)
          Gets the class of a variable.
 Set<String> getVariableNames()
          Gets the defined variable names.
 Object interpret(File file)
          Interprets a file.
 Object interpret(GroovyObject object)
          Interprets a groovy object.
 Object interpret(InputStream in, String fname)
          Interprets an input stream.
 Object interpret(Reader r, String fname)
          Interprets a reader.
 Object interpret(String s, String fname)
          Interprets a string.
 Object interpret(URL url)
          Interprets a URL.
 boolean isDefined(String name)
          Checks whether a variable is defined.
 Class<?> loadClass(String name)
          Loads an interpreted class.
 GroovyObject parseGroovyObject(File file)
          Parses a groovy object from a file.
 GroovyObject parseGroovyObject(InputStream in, String fname)
          Parses a groovy object from a stream.
 GroovyObject parseGroovyObject(URL url)
          Parses a groovy object from a URL.
 void reset()
          Resets this interpreter.
 void setVariable(String name, Object value)
          Sets the value of a variable.
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroovyInterpreter

public GroovyInterpreter()
Constructs a new interpreter.


GroovyInterpreter

public GroovyInterpreter(Binding context)
Constructs a new interpreter with a context.

Parameters:
context - the context.

GroovyInterpreter

public GroovyInterpreter(ClassLoader loader)
Constructs a new interpreter with a class loader.

Parameters:
loader - the parent class loader.

GroovyInterpreter

public GroovyInterpreter(ClassLoader loader,
                         Binding context)
Constructs a new interpreter with a class loader and context.

Parameters:
loader - the class loader.
context - the context.

GroovyInterpreter

public GroovyInterpreter(GroovyInterpreter interpreter)
Constructs a new child interpreter.

Parameters:
interpreter - the parent interpreter.
Method Detail

interpret

public Object interpret(String s,
                        String fname)
Description copied from interface: Interpreter
Interprets a string.

Specified by:
interpret in interface Interpreter
Parameters:
s - the string from which the statements are read.
fname - the name of the parsed string.
Returns:
the result of the evaluation of the last statement.

interpret

public Object interpret(InputStream in,
                        String fname)
Description copied from interface: Interpreter
Interprets an input stream.

Specified by:
interpret in interface Interpreter
Parameters:
in - the input stream from which the statements are read.
fname - the name of the parsed stream.
Returns:
the result of the evaluation of the last statement.

interpret

public Object interpret(Reader r,
                        String fname)
Description copied from interface: Interpreter
Interprets a reader.

Specified by:
interpret in interface Interpreter
Parameters:
r - the reader.
fname - the name of the parsed stream.
Returns:
the result of the evaluation of the last statement.

interpret

public Object interpret(File file)
                 throws IOException
Description copied from interface: Interpreter
Interprets a file.

Specified by:
interpret in interface Interpreter
Parameters:
file - the file to interpret.
Returns:
the result of the evaluation of the last statement.
Throws:
IOException - on I/O errors.

interpret

public Object interpret(URL url)
                 throws IOException
Description copied from interface: Interpreter
Interprets a URL.

Specified by:
interpret in interface Interpreter
Parameters:
url - the url to interpret.
Returns:
the result of the evaluation of the last statement.
Throws:
IOException - on I/O errors.

defineVariable

public void defineVariable(String name,
                           Object value)
Description copied from interface: Interpreter
Defines a variable in the interpreter environment.

Specified by:
defineVariable in interface Interpreter
Parameters:
name - the variable's name.
value - the initial value of the variable.

defineVariable

public void defineVariable(String name,
                           Object value,
                           Class<?> c)
Description copied from interface: Interpreter
Defines a variable of the specified class.

Specified by:
defineVariable in interface Interpreter
Parameters:
name - the name.
value - the value.
c - the class.

isDefined

public boolean isDefined(String name)
Description copied from interface: Interpreter
Checks whether a variable is defined.

Specified by:
isDefined in interface Interpreter
Parameters:
name - the name.
Returns:
true if defined, false otherwise.

getVariable

public Object getVariable(String name)
Description copied from interface: Interpreter
Gets the value of a variable.

Specified by:
getVariable in interface Interpreter
Parameters:
name - the variable name.
Returns:
the variable value.

setVariable

public void setVariable(String name,
                        Object value)
Description copied from interface: Interpreter
Sets the value of a variable.

Specified by:
setVariable in interface Interpreter
Parameters:
name - the variable name.
value - the value of the variable.

getVariableClass

public Class<?> getVariableClass(String name)
Description copied from interface: Interpreter
Gets the class of a variable.

Specified by:
getVariableClass in interface Interpreter
Parameters:
name - the variable name.
Returns:
the variable class.

getVariableNames

public Set<String> getVariableNames()
Description copied from interface: Interpreter
Gets the defined variable names.

Specified by:
getVariableNames in interface Interpreter
Returns:
a set of strings.

reset

public void reset()
Description copied from interface: Interpreter
Resets this interpreter.

Specified by:
reset in interface Interpreter

addClassPath

public void addClassPath(String path)
Description copied from interface: Interpreter
Adds a class search path.

Specified by:
addClassPath in interface Interpreter
Parameters:
path - the path to add.

addClassURL

public void addClassURL(URL url)
Description copied from interface: Interpreter
Adds a class search URL.

Specified by:
addClassURL in interface Interpreter
Parameters:
url - the url to add.

loadClass

public Class<?> loadClass(String name)
                   throws ClassNotFoundException
Description copied from interface: Interpreter
Loads an interpreted class.

Specified by:
loadClass in interface Interpreter
Parameters:
name - the fully qualified name of the class to load.
Returns:
the loaded class.
Throws:
ClassNotFoundException - if the class cannot be find.

defineClass

public Class<?> defineClass(String name,
                            byte[] code)
Description copied from interface: Interpreter
Converts an array of bytes into a class.

Specified by:
defineClass in interface Interpreter
Parameters:
name - the fully qualified name of the class to load.
code - the byte code of the class.
Returns:
the defined class.

getClassNames

public Set<String> getClassNames()
Description copied from interface: Interpreter
Gets the defined class names.

Specified by:
getClassNames in interface Interpreter
Returns:
a set of strings.

getClassLoader

public ClassLoader getClassLoader()
Description copied from interface: Interpreter
Gets the class loader.

Specified by:
getClassLoader in interface Interpreter
Returns:
the class loader.

interpret

public Object interpret(GroovyObject object)
Interprets a groovy object.

Parameters:
object - the parsed object.
Returns:
the result of the evaluation of the last statement.
Throws:
Error - if interpretation fails.

getContext

public Binding getContext()
Gets the context.

Returns:
the context.

getEncoding

public String getEncoding()
Gets the encoding.

Returns:
the encoding.

parseGroovyObject

public GroovyObject parseGroovyObject(File file)
                               throws IllegalAccessException,
                                      InstantiationException,
                                      PrivilegedActionException
Parses a groovy object from a file.

Parameters:
file - the file.
Returns:
the parsed object.
Throws:
IllegalAccessException - if no default constructor.
InstantiationException - if instantiation fails.
PrivilegedActionException - if file not found.

parseGroovyObject

public GroovyObject parseGroovyObject(URL url)
                               throws IllegalAccessException,
                                      InstantiationException,
                                      PrivilegedActionException
Parses a groovy object from a URL.

Parameters:
url - the URL.
Returns:
the parsed object.
Throws:
IllegalAccessException - if no default constructor.
InstantiationException - if instantiation fails.
PrivilegedActionException - if URL not available.

parseGroovyObject

public GroovyObject parseGroovyObject(InputStream in,
                                      String fname)
                               throws IllegalAccessException,
                                      InstantiationException
Parses a groovy object from a stream.

Parameters:
in - the input stream.
fname - the file name.
Returns:
the parsed object.
Throws:
IllegalAccessException - if no default constructor.
InstantiationException - if instantiation fails.


Copyright © 2004 The Norther Organization. All rights reserved.