Wiki source code of WOLips EOGenerator

Version 28.1 by David Avendasora on 2011/05/24 12:57

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