This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Three questions about Java Scripting API. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Three questions about Java Scripting API." Watch "Three questions about Java Scripting API." New topic
Author

Three questions about Java Scripting API.

Dmitry Zhuravlev
Ranch Hand

Joined: Apr 14, 2010
Posts: 91
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Three questions about Java Scripting API.
 
Similar Threads
For all you language buffs: why is static import of something in the default package impossible?
dealing with formula objects
Where do I get java-engine.jar to make new ScriptEngineManager().getEngineByName("java"); work
Calling Javascript function from Java Code
Need help with Java Scripting API.