Package org.apache.bsf.util
Class BSFEngineImpl
java.lang.Object
org.apache.bsf.util.BSFEngineImpl
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,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 (added original debugging support)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ClassLoader
protected String
protected Vector
protected String
protected BSFManager
protected String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply
(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
Default impl of execute - calls eval and ignores the result.void
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
Receive property change events from the manager and update my fields as needed.void
Graceful terminationvoid
undeclareBean
(BSFDeclaredBean bean) Undeclare a previously declared bean.
-
Field Details
-
mgr
-
lang
-
declaredBeans
-
classPath
-
tempDir
-
classLoader
-
-
Constructor Details
-
BSFEngineImpl
public BSFEngineImpl()
-
-
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 interfaceBSFEngine
- Parameters:
source
- (context info) the source of this expression (e.g., filename)lineNo
- (context info) the line number in source for exprcolumnNo
- (context info) the column number in source for exprfuncBody
- the multi-line, value returning script to evaluateparamNames
- the names of the parameters above assumesarguments
- values of the above parameters- Throws:
BSFException
- if anything goes wrong while doin' it.
-
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 interfaceBSFEngine
- Parameters:
source
- (context info) the source of this expression (e.g., filename)lineNo
- (context info) the line number in source for exprcolumnNo
- (context info) the column number in source for exprfuncBody
- the multi-line, value returning script to evaluateparamNames
- the names of the parameters above assumesarguments
- values of the above parameterscb
- the CodeBuffer to compile into- Throws:
BSFException
- if anything goes wrong while doin' it.
-
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 interfaceBSFEngine
- Parameters:
source
- (context info) the source of this expression (e.g., filename)lineNo
- (context info) the line number in source for exprcolumnNo
- (context info) the column number in source for exprexpr
- the expression to compilecb
- 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(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 interfaceBSFEngine
- Parameters:
source
- (context info) the source of this script (e.g., filename)lineNo
- (context info) the line number in source for scriptcolumnNo
- (context info) the column number in source for scriptscript
- the script to compilecb
- the CodeBuffer to compile into- Throws:
BSFException
- if anything goes wrong while compiling a BSFException is thrown. The reason indicates the problem.
-
declareBean
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 interfaceBSFEngine
- Parameters:
bean
- the bean to declare- Throws:
BSFException
- if the engine cannot do this operation
-
exec
Default impl of execute - calls eval and ignores the result.- Specified by:
exec
in interfaceBSFEngine
- Parameters:
source
- (context info) the source of this expression (e.g., filename)lineNo
- (context info) the line number in source for exprcolumnNo
- (context info) the column number in source for exprscript
- the script to execute- Throws:
BSFException
- if anything goes wrong while exec'ing a BSFException is thrown. The reason indicates the problem.
-
iexec
Default impl of interactive execution - calls eval and ignores the result.- Specified by:
iexec
in interfaceBSFEngine
- Parameters:
source
- (context info) the source of this expression (e.g., filename)lineNo
- (context info) the line number in source for exprcolumnNo
- (context info) the column number in source for exprscript
- the script to execute- Throws:
BSFException
- if anything goes wrong while exec'ing a BSFException is thrown. The reason indicates the problem.
-
initialize
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 interfaceBSFEngine
- 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
Receive property change events from the manager and update my fields as needed.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- PropertyChange event with the change data
-
terminate
public void terminate()Description copied from interface:BSFEngine
Graceful termination -
undeclareBean
Description copied from interface:BSFEngine
Undeclare a previously declared bean.- Specified by:
undeclareBean
in interfaceBSFEngine
- Parameters:
bean
- the bean to undeclare- Throws:
BSFException
- if the engine cannot do this operation
-