Wiki source code of Generating EO Java Classes

Version 36.1 by Lachlan Deck on 2007/01/11 20:17

Hide last authors
ianjoyner 33.1 1 WOLips encapsulates the functionality of [[EOGenerator>>http://www.rubicode.com/Software/EOGenerator/]] so that the Java classes can be generated from within Eclipse. WOLips can create an **.eogen** definition for you when the model is created or you can create one after the model has been created by going to **File** - **New** - **Other...** and selecting **EOGenerator**.
chuckhill 18.1 2
Kieran Kelleher 25.1 3 === Install and Configure EOGenerator ===
chuckhill 18.1 4
ianjoyner 33.1 5 Before you can generate Java classes you will need to download and install EOGenerator. **EOGenerator is not part of Eclipse or WOLips.** After it is installed, tell Eclipse where it is in preferences:
chuckhill 18.1 6
ianjoyner 33.1 7 [[image:EOGeneratorPreferences.jpg]]
Kieran Kelleher 25.1 8
9 === Setup Configuration for a Model ===
10
ianjoyner 33.1 11 The next step is to fill in the .eogen configuration for your model.
Kieran Kelleher 25.1 12
13 {{info title="Multiple Models"}}
14
ianjoyner 33.1 15 If you have multiple models that you need to generate Java classes for, and they need different settings (templates, destination directories etc), each of these will need its own .eogen configuration.
Kieran Kelleher 25.1 16
17 {{/info}}
18
ianjoyner 33.1 19 Double click on the <ModelName>.eogen icon in the Package Explorer or Navigator:
Kieran Kelleher 25.1 20 [[image:eogenIcon.jpg]]
21 The top section of the editor looks like this:
22
23 [[image:EOGenerator1.jpg]]
24
25 Set the model(s) to generate Java for in the first area. In the second include models containing prototypes and models that are referenced by the models in the first group, but which should not have Java generated for the entities in them.
26
Lachlan Deck 35.1 27 The File Names settings can be ignore unless you need to generate oddly formed file names. You will usually want to **Create Packages** (place the generated files in a directory corresponding to their package). It can useful to have different **Destination** and **Subclass Destination** directories. The totally generated classes in the Destination directory are not very interesting and can be tucked away out of sight.
chuckhill 18.1 28
29 [[image:EOGenerator2.jpg]]
30
31 The **Templates** determine how the Java code is generated. The setting should be self explanatory. The **Defines** are useful for extending the templates with custom values.
32
33 [[image:EOGenerator3.jpg]]
34
35 === Generate the Classes ===
36
ianjoyner 33.1 37 To generate the Java classes, simply right (control) click on the .eogen configuration and select **EOGenerate...** from the context menu. A dialog window will be shown when EOGenerator finishes so that you can verify what it did.
chuckhill 18.1 38
ianjoyner 33.1 39 {{note title="EOGenerator Not Running?"}}
chuckhill 18.1 40
ianjoyner 33.1 41 Nothing happens? Just see a flicker of a progress bar at the bottom right? Go back to the Preferences. The path to the eogenerator executable is missing or incorrect.
chuckhill 18.1 42
ianjoyner 33.1 43 {{/note}}
chuckhill 18.1 44
ianjoyner 33.1 45 {{info title="Ant generation"}}
chuckhill 18.1 46
ianjoyner 33.1 47 Manually generating your files can, of course, get a little boring after a while. You may prefer the generation to happen in the background via ant (for example when you save changes to your model). This is especially useful for automated build environments.
chuckhill 18.1 48
ianjoyner 33.1 49 Create a target in your build.xml called "init.eogenerator" like the following:
chuckhill 18.1 50
ianjoyner 33.1 51 {code:xml}
52 <target name="init.eogenerator">
53 <exec executable="/usr/bin/env" dir="${basedir}">
54 <arg value="perl" />
55 <arg value="${basedir}/etc/eogenerating.pl" />
56 </exec>
57 </target>
58 {code}
chuckhill 18.1 59
ianjoyner 33.1 60 If ant supported loops by default we wouldn't need an additional script, but because we want to find all {{*.eogen}} files in our {{Resources}} directory and execute them one by one we can use perl and call it from ant. Create a file {{yourprojectdir/etc/eogenerating.pl}} as follows:
chuckhill 18.1 61
ianjoyner 33.1 62 {code:none}
63 #!/usr/bin/env perl
chuckhill 18.1 64
ianjoyner 33.1 65 use strict;
66 use warnings;
67
68 my $RESOURCES = "Resources";
69
70 if ( -d $RESOURCES ) {
71 opendir(DIR, $RESOURCES) || die "can't open $RESOURCES: $!";
72 my @files = grep { ! /^\./ && -f "$RESOURCES/$_" && /\.eogen$/ } readdir(DIR);
73 closedir DIR;
74 foreach (@files) {
75 my @args = ("./$RESOURCES/$_");
76 system(@args);
77 }
78 }
79 {code}
80
81 Lastly, adjust your {{compile}} target from
82 {code:xml}
83 <target name="compile" depends="setProps,init.build"> ... </target>
84 {code}
85
86 to
87
88 {code:xml}
89 <target name="compile" depends="setProps,init.eogenerator,init.build"> ... </target>
90 {code}
91
92 {{/info}}