Wiki source code of EOGenerator

Version 27.1 by David Avendasora on 2011/05/25 13:05

Show last authors
1 The WOLips EOGenerator is an integral part of WOLips and shares its codebase with Entity Modeler. It uses release 1.5 of the [[Velocity Templating Engine>>http://velocity.apache.org]] and template files that use the [[Velocity Template Language>>http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html]]. This templating language is similar to the original Rubicode EOGenerator that many developers used with WebObjects 5.3 and earlier so migrating old templates to the new language is time consuming, but not difficult.
2
3 === Default Setup ===
4
5 If you don't specify a custom template name in your .eogen file, then the WOLips EOGenerator will simply use the built-in ones. This is the way all developers should start out. You can always grab those templates and modify them, or use some of the many modifications shared by other WebObjects developers on the [[WOL:EOGenerator Templates and Additions]] page.
6
7 === Customizing ===
8
9 There are two ways: create eclipse-wide settings, or create settings per project.
10
11 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...//
12
13 ==== eclipse-wide settings for EOGeneration ====
14
15 ~1. Download the templates that Mike Schrag made from [[http://webobjects.mdimension.com/wolips/EOGenerator/Velocity%20EOGenerator%20Templates/]]
16
17 and place them in a folder. In my case that was in
18
19 /Applications/Developing/VelocityEOGeneratorTemplates
20
21 Inside this folder you will have two standard templates: Entity.java en Entity.java. Do not change them for the moment.
22
23 (Additional templates and a reference are available [[here>>EOGenerator Templates and Additions]])
24
25 2. Go to Preferences > WOLips > EOGenerator
26
27 In EOGenerator Template Folder, fill in the folder you have placed the templates
28 In EOGenerator Java Template fill in Entity.java
29 In EOGenerator Subclass Java Template fill in Entity.java
30
31 This is how it looks in my settings:
32
33 {{panel bgColor="#d8e4f1"}}
34
35 \\ !VEOGeneratorSettingsEclipse.png|align=center!\\
36 \\
37 \\
38 \\
39
40 {{/panel}}
41
42 3. Go to the eomodel from which you want to create classes and subclasses in the WOPackage sidebar of Eclipse
43
44 4. Right click and choose WOLips Tools > Create EOGenerator File from the contextual menu, (it's a submenu)
45
46 {{panel bgColor="#d8e4f1"}}
47
48 \\ !CreateEOGenContextualMenu.png|align=center!\\
49 \\
50 \\
51 \\
52
53 {{/panel}}
54
55 Now a eogen file is created which has the name of the EOModel and an .eogen extension.
56 If there is already an eogen file, then another one will be created, with a number between the EOModel name and the extension.
57 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).
58
59 {{panel bgColor="#d8e4f1"}}
60
61 \\ !MoreEogenfiles.png|align=center!\\
62 \\
63 \\
64 \\
65
66 {{/panel}}
67
68 5. Go to the eogen file, right click and choose EOGenerate... from the contextual menu.
69
70 {{panel bgColor="#d8e4f1"}}
71
72 \\ !EOGenerateContextualMenu.png|align=center!\\
73 \\
74 \\
75 \\
76
77 {{/panel}}
78
79 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.
80
81 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.
82
83 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.
84
85 7. If you are fine, you can start fine tuning your templates, or start defining templates per project.
86
87 ==== making Velocity EOGenerator settings per project ====
88
89 ~1. Under Preferences > WOLips > EOGenerator
90 ~> Remove all entries (this is not strictly necessary, but it rules out any errors at the project level)
91
92 {{panel bgColor="#d8e4f1"}}
93
94 \\ !1. EOGenerator Project.png|align=center!\\
95 \\
96 \\
97 \\
98
99 {{/panel}}
100
101 2. Add a folder named templates in your project folder, inside of which you place your template files.
102 For starters, don't rename them. You can download them here:
103 [[http://webobjects.mdimension.com/wolips/EOGenerator/Velocity%20EOGenerator%20Templates/]]
104
105 {{panel bgColor="#d8e4f1"}}
106
107 \\ !2. Directory Structure.png|align=center!\\
108 \\
109 \\
110 \\
111
112 {{/panel}}
113
114 Other options for Veogen to pick up any changes you wish to make to the templates:
115
116 * 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.
117 * 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).//,,
118
119 3. Double check your model. It used to be true that none of your entities could extend EOGenericRecord. That is no longer true and you can use either custom classes or EOGenericRecord as a class, or a mix of the two. We suggest that your entity classes should be in packages for this all to work optimally, such as "your//com.projectname.eo//class". If you use a class that is not in a package, there may be a number of errors in the resulting Java class files.
120
121 {{panel bgColor="#d8e4f1"}}
122
123 \\ !3. Entities Snapshot.png|align=center!\\
124 \\
125 \\
126 \\
127
128 {{/panel}}
129
130 4. Create or edit your .eogen file, mine looks like this:
131
132 {{panel bgColor="#d8e4f1"}}
133
134 \\ !4. Config Overview.png|align=center!\\
135 \\
136 \\
137 \\
138
139 {{/panel}}
140
141 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:
142
143 {{panel bgColor="#d8e4f1"}}
144
145 {code}
146 1. -destination Sources
147 -java
148 -javaTemplate _Entity.java
149 -model Resources/SF.eomodeld
150 -packagedirs
151 -subclassDestination Sources
152 -subclassJavaTemplate Entity.java
153 -templatedir templates
154 -verbose
155 {code}
156
157 {{/panel}}
158
159 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~://
160
161 {{panel bgColor="#d8e4f1"}}
162
163 \\ !select.png|align=center!\\
164 \\
165 \\
166 \\
167
168 {{/panel}}
169
170 7. Then uncheck 'EOGenerator Files':
171
172 {{panel bgColor="#d8e4f1"}}
173
174 \\ !filters.png|align=center!\\
175 \\
176 \\
177 \\
178
179 {{/panel}}