Introduction
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.
- Create a meta-model
- Create an EMF profile package including stereotypes and actions
- 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.
- Create a model based on the meta-model
- Apply stereotypes using EMF profiles
- 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
- For the meta-model Ecore can be reused as data modeling language.
- 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 - 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.
Step 2
- 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.
- The stereotypes can easily be applied through the tree-based Ecore editor.
- 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.
Model with applied Stereotpyes |
Output of the create file |
Links to the project:
GitHub-Repository: https://github.com/elexx/emf-profiles
Branch: https://github.com/elexx/emf-profiles/tree/emfprofileactions2
ORM Mapper UseCase Example: ORM_Mapper_UseCase.zip
ORM Mapper UseCase Example: ORM_Mapper_UseCase.zip
No comments:
Post a Comment