Architected Futures™

Tools and strategies ... for boiling the ocean

Create the Ecore Model

Procedure

The Ecore model is essentially a UML model defining the classes and relationships (associations) needed to define the data within an application. It is used to generate the Java code for an application which provides the ability to view and edit the information based on the the described model.

  1. Create an empty modeling project in the workspace. From the workbench main menu, Select File -> New, then click Other. This opens a New wizard. In the wizard, click the arrow to the left of Eclipse Modeling Framework to expand the offerings. Click on Empty EMF Project. Then click Next.
    New Project Wizard
  2. Give the project a name. Then click on Finish.
    Specify Project Details
  3. Next we want to create an "Ecore" specification file defining the actual core information structure for the application. In the workbench project folder which we just created, expand the folder and right click on the sub-folder named model. A popup window should open, select New, then click Other. This again opens a New wizard. In the wizard, in the Eclipse Modeling Framework group, click on Ecore Model. Then click Next.
    New Ecore Model Wizard
  4. The file should already be positioned into the correct folder. Give the model a name. Then click on Finish.
    Specify Ecore Model location and name
  5. After the Ecore Model create step is finished you are returned to the workbench with two changes. First, the model has now been added to the elements in the Package Explorer. Second, a new Editor window has been opened in the default, tree-based, editor mode.1
    Ecore Model Editor Window
  6. Next we need to begin to define the content of the model. Clicking on the arrow icon to the left of the model in the Editor causes the contents to expand. At this point there is no content, so clicking on the arrow causes a single child icon to appear without a name. This is the root package of the model. Double clicking on the child icon causes a Property View for the element to appear with labels for three properties, all with empty values. We need to give the root package a name and a URI. When the data is supplied in the Properties View it will be automatically updated in the Editor window.
    Root Package Properties
  7. Once the root package is defined, detail information elements can be defined as children of the root package. Right-clicking on the root package opens a dialog window. Select New Child and click on EClass. This creates a new node, indicated by an indented EClass icon, on the model tree and the Properties View changes to reflect the new EClass item. Provide the EClass element with a name. By convention EClass names should start with a capital.
    New Class Defined
  8. Right-click on the newly defined EClass element in the tree to bring up a context menu. Select New Child and click on EAttribute. This creates a new indented node and a new Properties View for the EAttribute. Provide the EAttribute element with a name. By convention EAttribute (and EReference) names should start with a lower case. Click in the EType field entry for the EAttribute and a dropdown indicator should appear at the far right of the field. Click the dropdown and select the appropriate data type for the element.
    New Attribute Defined
  9. Add more attributes and add more classes. There is no need at this point to complete the full application information model definition. One of the aspects of this exercise is to demonstrate the ability to modify the model after code has been generated, and then to re-generate the code. In the context of defining classes, there are two types of elements we may want to add to the classes we create:
    • EAttribute - these define routine attributes of the class. They define data elements which are internal to a class element.
    • EReference - these define connections or associations between two classes. Rather than a data type, the EType of an EReference defines the ECLass that it is a reference to.
      Initial Model Tree View
  10. Save your changes using File -> Save from the menu bar.If you prefer graphical editing of the model, a graphical view can be created from the tree view of the model. Right-click on the model in the Package Explorer and then click on Initialize Ecore Diagram File...  to bring up the Diagram File wizard.
    Diagram File Wizard
  11. Accept the default names and click Finish. There will now be a new entry in the Package Explorer for the diagram editor and a new Editor window will be opened with a graphical version of the model. You may now edit the model by adding, changing or deleting classes, attributes, references, etc. through this view of the model. You can also move the classes and references around to make your diagram easier to understand. Changes made in the graphical editor view of the model will be reflected back in the tree view of the model once the model has been saved. Note: If you decide to switch between the two methods of editing the model, be sure to save your changes in the editor you are working in before moving to the other editor.
    ECore Model Diagram Editor
    If you want to use the graphical editor it is usually a good idea to start early before you build up too many relationships (references) in the model. A diagram the is generated with a model that has lots of relationships may be hard to figure out and rearrange so that it makes sense. It is usually easier to adjust the composition of the diagram slowly as the model is built.

References

 

  • 1. Other options include graphical modeling, textual modeling, Java annotations and importing from UML tools.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.