org.apache.bsf.util

Class BSFEngineImpl

Implemented Interfaces:
BSFEngine, PropertyChangeListener
Known Direct Subclasses:
JavaScriptEngine, JythonEngine, XSLTEngine

public abstract class BSFEngineImpl
extends java.lang.Object
implements BSFEngine

This is a base implementation of the BSFEngine interface which engine implementations may choose to extend to get the basic methods of the interface implemented.

Authors:
Sanjiva Weerawarana
Olivier Gruber (added original debugging support)

Nested Class Summary

Field Summary

protected ClassLoader
classLoader
protected String
classPath
protected Vector
declaredBeans
protected String
lang
protected BSFManager
mgr
protected String
tempDir

Method Summary

Object
apply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments)
Default impl of apply - calls eval ignoring parameters and returns the result.
void
compileApply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments, CodeBuffer cb)
Default impl of compileApply - calls compileExpr ignoring parameters.
void
compileExpr(String source, int lineNo, int columnNo, Object expr, CodeBuffer cb)
Default impl of compileExpr - generates code that'll create a new manager, evaluate the expression, and return the value.
void
compileScript(String source, int lineNo, int columnNo, Object script, CodeBuffer cb)
Default impl of compileScript - generates code that'll create a new manager, and execute the script.
void
declareBean(BSFDeclaredBean bean)
Declare a bean after the engine has been started.
void
exec(String source, int lineNo, int columnNo, Object script)
Default impl of execute - calls eval and ignores the result.
void
iexec(String source, int lineNo, int columnNo, Object script)
Default impl of interactive execution - calls eval and ignores the result.
void
initialize(BSFManager mgr, String lang, Vector declaredBeans)
initialize the engine; called right after construction by the manager.
void
propertyChange(PropertyChangeEvent e)
Receive property change events from the manager and update my fields as needed.
void
terminate()
Graceful termination
void
undeclareBean(BSFDeclaredBean bean)
Undeclare a previously declared bean.

Field Details

classLoader

protected ClassLoader classLoader


classPath

protected String classPath


declaredBeans

protected Vector declaredBeans


lang

protected String lang


mgr

protected BSFManager mgr


tempDir

protected String tempDir

Method Details

apply

public Object apply(String source,
                    int lineNo,
                    int columnNo,
                    Object funcBody,
                    Vector paramNames,
                    Vector arguments)
            throws BSFException
Default impl of apply - calls eval ignoring parameters and returns the result.
Specified by:
apply in interface BSFEngine


compileApply

public void compileApply(String source,
                         int lineNo,
                         int columnNo,
                         Object funcBody,
                         Vector paramNames,
                         Vector arguments,
                         CodeBuffer cb)
            throws BSFException
Default impl of compileApply - calls compileExpr ignoring parameters.
Specified by:
compileApply in interface BSFEngine


compileExpr

public void compileExpr(String source,
                        int lineNo,
                        int columnNo,
                        Object expr,
                        CodeBuffer cb)
            throws BSFException
Default impl of compileExpr - generates code that'll create a new manager, evaluate the expression, and return the value.
Specified by:
compileExpr in interface BSFEngine


compileScript

public void compileScript(String source,
                          int lineNo,
                          int columnNo,
                          Object script,
                          CodeBuffer cb)
            throws BSFException
Default impl of compileScript - generates code that'll create a new manager, and execute the script.
Specified by:
compileScript in interface BSFEngine


declareBean

public void declareBean(BSFDeclaredBean bean)
            throws BSFException
Declare a bean after the engine has been started. Declared beans are beans that are named and which the engine must make available to the scripts it runs in the most first class way possible.
Specified by:
declareBean in interface BSFEngine

Parameters:
bean - the bean to declare

Throws:
BSFException - if the engine cannot do this operation


exec

public void exec(String source,
                 int lineNo,
                 int columnNo,
                 Object script)
            throws BSFException
Default impl of execute - calls eval and ignores the result.
Specified by:
exec in interface BSFEngine


iexec

public void iexec(String source,
                  int lineNo,
                  int columnNo,
                  Object script)
            throws BSFException
Default impl of interactive execution - calls eval and ignores the result.
Specified by:
iexec in interface BSFEngine


initialize

public void initialize(BSFManager mgr,
                       String lang,
                       Vector declaredBeans)
            throws BSFException
initialize the engine; called right after construction by the manager. Declared beans are simply kept in a vector and that's it. Subclasses must do whatever they want with it.
Specified by:
initialize in interface BSFEngine


propertyChange

public void propertyChange(PropertyChangeEvent e)
Receive property change events from the manager and update my fields as needed.

Parameters:
e - PropertyChange event with the change data


terminate

public void terminate()
Graceful termination
Specified by:
terminate in interface BSFEngine


undeclareBean

public void undeclareBean(BSFDeclaredBean bean)
            throws BSFException
Undeclare a previously declared bean.
Specified by:
undeclareBean in interface BSFEngine

Parameters:
bean - the bean to undeclare

Throws:
BSFException - if the engine cannot do this operation