Wiki source code of EOGenerator

Last modified by David Avendasora on 2011/08/25 00:02

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