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 Ol...@freudenberg.de on 2003/01/31 17:35:49 UTC
how to access scripted objects?
Hi,
I've no idea how to access scripted objects (JavaScript). My java test app
looks like this:
BSFManager mgr = new BSFManager();
BSFEngine engine = mgr.loadScriptingEngine("javascript");
FileReader in = new FileReader("c:/temp/test.js");
String script = IOUtils.getStringFromReader( in);
Object obj = engine.eval("", -1, -1, script);
The JavaScript test.js looks like this :
var g_test = new Array();
function f()
{
g_test[1] = new Object();
g_test[1].str = 'Y1Z1';
g_test[2] = new Object();
g_test[2].str = 'Y1Z2';
}
The variable 'g_test' will be initialized by function 'f()'.
I don't know how to invoke 'f()' and how to access 'g_test'.
Please help.
With kind regards,
Oliver
Freudenberg IT KG mailto:oliver.kowalke@freudenberg.de
Produktentwicklung http://www.freudenberg-it.de
Obergraben 10 Fon: +49 (0) 351 89 85 661
01097 Dresden, Germany Fax: +49 (0) 351 89 85 666
Re: how to access scripted objects?
Posted by "Victor J. Orlikowski" <vj...@dulug.duke.edu>.
On Fri, Jan 31, 2003 at 05:35:49PM +0100, Oliver.Kowalke@freudenberg.de wrote:
> I've no idea how to access scripted objects (JavaScript). My java test app
> looks like this:
>
> BSFManager mgr = new BSFManager();
> BSFEngine engine = mgr.loadScriptingEngine("javascript");
> FileReader in = new FileReader("c:/temp/test.js");
> String script = IOUtils.getStringFromReader( in);
>
> Object obj = engine.eval("", -1, -1, script);
>
> The JavaScript test.js looks like this :
>
> var g_test = new Array();
> function f()
> {
> g_test[1] = new Object();
> g_test[1].str = 'Y1Z1';
> g_test[2] = new Object();
> g_test[2].str = 'Y1Z2';
> }
>
> The variable 'g_test' will be initialized by function 'f()'.
> I don't know how to invoke 'f()' and how to access 'g_test'.
>
1) You should invoke f() either from within your script or via the
call() method.
2) To access g_test, you may want to use an expression. I will
warn you, however, that if you are using Rhino, you will run into
a large wart w.r.t. array handling.
Hope that helps,
Victor
--
Victor J. Orlikowski | The Wall is Down, But the Threat Remains!
==================================================================
orlikowski@apache.org | vjo@dulug.duke.edu | vjo@us.ibm.com