You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by "Mark R. Diggory" <md...@latte.harvard.edu> on 2003/02/03 19:48:09 UTC

dealing with reserved terms 'this', 'super'

I'm using BSF in a method of a class kinda like this:


public class Test{

     protected BSFManager manager = null;

     protected doulbe value;

     public Test()throws BSFException{

         manager = new BSFManager();

         manager.declareBean("this",this, this.getClass());
     }

     public Object myMethod(String script) throws BSFException{

        BSFEngine engine = manager.loadScriptingEngine("javascript");

        return engine.eval("my_generated_method",0, 0, script);

    }

    public void setValue(double value){
        this.value = value;
    }

    public double getVlaue(){
        return value;
    }
}

this idea is that I could write script that looks very much like java 
code that would normally go into "myMethod". However, it appears that 
words like "this" and "super" are reserved words. Is there anyway I can 
get "this" to "reference the object instance of this class in my scripts?

I.E. I want a javascript that looks something like this to run an object 
instance of this class.

{
this.setValue(0.04322*100);
this.getValue();
}

Is there a means to access this in BSF?

-Mark Diggory