This site's content was compiled from 1993 to 2006. Beyond that, Google is your friend.
Greg Lee
A utility that generates Eiffel source code wrappers for Java class files.
When used in conjunction with SmartEiffel's 1.1's compile_to_jvm command, one can make use of any Java class from Eiffel.
Wrap_jvm_class is a command line application written in Eiffel that creates an Eiffel source file wrapper for a JVM class file. Using wrap_jvm_class and the SmartEiffel compile_to_jvm command, it is possible to write Eiffel programs that make use of existing Java executables and also create Eiffel libraries that can be called from Java executables. It is even possible to create applets and use the Swing graphical user interface libraries.
Wrap_jvm_class will run on any system that supports SmartEiffel's compile_to_jvm command.
Wrap_jvm_class uses the Java reflection API to determine the various fields and methods in a Java class file and then generates the text of an Eiffel source file that wraps that Java class.
The generated Eiffel wrapper class works with its associated Java class by maintaining a reference to a Java runtime instance of the Java class. When a creation routine is called on the Eiffel class, an instance of the wrapped Java class is created and stored as an attribute of the Eiffel class. After creation, calling a routine in the Eiffel class causes the corresponding method to be called in the Java class instance. The wrapper class takes care of manipulating method parameters and return values to switch between the Eiffel and Java environments.
Each SmartEiffel compilation produces a unique Java Virtual Machine class file for every Eiffel class. The SmartEiffel compiler optimizes the generated class files by eliminating unused attributes and routines and also by eliminating polymorphic calls when possible. Thus class files produced by one compilation cannot be used with the output of another compilation run.
All of this makes it a lot easier to use Java classes from Eiffel than to use Eiffel classes from Java. Eiffel code is best used from Java by creating a system of Eiffel classes that work together and present a single, standard Java interface to external callers. Packaging such an Eiffel system may require the construction of a supporting Java language class to provide the external interface.
Wrap_jvm_class provides several ways to automatically generate Eiffel wrapping classes and Java support classes to facilitate calls between Eiffel and Java.
The SmartEiffel compile_to_jvm command currently cannot compile Eiffel code that uses the INTEGER_64 type or agents. Wrap_jvm_class will correctly generate wrappers for Java classes and interfaces that use 64 bit integers (in Java, longs) but they will not compile. Wrap_jvm_class can also generate interface adapters and inheritance delegators that use Eiffel agents.
Can I write applets in Eiffel? Yes! See the examples message_applet and scribble.
Can I inherit from a Java class in Eiffel? No, but wrap_jvm_class can automatically generate a Java class stub that delegates the redefined functions to an automatically generated Eiffel class. To implement the "inherited" functions in Eiffel, all you have to do is edit the generated Eiffel source code file.
Can I implement a Java interface in Eiffel? A good approach is to use wrap_jvm_class to generate a Java stub class that implements the desired interface and delegates the interface functions to an automatically generated Eiffel class. All you have to do is edit the generated Eiffel source code file.
Can I write Java Swing GUI applications in Eiffel? Absolutely! See the examples display_message and file_tree_demo.
Why are the generated routine names in the Eiffel wrapper classes so long? Because Java supports function overloading, the Eiffel version of the simple function name in Java has to have the parameter and return type information tacked onto it to ensure it's unique.
Can wrap_jvm_class handle Java inner classes? Yes.
Why wrap Java libraries when they are of uniformly high quality or compelling functionality? The main point is that someone else is doing all of the really hard work to create those Java libraries. With wrap_jvm_class, we Eiffelists can choose to use them or not as we please.
"Scribble" applet under Windows 2000 and MacOS/X / image: wrap-jvm-class documentation