by Dr. Durant
Dr. Welch developed an EA6/C++ hints document, upon which this one for EA7/Java is based.
Here are some things I learned while doing code generation in Enterprise
Architect. I hope you find this useful.
- Enterprise Architect (EA) Basics
- Most of the EA dialogs have context sensitive help buttons that are helpful
- Set-up a local map for your source code (and perhaps more) from Settings | Local Paths ...
- Create symbolic names for localized paths
- Each developer can have their own working directories as each EA user keeps their own Local Paths
- During saves any paths that match have the symbolic name substituted
- During load the symbolic name is replaced with the localized path
- If one developer uses Local Paths all should
- Path: D:\My Documents\cs489\CodeCounter\src, ID: srcRoot, Type: Java (Everyone sets srcRoot according to his or her preferences)
- Set-up EA Code Engineering Properties
- Tools | Options (Ctrl-F9)
- Select Source Code Engineering | Attribute/Operations
- Select all options but "On reverse synch, delete model associations not
in code"
- Assign classes to your target directory (e.g., src directory for Java)
- Right-click each class and select Generate Code
- Click ... and select the location for the source code (if you placed the class in a package using EA [e.g., via a Package diagram], indicate the appropriate subdirectory [e.g., yourWorkspace\ProjectName\src\packageName])
- Confirm that the Target language is correct
- Select Generate to do the initial generation or generate the group of classes all together (Select all and hit F11 -- EA sometimes reverts to an old path if you use this batch generation method, so double-check its output, especially if you change paths mid-project)
- Note: Although EA is a round-trip CASE tool, you can not simultaneously make changes in both the model and the code and retain both...
- If you make changes to the code, be sure to save them (so they are committed to disk and visible to EA) and use EA's Synchronize Model with Code option to bring the code changes into the model. (It is not necessary to do this for added comments, after filling in method stubs, etc. -- only for changes to the class structure [new methods, changing argument types, removing attributes, etc.]. However, since EA recognizes Javadoc comments, you should do this if you add documentation in this format so that it is visible and editable in EA.)
- If you make changes to the model, you can push them into the code using Generate Code (F11).
- Creating the project in Eclipse (instructions based on version 3.3)
- Bring up the new Java Project dialog in Eclipse
- Enter the project name that matches the generation directory you created in EA
- A warning that "a resource with the project name already exists" should appear; this indicates that you have the locations matched between EA and Eclipse
- Change "Contents" to "Create project from existing source" and select the project's root folder (one level above the "src" directory)
- Click Next and confirm that your source files show up in your project.
- Click Finish to create the project
- Caveats
- EA isn't really good at making code changes when attributes and
association role types change in the model
- If it isn't working, simply delete the old declaration from the
source code and then generate the code again
- Recommendations:
- Take full advantage of the "Notes" fields provided in the EA Properties windows. These not only help describe your model but the
text is exported as comments in the appropriate place in your source code. For example, for Java, class, method, argument, and attribute descriptions generate (and can be synchronized from) Javadoc comments in the source code.
This is a nice feature.