2006-02-03, rgf

org.apache.bsf.engines.activescript
Class ActiveScriptEngine

java.lang.Object
  extended byorg.apache.bsf.util.BSFEngineImpl
      extended byorg.apache.bsf.engines.activescript.ActiveScriptEngine
All Implemented Interfaces:
BSFEngine, java.util.EventListener, JavaBeanAddEventListener, java.beans.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

Nested Class Summary
(package private)  class ActiveScriptEngine.ArrayInfo
           
 
Field Summary
(package private)  BSFManager bsfmgr
           
(package private)  byte[] css
           
(package private) static BSFException dllLoadException
           
protected  java.lang.String lang
           
(package private) static java.lang.String LANG_JSCRIPT
           
(package private) static java.lang.String LANG_PERLSCRIPT
           
(package private) static java.lang.String LANG_VBSCRIPT
           
(package private) static java.lang.String libName
           
 
Fields inherited from class org.apache.bsf.util.BSFEngineImpl
classLoader, classPath, declaredBeans, mgr, tempDir
 
Constructor Summary
ActiveScriptEngine()
           
 
Method Summary
 void addEventListener(java.lang.Object bean, java.lang.String event, java.lang.String filter, java.lang.String script)
          add an event listener
 int bindMember(java.lang.Object target, java.lang.String name, short bindType)
          Binds a method to an integer so it can be later referenced to invoke the method via callMethod.
 java.lang.Object call(java.lang.Object object, java.lang.String method, java.lang.Object[] args)
          Return an object from an extension.
 java.lang.Object callMethod(java.lang.Object bean, int methodID, java.lang.Object[] args)
          Invokes the method assocaited with methodID on the bean with parameters in the array args.
(package private)  java.lang.Object callMethodViaBSF(java.lang.Object[] args)
           
 java.lang.Object createBean(java.lang.Object[] args)
          createBean
static java.lang.Throwable createBSFException(int reason, java.lang.String msg, java.lang.Throwable t)
           
 void declareBean(BSFDeclaredBean bean)
          Declare a bean after the engine has been started.
 java.lang.Object eval(java.lang.String source, int lineNo, int columnNo, java.lang.Object oscript)
          This is used by an application to evaluate a string containing some expression.
 void exec(java.lang.String source, int lineNo, int columnNo, java.lang.Object script)
          This is used by an application to execute a string containing a script to execute.
protected  void finalize()
           
 void initialize(BSFManager mgr, java.lang.String language, java.util.Vector declaredBeans)
          initialize the engine; called right after construction by the manager.
protected  boolean isCaseSensitive()
           
protected  boolean isJScript()
           
protected  boolean isPerlScript()
           
protected  boolean isVBScript()
           
 java.lang.Object lookupBean(java.lang.String name)
          lookupBean
(package private) static void nativeIdispatchAddRef(byte[] IdispatchInterface)
           
(package private) static void nativeIdispatchDeleteRef(byte[] IdispatchInterface)
           
 void setEvalRet(java.lang.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, iexec, propertyChange
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dllLoadException

static BSFException dllLoadException

libName

static final java.lang.String libName
See Also:
Constant Field Values

LANG_VBSCRIPT

static final java.lang.String LANG_VBSCRIPT
See Also:
Constant Field Values

LANG_PERLSCRIPT

static final java.lang.String LANG_PERLSCRIPT
See Also:
Constant Field Values

LANG_JSCRIPT

static final java.lang.String LANG_JSCRIPT
See Also:
Constant Field Values

css

byte[] css

bsfmgr

BSFManager bsfmgr

lang

protected java.lang.String lang
Constructor Detail

ActiveScriptEngine

public ActiveScriptEngine()
Method Detail

addEventListener

public void addEventListener(java.lang.Object bean,
                             java.lang.String event,
                             java.lang.String filter,
                             java.lang.String script)
                      throws BSFException
add an event listener

Specified by:
addEventListener in interface JavaBeanAddEventListener
Throws:
BSFException

bindMember

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

Throws:
java.lang.Exception

call

public java.lang.Object call(java.lang.Object object,
                             java.lang.String method,
                             java.lang.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.
object - object on which to make the call
Throws:
BSFException - if anything goes wrong while eval'ing a BSFException is thrown. The reason indicates the problem.

callMethod

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

Throws:
java.lang.Exception

callMethodViaBSF

final java.lang.Object callMethodViaBSF(java.lang.Object[] args)
                                 throws BSFException
Throws:
BSFException

createBean

public final java.lang.Object createBean(java.lang.Object[] args)
                                  throws BSFException
createBean

Throws:
BSFException

createBSFException

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

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 class BSFEngineImpl
Parameters:
bean - the bean to declare
Throws:
BSFException - if the engine cannot do this operation

eval

public java.lang.Object eval(java.lang.String source,
                             int lineNo,
                             int columnNo,
                             java.lang.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
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
oscript - the expression to evaluate
Throws:
BSFException - if anything goes wrong while eval'ing a BSFException is thrown. The reason indicates the problem.

exec

public void exec(java.lang.String source,
                 int lineNo,
                 int columnNo,
                 java.lang.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 class BSFEngineImpl
Throws:
BSFException

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

initialize

public void initialize(BSFManager mgr,
                       java.lang.String language,
                       java.util.Vector declaredBeans)
                throws BSFException
Description copied from class: BSFEngineImpl
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 class BSFEngineImpl
Throws:
BSFException

isCaseSensitive

protected final boolean isCaseSensitive()

isJScript

protected final boolean isJScript()

isPerlScript

protected final boolean isPerlScript()

isVBScript

protected final boolean isVBScript()

lookupBean

public final java.lang.Object lookupBean(java.lang.String name)
lookupBean


nativeIdispatchAddRef

static void nativeIdispatchAddRef(byte[] IdispatchInterface)
                           throws BSFException
Throws:
BSFException

nativeIdispatchDeleteRef

static void nativeIdispatchDeleteRef(byte[] IdispatchInterface)
                              throws BSFException
Throws:
BSFException

setEvalRet

public final void setEvalRet(java.lang.Object ret)

terminate

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

Specified by:
terminate in interface BSFEngine
Overrides:
terminate in class BSFEngineImpl

undeclareBean

public void undeclareBean(BSFDeclaredBean bean)
                   throws BSFException
Undeclare a previously declared bean.

Specified by:
undeclareBean in interface BSFEngine
Overrides:
undeclareBean in class BSFEngineImpl
Parameters:
bean - the bean to undeclare
Throws:
BSFException - if the engine cannot do this operation

2006-02-03, rgf