Free EcmaScript Interpreter.  
A JavaScript interpreter written in Java.
 
 
Bean Scripting Framework

The Bean Scripting Framework (information at http://jakarta.apache.org/bsf) , is a generic interface to many scripting engines. If you want to use the BSF engine, you must add the corresponding jar to the classpath. 

The source file FESI.Tests.BSFTest.java is a test of the interface, that  can be used as an example on how to invoke it.


Calling FESI from the BSF interface

FESI can be instantiated and then called explicitely, for example::
import com.ibm.bsf.*;

     BSFManager  mgr = new BSFManager()

String[] extensions = { "es" }; // File name extensions

BSFManager.registerScriptingEngine("ecmascript", "FESI.Bsf.BsfEngine", extensions);

// Call via generic interface
Object result = mgr.eval("ecmascript", "testString", 0, 0, "2+32");
// Result is a Byte with value 34.

See the documentation of BSF for alternative ways of calling the script and for the use bean registration.  Use the BSF apply function if you want to return a value using the return statetement.

It is possible to access the JSGlobalObject of the interpreter by using the following idom (any object can be used):
           
     Object result = mgr.eval("ecmascript", "getAnObject", 0, 0,
                "new Object(); ");
     JSObject jso = (JSObject) result;
     JSGlobalObject global = jso.getGlobalObject();

Or more directly using:

      FESI.Bsf.BsfEngine fesiEngine = (FESI.Bsf.BsfEngine) mgr.loadScriptingEngine ("ecmascript");
      JSGlobalObject global = fesiEngine.getJSGlobalObject();

Configuring BSF

There are two ways to configure the BSF manager:
  1. Explicitely registering the interpreter in your code (as illustrated in the example above)
  2. By editing the resource com.ibm.bsf.Languages,  which is in the file .../com/ibm/bsf/Languages.properties, and adding the line:
                   fesi=FESI.Bsf.BsfEngine, es
    The resource file can be replaced in the bsf.jar file. fesi.jar must then naturally be on the class path of the program using BSF.

Information table


Category
Description
Language identifier
ecmascript
File extension(s)
.es
Looking up a bean
x = bsf.lookupBean (“name-of-bean”)
Create a new bean
Any Java object can be used as a bean.
Registering a bean
bsf.registerBean (“name-of-bean”, bean)
Unregistering a bean
bsf.unregisterBean (“name-of-bean”)
Binding a script to be executed
upon event firing
target.onEvent= "script-to-exec”
The BSF method (addEventListener) has not beend tested.
Doing all bean operations
Use FESI JavaAccess capabilities (similar to LiveConnect)
Language home
http://fesi.lugrin.ch


Return to the main page

Copyright © Jean-Marc Lugrin 1998-2003 - Under LGPL license Last update: 1 September 2003