org.apache.bsf.util
Class BSFEngineImpl

java.lang.Object
  extended by org.apache.bsf.util.BSFEngineImpl
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, BSFEngine
Direct Known Subclasses:
ActiveScriptEngine, JaclEngine, JavaClassEngine, JavaScriptEngine, JPythonEngine, JythonEngine, NetRexxEngine, 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.

Author:
Sanjiva Weerawarana, Olivier Gruber (adding debugging support)

Field Summary
protected  java.lang.ClassLoader classLoader
           
protected  java.lang.String classPath
           
protected  BSFDebugManagerImpl dbgmgr
           
protected  java.util.Vector declaredBeans
           
protected  java.lang.String lang
           
protected  BSFManager mgr
           
protected  java.lang.String tempDir
           
 
Constructor Summary
BSFEngineImpl()
          Get the debug manager in the constructor, not in initialize.
 
Method Summary
 java.lang.Object apply(java.lang.String source, int lineNo, int columnNo, java.lang.Object funcBody, java.util.Vector paramNames, java.util.Vector arguments)
          Default impl of apply - calls eval ignorning parameters and returns the result.
 void compileApply(java.lang.String source, int lineNo, int columnNo, java.lang.Object funcBody, java.util.Vector paramNames, java.util.Vector arguments, CodeBuffer cb)
          Default impl of compileApply - calls compileExpr ignorning parameters.
 void compileExpr(java.lang.String source, int lineNo, int columnNo, java.lang.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(java.lang.String source, int lineNo, int columnNo, java.lang.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 disconnectedDebuggerNotify()
          Basic engines are not supporting breakpoints for the meaning and support is something that is language-specific.
 void exec(java.lang.String source, int lineNo, int columnNo, java.lang.Object script)
          Default impl of execute - calls eval and ignores the result.
 java.lang.Object getSpecificDebuggingInterface()
          By default, an engine does not support debugging.
 void initialize(BSFManager mgr, java.lang.String lang, java.util.Vector declaredBeans)
          initialize the engine; called right after construction by the manager.
 void placeBreakpointAtLine(int brkptid, java.lang.String docname, int lineno)
           
 void placeBreakpointAtOffset(int brkptid, java.lang.String docname, int offset)
           
 void propertyChange(java.beans.PropertyChangeEvent e)
          Receive property change events from the manager and update my fields as needed.
 void removeBreakpoint(java.lang.String docname, int brkptid)
           
 void setEntryExit(java.lang.String docname, boolean on)
           
 void terminate()
          Graceful termination
 void undeclareBean(BSFDeclaredBean bean)
          Undeclare a previously declared bean.
 
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
call, eval
 

Field Detail

mgr

protected BSFManager mgr

dbgmgr

protected BSFDebugManagerImpl dbgmgr

lang

protected java.lang.String lang

declaredBeans

protected java.util.Vector declaredBeans

classPath

protected java.lang.String classPath

tempDir

protected java.lang.String tempDir

classLoader

protected java.lang.ClassLoader classLoader
Constructor Detail

BSFEngineImpl

public BSFEngineImpl()
Get the debug manager in the constructor, not in initialize. First, this is ok since the debug manager is not BSFManager dependent. Second, the debug manager needs to be known sooner than "initialize" for the JavaScript engine.

Method Detail

getSpecificDebuggingInterface

public java.lang.Object getSpecificDebuggingInterface()
By default, an engine does not support debugging. Subclasses will need to redefine this method in order to provide debuggers with their language-specific interface for debugging.

Specified by:
getSpecificDebuggingInterface in interface BSFEngine

disconnectedDebuggerNotify

public void disconnectedDebuggerNotify()
Basic engines are not supporting breakpoints for the meaning and support is something that is language-specific.

Specified by:
disconnectedDebuggerNotify in interface BSFEngine

placeBreakpointAtLine

public void placeBreakpointAtLine(int brkptid,
                                  java.lang.String docname,
                                  int lineno)
                           throws BSFException
Specified by:
placeBreakpointAtLine in interface BSFEngine
Throws:
BSFException

placeBreakpointAtOffset

public void placeBreakpointAtOffset(int brkptid,
                                    java.lang.String docname,
                                    int offset)
                             throws BSFException
Specified by:
placeBreakpointAtOffset in interface BSFEngine
Throws:
BSFException

removeBreakpoint

public void removeBreakpoint(java.lang.String docname,
                             int brkptid)
                      throws BSFException
Specified by:
removeBreakpoint in interface BSFEngine
Throws:
BSFException

setEntryExit

public void setEntryExit(java.lang.String docname,
                         boolean on)
                  throws BSFException
Specified by:
setEntryExit in interface BSFEngine
Throws:
BSFException

apply

public java.lang.Object apply(java.lang.String source,
                              int lineNo,
                              int columnNo,
                              java.lang.Object funcBody,
                              java.util.Vector paramNames,
                              java.util.Vector arguments)
                       throws BSFException
Default impl of apply - calls eval ignorning parameters and returns the result.

Specified by:
apply in interface BSFEngine
Parameters:
source - (context info) the source of this expression (e.g., filename)
lineNo - (context info) the line number in source for expr
columnNo - (context info) the column number in source for expr
funcBody - the multi-line, value returning script to evaluate
paramNames - the names of the parameters above assumes
arguments - values of the above parameters
Throws:
BSFException - if anything goes wrong while doin' it.

compileApply

public void compileApply(java.lang.String source,
                         int lineNo,
                         int columnNo,
                         java.lang.Object funcBody,
                         java.util.Vector paramNames,
                         java.util.Vector arguments,
                         CodeBuffer cb)
                  throws BSFException
Default impl of compileApply - calls compileExpr ignorning parameters.

Specified by:
compileApply in interface BSFEngine
Parameters:
source - (context info) the source of this expression (e.g., filename)
lineNo - (context info) the line number in source for expr
columnNo - (context info) the column number in source for expr
funcBody - the multi-line, value returning script to evaluate
paramNames - the names of the parameters above assumes
arguments - values of the above parameters
cb - the CodeBuffer to compile into
Throws:
BSFException - if anything goes wrong while doin' it.

compileExpr

public void compileExpr(java.lang.String source,
                        int lineNo,
                        int columnNo,
                        java.lang.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
Parameters:
source - (context info) the source of this expression (e.g., filename)
lineNo - (context info) the line number in source for expr
columnNo - (context info) the column number in source for expr
expr - the expression to compile
cb - the CodeBuffer to compile into
Throws:
BSFException - if anything goes wrong while compiling a BSFException is thrown. The reason indicates the problem.

compileScript

public void compileScript(java.lang.String source,
                          int lineNo,
                          int columnNo,
                          java.lang.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
Parameters:
source - (context info) the source of this script (e.g., filename)
lineNo - (context info) the line number in source for script
columnNo - (context info) the column number in source for script
script - the script to compile
cb - the CodeBuffer to compile into
Throws:
BSFException - if anything goes wrong while compiling a BSFException is thrown. The reason indicates the problem.

declareBean

public void declareBean(BSFDeclaredBean bean)
                 throws BSFException
Description copied from interface: BSFEngine
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(java.lang.String source,
                 int lineNo,
                 int columnNo,
                 java.lang.Object script)
          throws BSFException
Default impl of execute - calls eval and ignores the result.

Specified by:
exec in interface BSFEngine
Parameters:
source - (context info) the source of this expression (e.g., filename)
lineNo - (context info) the line number in source for expr
columnNo - (context info) the column number in source for expr
script - the script to execute
Throws:
BSFException - if anything goes wrong while exec'ing a BSFException is thrown. The reason indicates the problem.

initialize

public void initialize(BSFManager mgr,
                       java.lang.String lang,
                       java.util.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
Parameters:
mgr - The BSFManager that's hosting this engine.
lang - Language string which this engine is handling.
declaredBeans - Vector of BSFDeclaredObject containing beans that should be declared into the language runtime at init time as best as possible.
Throws:
BSFException - if anything goes wrong while init'ing a BSFException is thrown. The reason indicates the problem.

propertyChange

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

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - PropertyChange event with the change data

terminate

public void terminate()
Description copied from interface: BSFEngine
Graceful termination

Specified by:
terminate in interface BSFEngine

undeclareBean

public void undeclareBean(BSFDeclaredBean bean)
                   throws BSFException
Description copied from interface: BSFEngine
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