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

java.lang.Object
  extended by org.norther.tammi.core.scripter.lang.AbstractEngine
      extended by org.norther.tammi.core.scripter.lang.AbstractInterpreter
All Implemented Interfaces:
PropertyChangeListener, EventListener, org.apache.bsf.BSFEngine, Interpreter, ScriptEngine
Direct Known Subclasses:
DJavaEngine, GroovyEngine

public abstract class AbstractInterpreter
extends AbstractEngine
implements Interpreter

An abstract interpreter adapter for BSF engines.

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

Field Summary
 
Fields inherited from interface org.norther.tammi.core.scripter.lang.Interpreter
JAVA_LANGUAGE
 
Fields inherited from interface org.norther.tammi.core.scripter.lang.ScriptEngine
APPLY, ARGUMENTS, EVALUATE, EXECUTE, MAIN
 
Constructor Summary
AbstractInterpreter()
          Constructs a new 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.
protected abstract  Interpreter getInterpreter()
          Gets the adapted interpreter.
 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.
 
Methods inherited from class org.norther.tammi.core.scripter.lang.AbstractEngine
compileApply, compileExpr, compileScript, exec, getClassPath, getDeclaredBeans, getInitializer, getLanguage, getTempDirectory, iexec, initialize, isInitialized, propertyChange, reinitialize, setClassLoader, setClassPath, setInitializer, setTempDirectory, terminate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.bsf.BSFEngine
apply, call, declareBean, eval, undeclareBean
 

Constructor Detail

AbstractInterpreter

public AbstractInterpreter()
Constructs a new 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.

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 class: AbstractEngine
Gets the class loader.

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

reset

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

Specified by:
reset in interface Interpreter

getInterpreter

protected abstract Interpreter getInterpreter()
Gets the adapted interpreter.

Returns:
the interpreter.


Copyright © 2004 The Norther Organization. All rights reserved.