From:  "dg" <dmitry.goldenberg@weblayers.com>
Date:  29 May 2006 03:29:04 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

Can I pass Java objects into my scripts via Rhino and get objects back?

NNTP-Posting-Host:  64.190.18.102

Hi,

I'm a newbie to Rhino.  Basically, I have a Java driver that executes
JavaScript scripts.  Currently, I'm doing it with BSF like this:

in Java:
      BSFManager mgr = new BSFManager();
      mgr.registerBean("myinput", new MyInput());
      mgr.registerBean("myoutput", myoutput);
      BSFEngine jsEngine = // ... load the JS engine
      String script = "";
      jsEngine.exec("source.js", 0, 0, script);

the JavaScript is:
var myinput = bsf.lookupBean(myinput);
var result = bsf.lookupBean(myoutput);
// do some voodoo on the input
// do some voodoo on the output

back to the Java driver:
      if (myoutput.getStatus() == SUCCESS) { ... etc.etc.

The problem that I have with this approach is my product management
does not like to see the user type in "bsf" in their scripts :))  I
think they've got a point.  Is there any way to rename the implicit bsf
variable?

If not, how can I reimplement this logic directly with Rhino ??  I've
looked at the samples but I can't seem to find anything that does what
I'm doing in the snippets above, I've only seen samples which *new up*
Java objects and manipulate them.

I'd appreciate any help.
- D.