Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Scripting engine - Java 6

Reply
Thread Tools

Scripting engine - Java 6

 
 
debasish
Guest
Posts: n/a
 
      07-31-2007
Hi -

I am a newbie wrt scripting in Java 6. I have 2 questions on this
topic :

a) With the current version of Java 6 distribution, the version of
Rhino that comes bundled is 1.6 Release 2. If I want to use a
different version of the Rhino engine (e.g. 1.6 Release 5), how do I
do that ?

b) In cases when I return a Javascript array from my script code, what
I get back in Java is sun.org.mozilla.javascript.internal.NativeArray,
which is probably a wrapper for org.mozilla.javascript.NativeArray. Is
it the common practice to handle these sun.org datatypes within my
Java program ? Or is there a way I can get back the actual mozilla
NativeArray type ?

Any help will be appreciated.

Thanks.
- Debasish

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-31-2007
On Tue, 31 Jul 2007 07:36:05 -0000, debasish
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>a) With the current version of Java 6 distribution, the version of
>Rhino that comes bundled is 1.6 Release 2. If I want to use a
>different version of the Rhino engine (e.g. 1.6 Release 5), how do I
>do that ?


I understand that Sun modified Rhino to fit their generic scripting
API. So that implies you can't simply plug in a different Rhino
version by swapping jars. Jet works with the original Mozilla Rhino,
so I gather all you need do is plop a different Rhino into the EXT
directory which will presumably have different package names and a
slightly different API.

see http://mindprod.com/jgloss/rhino.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-31-2007
On Tue, 31 Jul 2007 07:36:05 -0000, debasish
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>b) In cases when I return a Javascript array from my script code, what
>I get back in Java is sun.org.mozilla.javascript.internal.NativeArray,
>which is probably a wrapper for org.mozilla.javascript.NativeArray. Is
>it the common practice to handle these sun.org datatypes within my
>Java program ? Or is there a way I can get back the actual mozilla
>NativeArray type ?


What Sun is constantly trying to do with JCE, JDBC and now the
scripting is to make pluggable interfaces where various
implementations can replace Sun code with minimal fuss in the
applications. I laud them for this. Very early on I argued that
providing pluggable interfaces would be far more useful to the Java
community than providing polished implementations. I asked them to
create standard interfaces for every conceivable purpose, with a
reference implementation as a secondary concern, and a decent
implementation as a tertiary concern. I doubt it is because of my
request, but they have done what I wanted in spades. It is so rare a
corporation does what I wanted it to.

Sun are trying to mask the squirrelly differences between
implementation so you can swap implementors in a heartbeat. You are
trying to defeat them. You are better off ignoring Java's generifying
layer and using Mozilla Rhino directly.

see http://mindprod.com/jgloss/rhino.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
debasish
Guest
Posts: n/a
 
      07-31-2007
On Jul 31, 3:49 pm, Roedy Green <(E-Mail Removed)>
wrote:
>
> Sun are trying to mask the squirrelly differences between
> implementation so you can swap implementors in a heartbeat. You are
> trying to defeat them. You are better off ignoring Java's generifying
> layer and using Mozilla Rhino directly.
>
> seehttp://mindprod.com/jgloss/rhino.html


>> Does this mean that if I want to stick to Sun's generifying layer, I will be using classes like sun.org.mozilla.javascript.internal.NativeArray for data type transformations between Javascript and Java ? Or is there any other way of achieving the same goal.


Thanks.
- Debasish


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-31-2007
On Tue, 31 Jul 2007 11:19:00 -0000, debasish
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :


> Does this mean that if I want to stick to Sun's generifying layer,
>I will be using classes like sun.org.mozilla.javascript.internal.NativeArray
> for data type transformations between Javascript and Java ?
>Or is there any other way of achieving the same goal.


Keep in mind, if you do that, you are cheating and defeating the
purpose of what Sun has done, so your code could break at any time.
Basically you get objects, find out their class with getClass, then
write code to cast them to specific objects so you can access the
native methods. You may find the methods you need in Sun's glue
objects are private to foil such attempts.

If I were you I would decide: do I want Sun generic scripting or
Rhino. Then, if Sun, stop cheating and use only the Sun API.. If
Rhino, bypass the Sun layer. Treat Rhino as if Sun had never heard of
it, downloading your own jar.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
debasish
Guest
Posts: n/a
 
      07-31-2007
On Jul 31, 5:06 pm, Roedy Green <(E-Mail Removed)>
wrote:
> On Tue, 31 Jul 2007 11:19:00 -0000, debasish
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
> who said :
>
> > Does this mean that if I want to stick to Sun's generifying layer,
> >I will be using classes like sun.org.mozilla.javascript.internal.NativeArray
> > for data type transformations between Javascript and Java ?
> >Or is there any other way of achieving the same goal.

>
> Keep in mind, if you do that, you are cheating and defeating the
> purpose of what Sun has done, so your code could break at any time.
> Basically you get objects, find out their class with getClass, then
> write code to cast them to specific objects so you can access the
> native methods. You may find the methods you need in Sun's glue
> objects are private to foil such attempts.


>> If I return a Javascript array into Java and do a getClass(), I get sun.org.mozilla.javascript.internal.NativeArray. I understand that this is NOT programming to the interface, I am programming to the internal classes, which Java wraps. In that case what will be the best practice to use Javascript arrays which are returned from the script methods ? Of course one option will be to bypass Sun layer, use Rhino directly, possibly through something like BeanShell. But if I want to stick to Sun api, how do I deal with objects returned from Javascript ?


Cheers.
- Debasish


 
Reply With Quote
 
Tom Hawtin
Guest
Posts: n/a
 
      08-02-2007
debasish wrote:
>
> a) With the current version of Java 6 distribution, the version of
> Rhino that comes bundled is 1.6 Release 2. If I want to use a
> different version of the Rhino engine (e.g. 1.6 Release 5), how do I
> do that ?


The java.net scripting project claims to have an R4 implementation.

https://scripting.dev.java.net/

> b) In cases when I return a Javascript array from my script code, what
> I get back in Java is sun.org.mozilla.javascript.internal.NativeArray,
> which is probably a wrapper for org.mozilla.javascript.NativeArray. Is
> it the common practice to handle these sun.org datatypes within my
> Java program ? Or is there a way I can get back the actual mozilla
> NativeArray type ?


The sun.org.* classes are org.* classes simply renamed. This allows you
to actually use your own version of Rhino directly. Otherwise it's be
like trying to use your own copy of java.lang.String, which simply
doesn't work. sun.* is special in that untrusted code cannot access it.

A better approach would be to create a Java array (or other Java object)
from the JavaScript. Then you could use any scripting API implementation
of JavaScript.

Tom Hawtin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a Scripting Language as Your Scripting Language DaveInSidney Python 0 05-09-2005 03:13 AM
Python is the best and most popular general purpose scripting language; the universal scripting language Ron Stephens Python 23 04-12-2004 05:32 PM
Non Greedy Regular Expression in Scripting Engine 5.1 Wole ASP General 1 02-25-2004 03:48 PM
Re: Cannot install Windows Scripting Engine v5.6 - WSHOM.OCX freezes the system °Mike° Computer Support 4 08-21-2003 07:19 PM
PB with Python ActiveX Scripting Engine registration (Python 2.2.3/2.3) GE Python 1 08-02-2003 01:40 AM



Advertisments