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

java.lang.Object
  extended by org.norther.tammi.core.scripter.lang.EngineInterpreter
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, org.apache.bsf.BSFEngine, Interpreter

public class EngineInterpreter
extends Object
implements org.apache.bsf.BSFEngine, Interpreter, Serializable

An interpreter adapter for BSF engines.

Version:
$Id: EngineInterpreter.java,v 1.6 2009/09/28 15:08:46 cvsimp Exp $
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.
 Object apply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments)
           
 Object call(Object object, String name, Object[] args)
           
 void compileApply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments, org.apache.bsf.util.CodeBuffer cb)
           
 void compileExpr(String source, int lineNo, int columnNo, Object expr, org.apache.bsf.util.CodeBuffer cb)
           
 void compileScript(String source, int lineNo, int columnNo, Object script, org.apache.bsf.util.CodeBuffer cb)
           
 void declareBean(org.apache.bsf.BSFDeclaredBean bean)
           
 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.
 Object eval(String source, int lineNo, int columnNo, Object expr)
           
 void exec(String source, int lineNo, int columnNo, Object script)
           
 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.
 void iexec(String source, int lineNo, int columnNo, Object script)
           
 void initialize(org.apache.bsf.BSFManager mgr, String lang, Vector declaredBeans)
           
 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 propertyChange(PropertyChangeEvent evt)
           
 void reset()
          Resets this interpreter.
 void setVariable(String name, Object value)
          Sets the value of a variable.
 void terminate()
           
 void undeclareBean(org.apache.bsf.BSFDeclaredBean bean)
           
 
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

apply

public Object apply(String source,
                    int lineNo,
                    int columnNo,
                    Object funcBody,
                    Vector paramNames,
                    Vector arguments)
             throws org.apache.bsf.BSFException
Specified by:
apply in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

call

public Object call(Object object,
                   String name,
                   Object[] args)
            throws org.apache.bsf.BSFException
Specified by:
call in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

compileApply

public void compileApply(String source,
                         int lineNo,
                         int columnNo,
                         Object funcBody,
                         Vector paramNames,
                         Vector arguments,
                         org.apache.bsf.util.CodeBuffer cb)
                  throws org.apache.bsf.BSFException
Specified by:
compileApply in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

compileExpr

public void compileExpr(String source,
                        int lineNo,
                        int columnNo,
                        Object expr,
                        org.apache.bsf.util.CodeBuffer cb)
                 throws org.apache.bsf.BSFException
Specified by:
compileExpr in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

compileScript

public void compileScript(String source,
                          int lineNo,
                          int columnNo,
                          Object script,
                          org.apache.bsf.util.CodeBuffer cb)
                   throws org.apache.bsf.BSFException
Specified by:
compileScript in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

declareBean

public void declareBean(org.apache.bsf.BSFDeclaredBean bean)
                 throws org.apache.bsf.BSFException
Specified by:
declareBean in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

eval

public Object eval(String source,
                   int lineNo,
                   int columnNo,
                   Object expr)
            throws org.apache.bsf.BSFException
Specified by:
eval in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

exec

public void exec(String source,
                 int lineNo,
                 int columnNo,
                 Object script)
          throws org.apache.bsf.BSFException
Specified by:
exec in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

iexec

public void iexec(String source,
                  int lineNo,
                  int columnNo,
                  Object script)
           throws org.apache.bsf.BSFException
Specified by:
iexec in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

initialize

public void initialize(org.apache.bsf.BSFManager mgr,
                       String lang,
                       Vector declaredBeans)
                throws org.apache.bsf.BSFException
Specified by:
initialize in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

terminate

public void terminate()
Specified by:
terminate in interface org.apache.bsf.BSFEngine

undeclareBean

public void undeclareBean(org.apache.bsf.BSFDeclaredBean bean)
                   throws org.apache.bsf.BSFException
Specified by:
undeclareBean in interface org.apache.bsf.BSFEngine
Throws:
org.apache.bsf.BSFException

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