-
Notifications
You must be signed in to change notification settings - Fork 3
Refactoring the Entity Domain Model
Along the way, I decided that the LinkMap and LinkedContent portion of the Entity domain model could be reused in other models. I refactored that portion of the model into its own ecore model in its own bundle. Don't be afraid of a major refactoring like this. Refactoring happens! It's a good thing! This tutorial will show you how to do this refactoring.
Create a new Empty EMF Project called org.eclipselabs.etrack.domain.links and a new links.ecore. Set the package properties as follows:
- Name: links
- Ns Prefix: org.eclipselabs.etrack.domain.links
- Ns URI: http://www.eclipselabs.org/etrack/domain/links
Right-click in the editor and select Load Resource.... Click Browse Workspace... and select the entity.ecore model. Expand the entity.ecore resource and the entity package. Click and drag the LinkMap and LinkedContent classes to the links package, and save the editor.
Create the genmodel for the links.ecore just as you did for the entity.ecore. Remember to set the following properties on the genmodel:
- Containment Proxies: true
- Suppress Interfaces: true
- Base Package: org.eclipselabs.etrack.domain
Generate the model and edit code. You do not need to generate the editor. Next, right-click on entity.genmodel and select Reload.... Make sure Ecore model is selected and click Next. The wizard will automatically reload the ecore model, so simply click Next. In the root packages section, uncheck links, then click Add... and add select the links.genmodel. Finally, check the Links genmodel in the references generator models section and click Finish.
Right-click on the Entity root node in the entity.genmodel and re-generate the model, edit and editor. You should now see compile errors in all three entity bundles. Open the model MANIFEST.MF and add org.eclipselabs.etrack.domain.links as an imported package. This will fix the compile error in Entity.java. Next, delete LinkedContent.java and LinkMap.java from the entity model package.
Open the entity edit bundle's MANIFEST.MF and add org.eclipselabs.etrack.domain.links and org.eclipselabs.etrack.domain.links.provider as an imported package. Next, delete LinkedContentItemProvider.java and LinkMapItemProvider.java. Finally, open the entity editor bundle's MANIFEST.MF and add org.eclipselabs.etrack.domain.links.util and org.eclipselabs.etrack.domain.links.provider as an imported package.
The refactoring is complete and everything should now compile.