org.norther.tammi.core.scripter.lang
Class EngineInterpreter

java.lang.Object
  extended by org.norther.tammi.core.scripter.lang.EngineInterpreter
All Implemented Interfaces:
Serializable, Interpreter

public class EngineInterpreter
extends Object
implements Interpreter, Serializable

An interpreter adapter for BSF engines.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.norther.tammi.core.scripter.lang.Interpreter
JAVA_LANGUAGE
 
Constructor Summary
EngineInterpreter(String lang, org.apache.bsf.BSFEngine adaptee)
          Construcs a new adapter.
 
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 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EngineInterpreter

public EngineInterpreter(String lang,
                         org.apache.bsf.BSFEngine adaptee)
Construcs a new adapter.

Parameters:
lang - the language.
adaptee - the engine adaptee.
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 getVariableNames()
Description copied from interface: Interpreter
Gets the defined variable names.

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

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 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.

reset

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

Specified by:
reset in interface Interpreter


Copyright © 2004 The Norther Organization. All rights reserved.