This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 155482 - Provide support for scripts executed with javax.script.ScriptEngine
Summary: Provide support for scripts executed with javax.script.ScriptEngine
Status: NEW
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-15 16:49 UTC by swpalmer
Modified: 2014-01-16 10:28 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description swpalmer 2008-12-15 16:49:42 UTC
I have a swing application that is extensible through the scripting framework provided by javax.script.*.  It is really 
just an engine that can be scripted.  Users will run my application and choose a script to run or specify a script on 
the command line.  I use the built-in features of Java scripting to expose a few key objects to the script and start it 
up.  I want to edit the scripts in Netbeans since it is aware of the JavaScript syntax and obviously my main engine is 
also being edited and debugged in NetBeans.  However the NetBeans support for JavaScript is assuming that the browser 
is running my script, not the java scripting engine from the JRE.  As such, it complains about functions not being 
supported on certain browsers, when really all I’m doing is calling things like getName() on a java.io.File object.  
There is no way to tell the JavaScript component of NetBeans what objects I’m exporting to the scripting engine (and as 
what symbols) so that it can auto-complete while typing or verify that methods exist.
e.g. my Java code will do:

                void setScript(File script) {
                                this.script = script;
                                javax.script.ScriptEngineManager sem = new ScriptEngineManager();
                                String name = script.getName();
                                String ext = name.substring(name.lastIndexOf('.')+1);
                                engine = sem.getEngineByExtension(ext);
                                if (engine == null) {
                                                throw new RuntimeException("No engine will handle " + ext + " files.");
                                }
                }
                
                Object initScript() throws ScriptException, FileNotFoundException, NoSuchMethodException {
                                engine.put("engine", this);
                                engine.put("emailer", new Emailer());
                                return engine.eval(new FileReader(script));
                }

Users of my application can then add functionality by scripting various methods that I expose. A script would typically 
look like:

result = engine.doSomethingCool(blah1, blah2, blah3); 
emailer.sendEmail("someDude@someCompany.com", "Processed "+blah1, result);

You can see that "engine" and "emailer" refer to Java objects that I have exposed to the script.

I think there is an opportunity here for NetBeans to better support javax.script.* regardless of the scripting language 
used.
Comment 1 Petr Pisl 2009-10-08 11:06:51 UTC
I think this is an enhancement.