Monday, June 30, 2014

Actions in EMF Profiles


Since the Eclipse Modeling Framework (EMF) does not provide any native extension mechanism, the project EMF Profiles was invented as a solution for this problem. So called stereotypes can be used to extend and enrich meta-models. Once a stereotype is defined for a meta-model, it can be applied to models that conform to the respective meta-model. This mechanism, however, does not allow to extend models with additional semantic functionality (i.e., behavior), it only allows to annotate models and to add additional information to them.

The possibility to add semantic functionality to stereotypes in terms of stereotype actions enables developers to invoke the functionality of applied stereotypes in the context of annotated models in order to automate time-consuming and repetitive tasks automatically. Some usage examples include stereotypes and respective actions for model-to-code transformation (Entity Model to SQL, Entity Model to Annotated Java classes) or model-to-model transformation, for example pulling up members to super classes or automatically resolve conflicts in models that have conflict information attached in terms of stereotypes.

Our aim was to invent an easy-to-use extension mechanism for adding such semantic functionality to stereotypes in EMF Profiles.

Creating EMF Profile Actions

The first step is to add an implementation of the action functionality.
  1. Create a meta-model
  2. Create an EMF profile package including stereotypes and actions
  3. Implement and register action handlers

Using EMF Profile Actions

Once a profile is extended with actions, a modeler can take advantage of the provided functionality of the stereotypes.
  1. Create a model based on the meta-model
  2. Apply stereotypes using EMF profiles
  3. Execute actions of the applied stereotypes

Exemplary Use Case: ORM Mapper

For our example we want to create an Object-relational mapper (ORM). The generated function, an automatic creation of SQL code, will be minimal, due to demonstration purpose. In the next steps we create an EMF profile with an action and apply the profile to an existing model for executing the action.

Structure of our exemplary Use Case

Step 1

  1. For the meta-model Ecore can be reused as data modeling language.
  2. Next we have to create an EMF Profile "ORM_Mapper_EMFProfilePlugin" with the required annotations necessary to perform the ORM Mapper functionality including the definition of two stereotypes: Entity and Column. The stereotypes will be applied to EClass instances. The figure shows the finished EMF Profile model. Next we define the action CreateSQL, this action is now available for the whole EMF Profile Project and also requires an identifier. The action must be set in the properties of the desired stereotype, in our case the stereotype Entity.

    EMF Profile with Action CreateSQL

  3. In order to execute an action, a Java class has to implement the Action Handler interface in an Eclipse plug-in project, the "ORM_Mapper_ActionPlugin". It contains the code for the automatic generation of the SQL statements.

    Action Handler Class for generating SQL Code

    For the handler registration the extension point needs to be contributed so that the action identifier is bound to the handling class.
Extension Point with Action Handler Class and Action ID

Step 2

  1. In a further Eclipse instance with the registered EMF Profile, a model, the "ORM_Mapper_model", with a corresponding application of the defined EMF Profile from step 1 has to be created.
  2. The stereotypes can easily be applied through the tree-based Ecore editor.
  3. Model with applied Stereotpyes

  4. Now the option to execute our action is provided and are prompted to select from a list, after right-clicking our class "Dog".

    Available actions for the selected object

     The action has exported the create statements for our model into the "create" file.
Output of the create file

Links to the project:


No comments:

Post a Comment