Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

1.6 better than Rhino

Thread view: 
Timasmith - 05 Mar 2007 03:48 GMT
I've been using Rhino for a while with java 1.5.  Now having spent a
couple of hours troubleshooting why the script was converting my Long
object into a double value, I would consider changing to 1.6 to avoid
scripts messing with my data type objects.

Any ideas if Java 1.6 has an improved integration with Java in this
area?

thanks

Tim
Tom Hawtin - 05 Mar 2007 05:11 GMT
> I've been using Rhino for a while with java 1.5.  Now having spent a
> couple of hours troubleshooting why the script was converting my Long
[quoted text clipped - 3 lines]
> Any ideas if Java 1.6 has an improved integration with Java in this
> area?

The implementation is pretty much identical to Rhino 1.6R2. In fact, you
don't get the source if you download the JDK source. The most
significant difference is the package name.

Tom Hawtin
Knute Johnson - 05 Mar 2007 05:55 GMT
>> I've been using Rhino for a while with java 1.5.  Now having spent a
>> couple of hours troubleshooting why the script was converting my Long
[quoted text clipped - 9 lines]
>
> Tom Hawtin

What's a Rhino?

Signature

Knute Johnson
email s/nospam/knute/

Tom Hawtin - 05 Mar 2007 06:15 GMT
> What's a Rhino?

"Rhino is an open-source implementation of JavaScript written entirely
in Java. It is typically embedded into Java applications to provide
scripting to end users."

http://www.google.co.uk/search?q=rhinos+java
http://www.mozilla.org/rhino/

Tom Hawtin
Knute Johnson - 05 Mar 2007 17:18 GMT
>> What's a Rhino?
>
[quoted text clipped - 6 lines]
>
> Tom Hawtin

Thanks Tom.

Signature

Knute Johnson
email s/nospam/knute/

Andy Dingley - 05 Mar 2007 19:26 GMT
> What's a Rhino?

A punk hippo
Chris Uppal - 05 Mar 2007 06:42 GMT
[Since I've alreay emailed this directly to Tim by mistake once, /and/ reposted
it here, but in the wrong thread, why no just post it again ?  Maybe I'll post
it lot's of times.  Maybe I'll spam the world....]

> I've been using Rhino for a while with java 1.5.  Now having spent a
> couple of hours troubleshooting why the script was converting my Long
> object into a double value, I would consider changing to 1.6 to avoid
> scripts messing with my data type objects.

As far as I know, the only numeric type ECMAScript has is 64-bit floating
point.  So there's very little else a JavaScript interpreter is allowed to
do.

Of more practical value to you, I imagine, is to know why Rhino makes your
long (when converted to floating point) behave and/or look like a floating
point value instead of coyly pretending to be an integer.  I can only guess
that the original value is outside some range.  For instance ECMAScript's
built in Number -> String conversion will only represent "integer" Number
values as if they /are/ integers if they lie within some range -- the rules
are a little complicated, but I think that range is +/-1.0e21.

What is the value of the original long ?   And what are you doing with the
resulting JavaScript number to be able to see that it has "turned into"
floating point ?

   -- chris
Timasmith - 06 Mar 2007 01:20 GMT
On Mar 5, 1:42 am, "Chris Uppal" <chris.up...@metagnostic.REMOVE-
THIS.org> wrote:
> [Since I've alreay emailed this directly to Tim by mistake once, /and/ reposted
> it here, but in the wrong thread, why no just post it again ?  Maybe I'll post
[quoted text clipped - 23 lines]
>
>     -- chris

The original value was only 1000013 and was passed as a Long object
using this (simplified) Java:

<pre>
      Context cx = Context.enter();
      Scriptable scope = new ImporterTopLevel(cx);

      Object ctx = Context.javaToJS(new Long(1000013), scope);
      ScriptableObject.putProperty(scope, "longID", ctx);

      result = cx.evaluateString(scope, script, "<>", 0, null);
      return Context.jsToJava(result, javaclass);
      Context.exit();
</pre>

The script puked due as I use the script to pass the value along to a
query.  The Hibernate query died as it found a double value 1000013.0
being bound to a long parameter.

<pre>
qry = new MyQuery();
   s = "from MyTableObject v"
   + " where v.id = :longID";

qry.addParam(new QryParam("longID",longID));
qry.addParam(new QryParam("startDATE",startDATE));

</pre>

What is frustrating is that QryParam takes parameters (Object, Object)
so there was no need at all for the script to change the Object to a
double value.  I pass object parameters all the time for real java
objects, but for some reason it bastardized my Long.  The Calendar
subclass was fine.
Chris Uppal - 07 Mar 2007 16:40 GMT
> The original value was only 1000013 and was passed as a Long object

Then I'm afraid I have no idea what would be causing the problem.

Sorry....

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.