| Method from org.apache.bsf.engines.activescript.ActiveScriptEngine Detail: |
public void addEventListener(Object bean,
String event,
String filter,
String script) throws BSFException {
//The script language this engine is running.
EngineUtils.addEventListener(bean, event, filter, this, bsfmgr, "ActiveScriptEngine", 0, 0, script);
}
|
public final int bindMember(Object target,
String name,
short bindType) throws Exception {
return JavaBean.bindMember( target.getClass(), name, bindType);
}
Binds a method to an integer so it can be later referenced to invoke the method via callMethod. |
public Object call(Object object,
String method,
Object[] args) throws BSFException {
StringBuffer sb = new StringBuffer (300);
sb.append (object.toString());
sb.append (".");
sb.append (method);
sb.append ("(");
if (args != null) {
for (int i = 0; i < args.length; i++) {
sb.append (args[i].toString ());
if (i < args.length-1) {
sb.append (",");
}
}
}
sb.append (")");
return eval ("< internal >", -1, -1, sb.toString ());
}
Return an object from an extension. |
public final Object callMethod(Object bean,
int methodID,
Object[] args) throws Exception {
return JavaBean.callMethod(this, bean, methodID, args);
}
Invokes the method assocaited with methodID on the bean with parameters in the array args. |
final Object callMethodViaBSF(Object[] args) throws BSFException {
Object [] bsfargs= new Object[args.length-2];
if(args.length >2)System.arraycopy(args,2,bsfargs,0, args.length-2);
return EngineUtils.callBeanMethod(args[0], (String) args[1], bsfargs );
}
|
public static final Throwable createBSFException(int reason,
String msg,
Throwable t) {
if(t != null) return new BSFException(reason, msg, t);
else return new BSFException(reason,msg);
}
|
public final Object createBean(Object[] args) throws BSFException {
Object [] bsfargs= new Object[args.length-1];
if(args.length >1)System.arraycopy(args,1,bsfargs,0, args.length-1);
return EngineUtils.createBean((String) args[0], bsfargs );
}
|
public final void declareBean(BSFDeclaredBean bean) throws BSFException {
if(isVBScript()) exec("< declareBean >", 0, 0, "SET " + bean.name + "=bsf.lookupBean(\"" + bean.name + "\") 'via declareBean");
else if(isJScript()) exec("< declareBean >", 0, 0,"var " + bean.name + "=bsf.lookupBean(\"" + bean.name + "\"); //via declareBean");
else if(isPerlScript()) exec("< declareBean >", 0, 0, "$"+bean.name + "=$bsf- >lookupBean('" + bean.name + "'); #via declareBean");
else throw new BSFException(BSFException.REASON_OTHER_ERROR, lang + " does not support declareBean.");
}
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. |
public Object eval(String source,
int lineNo,
int columnNo,
Object oscript) throws BSFException {
if(!isPerlScript()) return nativeEval (css, source, lineNo, columnNo, oscript.toString (), true);
else
{ //ActiveState's Perl implementation does not seem to support this so this was added to make it work.
Integer key=new Integer(Thread.currentThread().hashCode());
nativeEval (css, "< bsf perl declare >",lineNo, columnNo, "$bsf- >setEvalRet(" + oscript.toString () + "); #via eval", false);
Object ret= evalRet.get(key);
if(ret== evalRet) ret = null;
evalRet.put(key, evalRet); //loose reference to whatever.
return ret;
}
}
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. |
public void exec(String source,
int lineNo,
int columnNo,
Object script) throws BSFException {
//Run the script throw away any return code.
synchronized(this)
{
if(terminated()) throw new BSFException(BSFException.REASON_OTHER_ERROR, "Exec or eval called after engine termination!");
}
nativeEval (css, source, lineNo, columnNo, script.toString (), false);
}
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. |
protected void finalize() throws Throwable {
terminate();
super.finalize();
}
|
public void initialize(BSFManager mgr,
String language,
Vector declaredBeans) throws BSFException {
if(null != dllLoadException) throw dllLoadException;
synchronized(this)
{
if(null != lang)
{ //Been called before... this is bad.
lang=language;
throw new BSFException(BSFException.REASON_OTHER_ERROR, "Engine " + this + " initialized again");
}
lang= language;
}
super.initialize (mgr, language, declaredBeans);
if(isPerlScript()) evalRet= new Hashtable(); //Used by languages which don't support expressions.
bsfmgr= mgr; //Save away so we can use duing JNI callback.
nativeInit (lang, null , null ); //Does not return unless exception or this engine is terminated.
//Delared beans are not declared using ActiveX Script's AddItem anymore since
// this does not allow to undeclare these beans later.
if(css == null)
{ //Double check: nativeInit should have set this field!
throw new BSFException(BSFException.REASON_OTHER_ERROR, "Engine " + this
+ " failed to initialize native interface properly.");
}
//Run a little script that sets up the declared beans.
// NOTE: this is done this way as opposed to doing it with MS com addnamedItem because
// this allows for undeclare of these beans to work.
if( 0 !=declaredBeans.size())
{
String prefix= "";
String bsf= "";
String suffix= "";
String eos="";
String eosLast="";
if(isVBScript())
{
prefix= "SET ";
bsf= "=bsf.lookupBean(\"";
suffix= "\")";
eos=":";
eosLast="";
}
else if(isJScript())
{
prefix= "var ";
bsf= "=bsf.lookupBean(\"";
suffix= "\")";
eos=";";
eosLast=eos;
}
else if(isPerlScript())
{
prefix= "$";
bsf= "=$bsf- >lookupBean('";
suffix= "')";
eos=";";
eosLast=eos;
}
else throw new BSFException(BSFException.REASON_OTHER_ERROR, lang + " does not support undeclareBean.");
StringBuffer startup= new StringBuffer("");
int numDeclaredBeans= declaredBeans.size();
for(int i=0; i < numDeclaredBeans; ++i)
{
BSFDeclaredBean b=(BSFDeclaredBean)declaredBeans.elementAt(i);
startup.append(prefix+ b.name + bsf+ b.name + suffix + (i< (numDeclaredBeans-1)? eos : eosLast));
}
exec("< declareBean >", 0, 0, startup.toString());
}
}
|
protected final boolean isCaseSensitive() {
return isVBScript();
}
|
protected final boolean isJScript() {
return lang.equalsIgnoreCase( LANG_JSCRIPT);
}
|
protected final boolean isPerlScript() {
return lang.equalsIgnoreCase( LANG_PERLSCRIPT);
}
|
protected final boolean isVBScript() {
return lang.equalsIgnoreCase( LANG_VBSCRIPT);
}
|
public final Object lookupBean(String name) {
return bsfmgr.lookupBean(name);
}
|
static native void nativeIdispatchAddRef(byte[] IdispatchInterface) throws BSFException
|
static native void nativeIdispatchDeleteRef(byte[] IdispatchInterface) throws BSFException
|
public final void setEvalRet(Object ret) {
evalRet.put( new Integer(Thread.currentThread().hashCode()) , ret != null ? ret : evalRet); //Had some problems setting the value to null.
}
|
public synchronized void terminate() {
if(!terminated())
{
byte[] css= this.css;
this.css= null;
bsfmgr=null; //Used by other methods during JNI callbacks.
evalRet= null; //Used by languages which don't support expressions.
lang=null;
nativeTerminate(css); //Let c++ objects cleanup too.
super.terminate();
}
}
|
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
if(isVBScript()) exec("< undeclareBean >", 0, 0, "SET " + bean.name + "=Nothing 'via undeclareBean");
else if(isJScript()) exec("< undeclareBean >", 0, 0, bean.name + "=null; // via undeclareBean");
else if(isPerlScript()) exec("< undeclareBean >", 0, 0, "undef " + bean.name + " ; #via undeclareBean");
else throw new BSFException(BSFException.REASON_OTHER_ERROR, lang + " does not support undeclareBean.");
}
Undeclare a previously declared bean. |