How to create a metamodel
Build date: 3-November-2006
Abstract
This tutorial is part of a serie of tutorials that explain step by step one of the aspect of Kermeta. This one will explain you how to a metamodel to be used by kermeta. However, there are many ways to create them, this tutorial will present some of them.
Table of Contents
Kermeta is a Domain Specific Language dedicated to metamodel engineering. It fills the gap let by MOF which defines only the structure of meta-models, by adding a way to specify static semantic (similar to OCL) and dynamic semantic (using operational semantic in the operation of the metamodel). Kermeta uses the object-oriented paradigm like Java or Eiffel. This document presents various aspects of the language, including the textual syntax, the metamodel (which can be viewed as the abstract syntax) and some more advanced features typically included in its framework.
![]() | Important |
|---|---|
| Kermeta is an evolving software and d espite that we put a lot of attention to this document, it may contain errors (more likely in the code samples). If you find any error or have some information that improves this document, please send it to us using the bug tracker in the forge: http://gforge.inria.fr/tracker/?group_id=32 or using the developer mailing list (kermeta-developers@lists.gforge.inria.fr) Last check: v0.3.1 |
![]() | Tip |
|---|---|
| The most update version of this document is available on line from http://www.kermeta.org . |
No particular background is necessary to read this tutorial.
![]() | Important |
|---|---|
| KerMeta must be installed. If not, please refer to "How to install KerMeta" tutorial. |
There are two ways to create a KerMeta meta model. The first one is to start from scratch just by creating a ".kmt" file. The second one is to create an Ecore file and then to transform it into a KerMeta meta model.
This tutorial should help you in manipulating the Ecore and KerMeta files. It gives an overview on how to create meta models and how to transform them.
Start by creating a new general empty project in Eclipse.
Select in the main menu of Eclipse
"File" > "New" >> "Other..."
This action opens the following window.
Select "New Kermeta file" and press "Next >".
Give a name (MyMetamodel.kmt for instance) to the new file, select a location (The default one is good for us) and leave Main class and Main operation blank for the moment. It will be used later to run models. Click on "Finish".
Now your main window should look like the one above. The file is written in KerMeta language. So you can edit this file to add some classes, attributes and so on using the KerMeta language (read http://www.kermeta.org/documents/manual/ for more details on KerMeta language).
Create an Ecore file. In the main menu of Eclipse select :
"File" > "New" >> "Other..."
Select "Ecore model" wizard and click "Next >". Select a location and a name for the file. Call it "AnOtherMetamodel.ecore" for example. Click on "Finish".
Your main window now looks like this :
You can edit this meta model. If you do not know how to do that, please visit the following link :
![]() | Important |
|---|---|
| You must at least fill in the name, ns prefix and ns URI of the package. |
Let us say that you edited this meta model and now you want to add some behaviors. Then you must transform the Ecore meta model into a KerMeta meta model. Right click on "AnOtherMetamodel.ecore" and select "KerMeta" and "Generate Kermeta source".
Do not pay attention to the dialog box alerting you that this is not a stable process. The following window appears :
Choose a name for the new KerMeta meta model. The default one is correct for us. So just click on "Finish".
Now your main window looks like this one :
Several transformations are available. This may appear complex but this is not. Actually, you can switch the representation of your meta model from one format to another. If you prefer coding, then you will probably prefer the kmt format (KerMeta text). Otherwise you will design with the reflexive editor and the km files (serialized files).
So transformations give you the ability to adapt the meta model to your preferred point of view : coding view or graphical view.
kmt meta model to km meta model
From a ".kmt" file, you can generate a "km" file more appropriate to design your meta model because it allows you to edit with the reflexive editor and later a graphical editor (We are working on it).
To do that, right click on "MyMetamodel.kmt" and select "Kermeta" and "Compite to Kermeta mode"l. Choose a file name and click on "Finish" (The default name is good). If you chose the default name, then double click on "MyMetamodel.km". Normally it opened the file thanks to the reflexive editor.
![]() | Tip |
|---|---|
| If not, right click on "MyMetamodel.km" and select "Open With" and "Reflexive Editor". |
km meta model to kmt meta model
Because ".km" and ".kmt" files are describing the same meta model, you can transform a ".km" file into a ".kmt file" and vice versa.
Right click on "MyMetamodel.km" file and select "Kermeta" and "Generate Kermeta Source". Choose a name and click on "Finish".
kmt meta model to Ecore meta model
You can generate an Ecore meta model from a ".kmt" file. Right click on "MyMetamodel.kmt" and select "Kermeta" and "Generate Ecore".
Km meta model to Ecore meta model
You can generate an Ecore meta model from a ".km" file. Right click on "MyMetamodel.km" and select "Kermeta" and "Generate Ecore".
![[Important]](http://www.kermeta.org/docs/html.single/KerMeta-How-to-create-a-metamodel/gfx/admonitions/important.gif)
![[Tip]](http://www.kermeta.org/docs/html.single/KerMeta-How-to-create-a-metamodel/gfx/admonitions/tip.gif)








