Package org.apache.bsf.util
Class BSFEngineImpl
- java.lang.Object
-
- org.apache.bsf.util.BSFEngineImpl
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener,BSFEngine
- Direct Known Subclasses:
JavaScriptEngine,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 (added original debugging support)
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoaderclassLoaderprotected java.lang.StringclassPathprotected java.util.VectordeclaredBeansprotected java.lang.Stringlangprotected BSFManagermgrprotected java.lang.StringtempDir
-
Constructor Summary
Constructors Constructor Description BSFEngineImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectapply(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 ignoring parameters and returns the result.voidcompileApply(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 ignoring parameters.voidcompileExpr(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.voidcompileScript(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.voiddeclareBean(BSFDeclaredBean bean)Declare a bean after the engine has been started.voidexec(java.lang.String source, int lineNo, int columnNo, java.lang.Object script)Default impl of execute - calls eval and ignores the result.voidiexec(java.lang.String source, int lineNo, int columnNo, java.lang.Object script)Default impl of interactive execution - calls eval and ignores the result.voidinitialize(BSFManager mgr, java.lang.String lang, java.util.Vector declaredBeans)initialize the engine; called right after construction by the manager.voidpropertyChange(java.beans.PropertyChangeEvent e)Receive property change events from the manager and update my fields as needed.voidterminate()Graceful terminationvoidundeclareBean(BSFDeclaredBean bean)Undeclare a previously declared bean.
-
-
-
Field Detail
-
mgr
protected BSFManager mgr
-
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
-
-
Method Detail
-
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 BSFExceptionDefault impl of apply - calls eval ignoring parameters and returns the result.- Specified by:
applyin 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(java.lang.String source, int lineNo, int columnNo, java.lang.Object funcBody, java.util.Vector paramNames, java.util.Vector arguments, CodeBuffer cb) throws BSFExceptionDefault impl of compileApply - calls compileExpr ignoring parameters.- Specified by:
compileApplyin 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(java.lang.String source, int lineNo, int columnNo, java.lang.Object expr, CodeBuffer cb) throws BSFExceptionDefault impl of compileExpr - generates code that'll create a new manager, evaluate the expression, and return the value.- Specified by:
compileExprin 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(java.lang.String source, int lineNo, int columnNo, java.lang.Object script, CodeBuffer cb) throws BSFExceptionDefault impl of compileScript - generates code that'll create a new manager, and execute the script.- Specified by:
compileScriptin 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
public void declareBean(BSFDeclaredBean bean) throws BSFException
Description copied from interface:BSFEngineDeclare 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:
declareBeanin interfaceBSFEngine- 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 BSFExceptionDefault impl of execute - calls eval and ignores the result.- Specified by:
execin 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
public void iexec(java.lang.String source, int lineNo, int columnNo, java.lang.Object script) throws BSFExceptionDefault impl of interactive execution - calls eval and ignores the result.- Specified by:
iexecin 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
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:
initializein 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
public void propertyChange(java.beans.PropertyChangeEvent e)
Receive property change events from the manager and update my fields as needed.- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener- Parameters:
e- PropertyChange event with the change data
-
terminate
public void terminate()
Description copied from interface:BSFEngineGraceful termination
-
undeclareBean
public void undeclareBean(BSFDeclaredBean bean) throws BSFException
Description copied from interface:BSFEngineUndeclare a previously declared bean.- Specified by:
undeclareBeanin interfaceBSFEngine- Parameters:
bean- the bean to undeclare- Throws:
BSFException- if the engine cannot do this operation
-
-