org.apache.bsf.engines.activescript

Class ActiveScriptEngine

Implemented Interfaces:
BSFEngine, JavaBeanAddEventListener, PropertyChangeListener

public class ActiveScriptEngine
extends BSFEngineImpl
implements JavaBeanAddEventListener

This is the interface to active scripting engines from the Bean Scripting Framework. This code uses John Ponzo's IBM Active Scripting Toolkit to tie in active scripting engines to BSF. This class implements Runnable to create a thread. This thread is to exclusively access the scripting engine. All methods from this class to the engines is proxied over to the engine thread for execution. Why? Because, MS engines are implemented to only be accessed from ONE thread.

Author:
Sanjiva Weerawarana

Field Summary

protected String
lang

Fields inherited from class org.apache.bsf.util.BSFEngineImpl

classLoader, classPath, dbgmgr, declaredBeans, lang, mgr, tempDir

Method Summary

void
addEventListener(Object bean, String event, String filter, String script)
add an event listener
int
bindMember(Object target, String name, short bindType)
Binds a method to an integer so it can be later referenced to invoke the method via callMethod.
Object
call(Object object, String method, Object[] args)
Return an object from an extension.
Object
callMethod(Object bean, int methodID, Object[] args)
Invokes the method assocaited with methodID on the bean with parameters in the array args.
static Throwable
createBSFException(int reason, String msg, Throwable t)
Object
createBean(Object[] args)
createBean
void
declareBean(BSFDeclaredBean bean)
Declare a bean after the engine has been started.
Object
eval(String source, int lineNo, int columnNo, Object oscript)
This is used by an application to evaluate a string containing some expression.
void
exec(String source, int lineNo, int columnNo, Object script)
This is used by an application to execute a string containing a script to execute.
protected void
finalize()
void
initialize(BSFManager mgr, String language, Vector declaredBeans)
initialize the engine; called right after construction by the manager.
protected boolean
isCaseSensitive()
protected boolean
isJScript()
protected boolean
isPerlScript()
protected boolean
isVBScript()
Object
lookupBean(String name)
lookupBean
void
setEvalRet(Object ret)
void
terminate()
Graceful termination
void
undeclareBean(BSFDeclaredBean bean)
Undeclare a previously declared bean.

Methods inherited from class org.apache.bsf.util.BSFEngineImpl

apply, compileApply, compileExpr, compileScript, declareBean, disconnectedDebuggerNotify, exec, getSpecificDebuggingInterface, initialize, placeBreakpointAtLine, placeBreakpointAtOffset, propertyChange, removeBreakpoint, setEntryExit, terminate, undeclareBean

Field Details

lang

protected String lang

Method Details

addEventListener

public void addEventListener(Object bean,
                             String event,
                             String filter,
                             String script)
            throws BSFException
add an event listener
Specified by:
addEventListener in interface JavaBeanAddEventListener


bindMember

public final int bindMember(Object target,
                            String name,
                            short bindType)
            throws Exception
Binds a method to an integer so it can be later referenced to invoke the method via callMethod.


call

public Object call(Object object,
                   String method,
                   Object[] args)
            throws BSFException
Return an object from an extension.
Specified by:
call in interface BSFEngine

Parameters:
method - The name of the method to call.
args - an array of arguments to be passed to the extension, which may be either Vectors of Nodes, or Strings.


callMethod

public final Object callMethod(Object bean,
                               int methodID,
                               Object[] args)
            throws Exception
Invokes the method assocaited with methodID on the bean with parameters in the array args.


createBSFException

public static final Throwable createBSFException(int reason,
                                                 String msg,
                                                 Throwable t)


createBean

public final Object createBean(Object[] args)
            throws BSFException
createBean


declareBean

public final 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
Overrides:
declareBean in interface BSFEngineImpl

Parameters:
bean - the bean to declare

Throws:
BSFException - if the engine cannot do this operation


eval

public Object eval(String source,
                   int lineNo,
                   int columnNo,
                   Object oscript)
            throws BSFException
This is used by an application to evaluate a string containing some expression. ActiveScript engines don't return anything .. so the return value is awlays null.
Specified by:
eval in interface BSFEngine


exec

public void exec(String source,
                 int lineNo,
                 int columnNo,
                 Object script)
            throws BSFException
This is used by an application to execute a string containing a script to execute. ActiveScript engines don't return anything .. so the return value is awlays null.
Specified by:
exec in interface BSFEngine
Overrides:
exec in interface BSFEngineImpl


finalize

protected void finalize()
            throws Throwable


initialize

public void initialize(BSFManager mgr,
                       String language,
                       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
Overrides:
initialize in interface BSFEngineImpl


isCaseSensitive

protected final boolean isCaseSensitive()


isJScript

protected final boolean isJScript()


isPerlScript

protected final boolean isPerlScript()


isVBScript

protected final boolean isVBScript()


lookupBean

public final Object lookupBean(String name)
lookupBean


setEvalRet

public final void setEvalRet(Object ret)


terminate

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


undeclareBean

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

Parameters:
bean - the bean to undeclare

Throws:
BSFException - if the engine cannot do this operation