Subj : RE: Call self defined java class in JS by Rhino To : netscape.public.mozilla.jseng From : Jiming Liu Date : Fri Dec 03 2004 06:12 pm This is a multi-part message in MIME format. ------=_NextPart_000_0003_01C4D963.A6997100 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Thierry, Thank you, it works!!! Can administrator put the following code on Rhino site please? I am sure there must have other fresh hand like me don't know how to do it. Rhino is very cool, but I have to say the document is poor. Best regards, Jiming import org.mozilla.javascript.*; /** * * @author Administrator */ public class Foo2 { public String echo(String str){ return str + ":" + str + ":" + str; } public static void main (String[] args) { Context cx = Context.enter (); try{ Scriptable scope = cx.initStandardObjects (); String s = "var b = f2.echo('aaa');"; Foo2 f2 = new Foo2(); scope.put("f2", scope, cx.javaToJS (f2, scope)); cx.evaluateString (scope, s, "", 1, null); System.out.println (cx.toString (scope.get ("b", scope))); }catch(Exception e){ e.printStackTrace (); }finally{ cx.exit (); } } } _____ From: Thierry Hanot [mailto:thanot@infovista.com] Sent: Friday, December 03, 2004 12:34 AM To: 'Jiming Liu' Subject: RE: Call self defined java class in JS by Rhino Hello I did have a quick look on the last version of Rhino May be you can have a look to the Context.javaToJS() Method. This method map automatically the java method into javascript without using the rhino naming . B.R Thierry -----Original Message----- From: Jiming Liu [mailto:jimingliu@gmail.com] Sent: Friday, December 03, 2004 10:53 PM To: mozilla-jseng@mozilla.org Subject: Call self defined java class in JS by Rhino Hi, Can anybody tell me why I have the extended from ScriptableObject and defined jsConstructor_*, jsGet_*, jsSet_*, jsFunction_* when I simply want to use the a self defined Java class? It is boring, especially when the class has a lot of methods. I think Jyphon do it more elegent. 1) define class; package com.pushtotest.myapplication; public class myApp { public String getName() { return "Frank"; } } 2)call in Jyphon from com.pushtotest.myapplication import myApp a = myApp() print "myApp says: Thank you", a.getName(), \ ", I will buy a support agreement." Look, much easier and more decent, right? Can anyone tell me how to use Rhino in this way or why Rhino do not support this way? Great thanks! Jiming ------=_NextPart_000_0003_01C4D963.A6997100 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Message

Thierry,

 <= /span>

Thank you, it = works!!!

 <= /span>

Can administrator = put the following code on Rhino site please? I am sure there must have other = fresh hand like me don’t know how to do it. Rhino is very cool, but I have to = say the document is poor.

 <= /span>

Best = regards,

 <= /span>

Jiming<= /span>

 <= /span>

 <= /span>

= import org.mozilla.javascript.*;

=  

= /**

=  *

=  * @author  Administrator

=  */

= public class Foo2 {

=    

=     public String echo(String str){

=         return str + ":" + str + ":" + = str;

=     }

=  

=     public static void main (String[] args) = {

=         Context cx =3D Context.enter ();

=         try{

=             Scriptable scope =3D cx.initStandardObjects = ();

=             String s =3D  "var b =3D = f2.echo('aaa');";

=             Foo2 f2 =3D new Foo2();

=             scope.put("f2", scope, cx.javaToJS (f2, = scope));

=            

=             cx.evaluateString (scope, s, "<cmd>", 1, = null);

=             System.out.println (cx.toString (scope.get ("b", = scope)));

=  

=         }catch(Exception e){

=             e.printStackTrace ();

=         }finally{

=             cx.exit ();

=         }

=        

=     }   

=    

= }

=  


From: Thierry = Hanot [mailto:thanot@infovista.com]
Sent: Friday, December = 03, 2004 12:34 AM
To: 'Jiming Liu'
Subject: RE: Call self = defined java class in JS by Rhino

 

Hello

I did have a quick look on the last version of = Rhino

May be you can have a look to the Context.javaToJS() =  Method.

This method map automatically the java method into = javascript without using the rhino naming .

 =

B.R

 =

Thierry

 =

 =

-----Original Message-----
From: Jiming Liu [mailto:jimingliu@gmail.com]
Sent: Friday, December = 03, 2004 10:53 PM
To: = mozilla-jseng@mozilla.org
Subject: Call self = defined java class in JS by Rhino

Hi,<= /p>

 

Can anybody = tell me why I have the extended from ScriptableObject and defined jsConstructor_*, = jsGet_*, jsSet_*, jsFunction_* when I simply want to use the a self defined Java = class? It is boring, especially when the class has a lot of methods. =

 

I think Jyphon = do it more elegent.

1) define = class;

package =
com.pushtotest.myapplication;
public class =
myApp
{
    &nbs=
p; public String getName()
    &nbs=
p; {
    &nbs=
p;    return =
"Frank";
    &nbs=
p; }
}
    

2)call in = Jyphon

from com.pushtotest.myapplication    =
import myApp
a =3D =
myApp()
print "myApp says: =
Thank you", a.getName(), \



 




 
 
", I will buy a =
support agreement."

 

Look, much easier and more decent, right?

 

Can anyone tell me how to use Rhino in this way or why Rhino do not support this = way?

 

Great thanks!

 

Jiming

 

 

 

 

 

------=_NextPart_000_0003_01C4D963.A6997100-- .