Wiki source code of Velocity EOGenerator (Veogen)

Version 34.1 by David Holt on 2008/02/07 13:11

Show last authors
1 This is a basic guide to getting the Velocity Generator to work under Leopard, using Eclipse 3.3.1.1 and WOLips 3.3.4669, later versions should work. The guide is basic in that it should work the way it's detailed below, it doesn't represent the only way, nor probably an optimized way to work with Velocity Generator.
2
3 === History and Context ===
4
5 (from Pierce T Wetter III)
6 EOModeler had built in code generation, which always sucked, because it didn't use the [[Generation Gap Pattern>>http://www.research.ibm.com/designpatterns/pubs/gg.html]]. It used some kind of Apple-specific template format.
7
8 [[EOGenerator>>http://www.rubicode.com/Software/EOGenerator/]], written in objc, relied on an objc-EOF framework to parse the model. That's broken in Mac OS 10.5, (WO 5.4), even if you have the 5.3 frameworks installed, because the Java-objc bridge it uses is not available on 10.5. It uses MiscMerge templates, an open source objc library.
9
10 [[JavaEOGenerator>>http://developer.apple.com/samplecode/JavaEOGenerator/]] is an Apple replacement that uses WO style templates (.html, .wod, etc.), which means it's actually written as a .woa. It uses the WO code to parse the model. The advantage of it is that if Apple changes the model file format, presumably they might change JavaEOGenerator. The disadvantage is that you have to rewrite your templates anyways.
11
12 What people are calling VelocityGenerator is built into WOLips, and uses the code from EntityModeler inside WOLips to parse the model. Given that Apple is funding EntityModeler these days, presumably it will be inherently compatible with any/all .eomodel files going forward. It uses a template library in [[Velocity format>>http://velocity.apache.org/engine/releases/velocity-1.5/vtl-reference-guide.html]], [[Velocity>>http://velocity.apache.org/]] being an open source Java library. It's main advantage is that it's built into WOLips, so there's nothing else to install, and it has some useful built-in defaults (like looking in a templates folder for the templates).
13
14 My decision: After considering the above, I went with the Velocity templates. They were built in, the .eogen default was to use that anyways, so I'll have zero-config issues with the other team members, and Mike Shrag's public much-more-capable template examples were in that format anyways.
15
16 === Tutorial ===
17
18 There are two ways: create eclipse-wide settings, or create settings per project.
19
20 Note: There is actually no need to download Mike's templates as described below unless you want to customize them. WOLips includes two sets of default templates in the .jar files (so don't bother searching your file system for them) - one as described below and another for use with WOnder. If you are using WOnder, you need to follow Mike's instructions for their use: "Where it says "Entity.java" and "//Entity.java" you can use WonderEntity.java and //WonderEntity.java ... If your individual .eogen files override that, you will have to set it in there also". If you leave the "EOGenerator Template Folder" field empty, it will use the default templates...
21
22 ==== eclipse-wide settings for EOGeneration ====
23
24 ~1. Download the templates that Mike Schrag made from [[http://webobjects.mdimension.com/wolips/EOGenerator/Velocity%20EOGenerator%20Templates/]]
25
26 and place them in a folder. In my case that was in
27
28 /Applications/Developing/VelocityEOGeneratorTemplates
29
30 Inside this folder you will have two standard templates: Entity.java en Entity.java. Do not change them for the moment.
31
32 (Additional templates and a reference are available [[here>>*EOGenerator Templates & Additions]])
33
34 2. Go to Preferences > WOLips > EOGenerator
35
36 In EOGenerator Template Folder, fill in the folder you have placed the templates
37 In EOGenerator Java Template fill in Entity.java
38 In EOGenerator Subclass Java Template fill in Entity.java
39
40 This is how it looks in my settings:
41
42 {{panel bgColor="#d8e4f1"}}
43
44 \\ !VEOGeneratorSettingsEclipse.png|align=center!\\
45 \\
46 \\
47
48 {{/panel}}
49
50 3. Go to the eomodel from which you want to create classes and subclasses in the WOPackage sidebar of Eclipse
51
52 4. Right click and choose WOLips Tools > Create EOGenerator File from the contextual menu, (it's a submenu)
53
54 {{panel bgColor="#d8e4f1"}}
55
56 \\ !CreateEOGenContextualMenu.png|align=center!\\
57 \\
58 \\
59
60 {{/panel}}
61
62 Now a eogen file is created which has the name of the EOModel and an .eogen extension.
63 If there is already an eogen file, then another one will be created, with a number between the EOModel name and the extension.
64 The one with the highest number will be the newest (unless you decided to throw earlier ones away, then the numbering starts all over again).
65
66 {{panel bgColor="#d8e4f1"}}
67
68 \\ !MoreEogenfiles.png|align=center!\\
69 \\
70 \\
71
72 {{/panel}}
73
74 5. Go to the eogen file, right click and choose EOGenerate... from the contextual menu.
75
76 {{panel bgColor="#d8e4f1"}}
77
78 \\ !EOGenerateContextualMenu.png|align=center!\\
79 \\
80 \\
81
82 {{/panel}}
83
84 If you have some definitions in your EOModel that have a Class Name that is not an EOGenericRecord, then the appropriate java class and subclass will be generated.
85
86 For instance: a Person class name in EOModel will result in a Person.java file (which will be overwritten the next time EOGeneration will take place) and a Person.java file. The java file without the underscore is the file that will not be overwritten the next time. This file is the file that you would add your own methods. The next time the model changes, the underscore.java file will be overwritten, but your methods are safe.
87
88 6. Check if everything worked out fine. If not (e.g. you made a typing error and a java file happens to be empty) throw away the generated file yo do not want, and restart the process.
89
90 7. If you are fine, you can start fine tuning your templates, or start defining templates per project.
91
92 ==== making Velocity EOGenerator settings per project ====
93
94 ~1. Under Preferences > WOLips > EOGenerator
95 ~> Remove all entries (this is not strictly necessary, but it rules out any errors at the project level)
96
97 {{panel bgColor="#d8e4f1"}}
98
99 \\ !1. EOGenerator Project.png|align=center!\\
100 \\
101 \\
102
103 {{/panel}}
104
105 2. Add a folder named templates in your project folder, inside of which you place your template files.
106 For starters, don't rename them. You can download them here:
107 [[http://webobjects.mdimension.com/wolips/EOGenerator/Velocity%20EOGenerator%20Templates/]]
108
109 {{panel bgColor="#d8e4f1"}}
110
111 \\ !2. Directory Structure.png|align=center!\\
112 \\
113 \\
114
115 {{/panel}}
116
117 Other options for Veogen to pick up any changes you wish to make to the templates:
118
119 * inside your eogen file you need to set template path to the folder containing Entity.java, and if it's named something other than Entity.java, you need to also set template name. Note that template name is ONLY a name, not a full path.
120 * or locate the template files in one of the paths that Velocity EOGenerator looks in by default (,,/Library/Application Support/WOLips/EOGenerator///Entity.java, for example).//,,
121
122 3. Double check your model, so that none of your entities extend EOGenericRecord,
123 otherwise the generation gap pattern won't work, as the velocity generator generates all files,
124 rather than just those extending custom classes. this is a change from the old eogenerator. Also, your entities should be in packages for this all to work optimally. In the example "projectname.eo.class". When it was tried with no package (class) there were a number of errors in the resulting Java class files.
125
126 {{panel bgColor="#d8e4f1"}}
127
128 \\ !3. Entities Snapshot.png|align=center!\\
129 \\
130 \\
131
132 {{/panel}}
133
134 4. Create or edit your .eogen file, mine looks like this:
135
136 {{panel bgColor="#d8e4f1"}}
137
138 \\ !4. Config Overview.png|align=center!\\
139 \\
140 \\
141
142 {{/panel}}
143
144 5. Double check, and open the .eogen file using open with > text editor. The whole command must all be on a single line; this is formatted for clarity:
145
146 {{panel bgColor="#d8e4f1"}}
147
148 {code}
149 1. -destination Sources
150 -java
151 -javaTemplate _Entity.java
152 -model Resources/SF.eomodeld
153 -packagedirs
154 -subclassDestination Sources
155 -subclassJavaTemplate Entity.java
156 -templatedir templates
157 -verbose
158 {code}
159
160 {{/panel}}
161
162 6. If you are not seeing your entity files that start with the underscore character "//" in Eclipse, it is because you have them filtered out. Select filters from the down triangle in the package explorer~://
163
164 {{panel bgColor="#d8e4f1"}}
165
166 \\ !select.png|align=center!\\
167 \\
168 \\
169
170 {{/panel}}
171
172 7. Then uncheck 'EOGenerator Files':
173
174 {{panel bgColor="#d8e4f1"}}
175
176 \\ !filters.png|align=center!\\
177 \\
178 \\
179
180 {{/panel}}