Rhino 1.6r7, the release currently included with Servoy 4, is actually a "minor, bug-fix release," but of course includes all the great new features introduced throughout 1.6rx - meaning to the best of my knowledge - no Rhino features have been disabled by Servoy! Alongside other new features introduced in Rhino 1.6rx such as E4X, a new global constructor known as "JavaImporter" surfaced.
Per the Rhino 1.6r1 change log, "JavaImporter...allows [you] to omit explicit package names when scripting Java." On the surface this may not seem like much of a feature, but in addition to the important technical advantages it provides over older techniques (detailed in the change log), JavaImporter can help to keep your code clean, organized and more readable [when scripting Java].
Have a look at how it is used (borrowed from: http://www.mozilla.org/rhino/rhino16R1.html):
var SwingGui = new JavaImporter(Packages.javax.swing,
Packages.javax.swing.event,
Packages.javax.swing.border,
java.awt.event,
java.awt.Point,
java.awt.Rectangle,
java.awt.Dimension);
...
with (SwingGui) {
var mybutton = new JButton(test);
var mypoint = new Point(10, 10);
var myframe = new JFrame();
...
}
In the above code, the variable SwingGui is assigned the value of JavaImporter, an ImporterTopLevel object, which is subsequently used in a with statement to instantiate classes from packages that were initially passed to the JavaImporter constructor. What you can take from this code is that Java packages can now be easily organized and more easily referenced within your Servoy code. You can assign collections of certain packages to certain variables, giving those variables descriptive names such as "SwingGui," then calling them as necessary. Also, you can easily add packages to the JavaImporter constructor as necessary, and the classes from those packages you add will become available throughout your solution, wherever you have used the variable to which they were assigned.
If you script Java from within your Servoy solutions, give JavaImporter a try.

0 comments:
Post a Comment