EMF-OCL Documents
Eclipse Modeling Framework & Objects Constraint Language Documents
EMF-OCL Documents 
Generating an EMF 1.1 Model

Generating an EMF Model with Object Constraint Language

This tutorial is a step-by-step description of the process of creating an EMF model with additional constraints and generating a simple model editor for it. Following this tutorial will show how easy EMF makes it to go from a simple model definition to a fully functioning editor for that model.

The screenshots are based on version 2.1 of the Eclipse SDK and version 1.0 of EMF-OCL plugin

The model we will generate looks like this in UML :

Library UML model context Book
inv: pages>0

context Book
inv: library.writers->includes(author)

We're going to show how an EMF-OCL model can be generated from an UML diagram (+ constraints)

Contents

Step 0: Prerequisites
Step 1a: Create an EMF project
Step 1b: Create an Ecore Model
Step 1c: Add the OCL constraints
Step 2: Generate the EMF Model Code
Step 3: Generate an Editor for the Model
Step 4: Run the Generated Editor


 contents

Step 0: Prerequisites

After installing the plugin package, verify that it is available in your Eclipse environment:


 contents

Step 1a: Make the Model

We're going to build the Ecore model using the eclipse interface. (library.ecore)


 contents

Step 1b: Create an Ecore Model

  • Right-click on "Library/src" and Bring up the "New/Other..." dialog
    other project
     
  • Select "Example EMF Model Creation Wizards", choose "Ecore Model" and click on "Next"
    EMF Project
     
  • Enter the File name and click on "Next"
    File name
     
  • Choose the Model Object "EPackage" and click on "Finish"
    epackage
     
  • Give a name to your EPackage. Here it is "Library".
    epackage name
     
  • Add a class to your model. Here it is "Library".
    add classes
     
  • Change the name of the class. (use the "help/Show View/Other/Basic/Properties" dialog if you don't have the window with properties)
    change properties
     
  • Do the same for other classes.
    You should have the following classes: (Library,Book and Writer)
    classes
     
  • Add an EEnum for the different types of books and give a name
    enumeration

    enumeration name
     
  • Add an EEnum Literal by type of book, give a name and a value by EEnum Literal
    literal

    literal name
     
  • Global view of Library.Ecore at this step:
    globalview1
     
  • Create the EData Type (Int, String for example) and put the correct OCLtype
    Edatatype

    Edatatype properties
     
  • Add EAttributes and change their properties (name, bounds, Etype, ...)
    attributes

    attributes properties
     
  • Add the different EReferences and change their properties:
    ereferences

    ereferences properties
     

  •  contents

    Step 1c: Add the OCL Constraints


     contents

    Step 2: Generate the EMF Model Code

    Create the GenModel:


     contents

    Step 3: Generate an Editor for the Model

    A fully functional Eclipse editor can also be generated for any model. By default, it is split between two plugins: an "edit" plugin includes adapters that provide a structured view and perform command-based editing of the model objects; an "editor" plugin provides the UI for the editor and wizard.

    In general, if you wish to generate the model, edit, and editor plugins in a single step, you can do so by selecting "Generate All" from the pop-up menu.

    The code should be compiled automatically as it is generated, and should recompile whenever it is changed. If you have disabled automatic building in the workbench preferences, you can initiate compilation manually:


     contents

    Step 4: Run the Generated Editor

    In order to run plugins in a runtime workbench, a lunch configuration must first be set up:

    A runtime workbench can be launched from the "Launch Configurations" dialog by clicking on the "Run" button. Once the launch configuration has been set up, it can also be launched from the "Run" button on the toolbar.

    The library model wizard can now be used to create a new instance of the model.