Chapter 4. Model manipulation in Kermeta

This section illustrates some importants steps in order to succesfully manipulate the metamodel in Kermeta. This is about why to register your metamodel and how to load/save it.

4.1. Serialization

Thanks to the persistence library, you can serialize (save and load) models. The persistence library is inspired from the resource manager of EMF models. There is a repository (called EMFRepository) containing a set of resources (the EMFResources). Each resource contains a reference called instance which contains all the root classes of the loaded model (there is usually one root class). So, the procedure of creation of a resource that will handle EMF models is the following :

  1. Instanciate an EMFRepository;

  2. Create a new EMF resource in this repository;

  3. Load this resource;

  4. Get the instances, i.e. the root class(es). All other instances can then be accessed by navigating the root class(es) properties.

[Note]Note

FSM tutorial provide code example (section 5.3) to illustrate this model serialization in Kermeta

4.2. Package registry

In order to link the instance file with its meta-model, a relative path (nsURI) should be provided. So, after the creation of the metamodel, we need to register this metamodel into the EMF Package Registry. In deployed mode (ie. in a runtime workbench), the ecore is automatically registered by the plugin. In development mode, you need to manually register it.

There is two ways to do that :

  • deploying an EMF plugin which add permanently the meta model to the Eclipse's EMF Package Registry;

  • registering dynamically the meta model on it.

[Note]Note

Take look at the example below if you want to know how to register a matamodel :