org.norther.tammi.core.scripter.lang
Interface Interpreter

All Known Implementing Classes:
AbstractInterpreter, DJavaEngine, EngineInterpreter, GroovyEngine, GroovyInterpreter

public interface Interpreter

An interface to language interpreters.

Version:
$Id: Interpreter.java,v 1.11 2009/09/28 15:08:46 cvsimp Exp $
Author:
Ilkka Priha

Field Summary
static String JAVA_LANGUAGE
          The java language.
 
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.
 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(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.
 void reset()
          Resets this interpreter.
 void setVariable(String name, Object value)
          Sets the value of a variable.
 

Field Detail

JAVA_LANGUAGE

static final String JAVA_LANGUAGE
The java language.

See Also:
Constant Field Values
Method Detail

interpret

Object interpret(String s,
                 String fname)
Interprets a string.

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.
Throws:
Error - if interpretation fails.

interpret

Object interpret(InputStream in,
                 String fname)
Interprets an input stream.

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.
Throws:
Error - if interpretation fails.

interpret

Object interpret(Reader r,
                 String fname)
Interprets a reader.

Parameters:
r - the reader.
fname - the name of the parsed stream.
Returns:
the result of the evaluation of the last statement.
Throws:
Error - if interpretation fails.

interpret

Object interpret(File file)
                 throws IOException
Interprets a file.

Parameters:
file - the file to interpret.
Returns:
the result of the evaluation of the last statement.
Throws:
Error - if interpretation fails.
IOException - on I/O errors.

interpret

Object interpret(URL url)
                 throws IOException
Interprets a URL.

Parameters:
url - the url to interpret.
Returns:
the result of the evaluation of the last statement.
Throws:
Error - if interpretation fails.
IOException - on I/O errors.

defineVariable

void defineVariable(String name,
                    Object value)
Defines a variable in the interpreter environment.

Parameters:
name - the variable's name.
value - the initial value of the variable.
Throws:
IllegalStateException - if name is already defined.

defineVariable

void defineVariable(String name,
                    Object value,
                    Class<?> c)
Defines a variable of the specified class.

Parameters:
name - the name.
value - the value.
c - the class.

isDefined

boolean isDefined(String name)
Checks whether a variable is defined.

Parameters:
name - the name.
Returns:
true if defined, false otherwise.

getVariable

Object getVariable(String name)
Gets the value of a variable.

Parameters:
name - the variable name.
Returns:
the variable value.
Throws:
IllegalStateException - if the variable does not exist.

setVariable

void setVariable(String name,
                 Object value)
Sets the value of a variable.

Parameters:
name - the variable name.
value - the value of the variable.
Throws:
IllegalStateException - if the assignment is invalid.

getVariableClass

Class<?> getVariableClass(String name)
Gets the class of a variable.

Parameters:
name - the variable name.
Returns:
the variable class.
Throws:
IllegalStateException - if the variable does not exist.

getVariableNames

Set<String> getVariableNames()
Gets the defined variable names.

Returns:
a set of strings.

addClassPath

void addClassPath(String path)
Adds a class search path.

Parameters:
path - the path to add.

addClassURL

void addClassURL(URL url)
Adds a class search URL.

Parameters:
url - the url to add.

loadClass

Class<?> loadClass(String name)
                   throws ClassNotFoundException
Loads an interpreted class.

Parameters:
name - the fully qualified name of the class to load.
Returns:
the loaded class.
Throws:
ClassNotFoundException - if the class cannot be find.

defineClass

Class<?> defineClass(String name,
                     byte[] code)
Converts an array of bytes into a class.

Parameters:
name - the fully qualified name of the class to load.
code - the byte code of the class.
Returns:
the defined class.
Throws:
ClassFormatError - if the class could not be defined.

getClassNames

Set<String> getClassNames()
Gets the defined class names.

Returns:
a set of strings.

getClassLoader

ClassLoader getClassLoader()
Gets the class loader.

Returns:
the class loader.

reset

void reset()
Resets this interpreter.



Copyright © 2004 The Norther Organization. All rights reserved.