So far, a major part of Somusar's activity on generators
development has been aimed at delivering a number of self-contained,
batch generators providing
a broad range of proof-of-concepts (POCs). These POC generators
demonstrate the flexibility and applicability of Somusar/Software Production Machine[tm]
for a number of different code-generation tasks.
Such an integration shows how to use Eclipse's comfortable user interface
to directly drive SoProMach's powerful code generation facilities,
significantly improving Eclipse users' productivity without limiting
their development experience.
The Somusar generator used for this article produces code
conforming to Keld H. Hansen's tutorial "Using DAOs in Apache Struts" published by JavaBoutique.
Depending on different project requirements and constraints,
different Somusar generators can be integrated
to produce source code, configuration files, and documentation
compliant to those requirements and constraints.
The article assumes that you have a working installation of
both Eclipse 3.0 and SoProMach/java_dao_struts
on Windows 2000 or Windows XP. Steps similar to those
described in this article are required
to integrate Eclipse and SoProMach on Linux or Mac OS X.
To test the SoProMach/java_dao_struts generator we suggest to set up a
new workspace in Eclipse. By default, when starting Eclipse
you may select a workspace. We chose the new workspace
shown in the picture below.
To be able to compile the Java files that the generator
will produce, you need to add several external JAR files.
These JARs are required to rebuild the project
described by Keld H. Hansen's in his tutorial "Using DAOs in Apache Struts",
independently of SoProMach/java_dao_struts. Please refer to Keld's
article for a list of the required components and JAR files.
To add the JARs to the Eclipse project use button "Add
External JARs..." shown in the next picture.
After creating the new project, you can now create a new package
"dk.hansen" by selecting the project with your mouse, and
right-clicking to activate menu "New -> Package"
and fill in the dialog illustrated below.
You can now add the one and only hand-written file required
for your project, "DAOException.java". You can get this file
from the download package of Keld's article. Import it into package
"dk.hansen" of your Eclipse project using the file system import
wizard as shown below. Make sure that "Create selected folders
only" is selected.
If everything so far worked properly, you should now be
able to double-click on DAOException.java and view it
in the editing area of Eclipse. More importantly, Eclipse's
automatic build should report no errors ("0 errors, 0 warnings, 0 infos")
as shown in the checkpoint picture below.
Up to now you have created a simple Java project with one class.
Extending Eclipse with the generator is not more complex than that.
The generator is configured as an external tool. You can
open the external tools configuration dialog by navigating this
menu path: Run -> External Tools -> External Tools...
Click on "Program", then on "New_configuration". Set the input fields of
tab "Main" (Location, Working Directory, Arguments)
as shown in the picture below, except that
is the installation folder where we uncompressed the
SoProMach/java_dao_struts trial package tarball (".tgz") file.
Instead of "C:\ide_user\dao_struts_gen" you should type the path
where you installed your copy of SoProMach/java_dao_struts. Do not click on "Apply" yet:
you need to set tab "Refresh" and "Common" first.
The input models to SoProMach/java_dao_struts are Sisendel entity files, listed in the
Entity files are plain text files, that can be imported into
Eclipse without any particular configuration.
Select package "dk.hansen" in the project view of Eclipse,
and right-click to activate the file-system import wizard of Eclipse.
You can thus import the four ".ef" files
provided in the "project" folder of your SoProMach/java_dao_struts trial package,
as shown in the next picture. Click on each selection box
beside the four .ef files, and do not click on the
selection box beside the "project" folder, otherwise
you will import additional unnecessary subfolders.
You are now ready to run the generator. Make sure that
your Eclipse window looks like the checkpoint picture below, with
0 errors, 0 warnings and 0 infos, and the four .ef files
in package "dk.hansen".
Now open file "dvd.ef" by double-clicking on its name. Its content
appears in the internal editor of Eclipse.
To run the SoProMach/java_dao_struts generator for the first time you have to
re-open the external tools dialog following this
menu path: Run -> External Tools -> External Tools...
Select "DAO Sopromach", then click on "Run". Within short
you should see a number of Java classes appear in the "dk.hansen"
package, and a "Console" tab appear in the output message area
of Eclipse. Click on this tab: your Eclipse should now look
like the following picture.
Note that the generated files that appeared in the "dk.hansen"
project are by default automatically compiled by Eclipse. The
whole project should get rebuilt with no errors.
At this stage your Eclipse + SoProMach environment has
produced the same code that Keld H. Hansen wrote for his tutorial,
with some minor differences. The generated code includes:
nineteen Java files;
two JSP files;
one struts-config.xml file;
one app.properties file.
All of these files are made available in the same package "dk.hansen".
You can now instruct
your code-generator-enabled Eclipse to produce similar code
for a different application of the same type. Instead of the DVD manager
code, you will generate equivalent code for a Book manager
Double-click on "book.ef" to open it in the editing area of
Eclipse. Follow menu path "Run -> External Tools -> DAO Sopromach"
to apply the SoProMach/java_dao_struts on file "book.ef". After doing so, you should
get twenty-three newly generated files, and your Eclipse should
look like the picture below.
Note that "book.ef" is slightly more complex than "dvd.ef": it has
more fields, one of which is numeric, and its "search_keys" collection
in section DB contains more than one field. This is reflected in
all the generated code. Open some of the generated files related
to "book" and compare them with their counterparts related to
the "dvd" entity.
You can now complete the Eclipse-SoProMach integration example
by repeating the previous step on files "cd.ef" and "vhs.ef".
If all goes well your "dk.hansen" package will contain
ninety-two generated files plus five hand-written files (four ".ef"
files and DAOException.java). Your Eclipse should now
look like the next picture.