This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Three questions about Java Scripting API.

 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
here are three questions about java scripting api, please help.

(1) How can I get all the variables created inside my engine?
There are two kinds of variables: first kind is Java objects that I have put inside the engine, and second kind is the variables created inside my script, such as 'var a = 4;'. How can I list all the variables of that two kinds, or at least the second kind?

(2) Is there is a way to make 'import static' to the engine? I dont want to write MyClass.MyEnum.MyEnumItem inside my script every time. Also, I cannot put the whole enum into the engine with engine.put("MyEnum", MyEnum); I can put only enum items separately: engine.put("MyEnum", MyEnum.EnumItemA);. Thats why I ask about static import.

(3) How can I cast engine variables back to java variables inside my java code?
Here is my example:



The result is:
Exception in thread "main" java.lang.ClassCastException: sun.org.mozilla.javascript.internal.NativeJavaObject cannot be cast to java.lang.Double
at mypackage.Main.main(Main.java:28)


Is it possible to retrieve my Double java object from the engine?
 
I found a beautiful pie. And a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!