For a general introduction into Eclipse EMF please see Eclipse Modeling Framework Tutorials
This article focus on the creation of EMF models based on Java interfaces.
This Article For Modeling Base Tutorial.
All Android Tutorials For Beginner And Professional In This Website.
For a general introduction into Eclipse EMF please see Eclipse Modeling Framework Tutorials
This article focus on the creation of EMF models based on Java interfaces.
This Article For Modeling Base Tutorial.
EMF allows to use annotated Java interfaces to define the data model. The annotations used are Javadoc annotations. Each attribute or class that is a part of the EMF model must have a @model tag and may have an optional list of additional attributes.
The @model tag may be followed by additional details about the model element. For example, if an attribute should be read-only (no generation of a set method),the following annotation needs to be added: changeable="false".
The following tags can be used in the @model definition:
Table 1. Java Annotations
| Annotation | Description |
|---|---|
| abstract="true" | Creates a abstract class |
| containment="true" | Express UML2 composition relationships (links with black diamonds). These objects references are saved with the object. |
| default=Value | Default value, can be a constant, enumeration. |
| changeable="false" | No setter will be generated |
We will model a webpage structure with EMF.
Create a new Java project called "sawan.modi.emf.webpage". Create a new folder called "metamodel" which will contain the EMF model.
Create the following interfaces.
package sawan.modi.emf.webpage.model;
/**
* @model
*/
public interface Article {
/**
* @model default=""
*/
public String getName();
}
package sawan.modi.emf.webpage.model;
import java.util.List;
/**
* @model
*/
public interface Category {
/**
* @model default=""
*/
public String getName();
/**
* @model containment="true"
*/
public ListgetArticles();
}
package sawan.modi.emf.webpage.model;
import java.util.List;
/**
* @model
*/
public interface Webpage {
/**
* @model default=""
*/
public String getName();
/**
* @model default=""
*/
public String getTitle();
/**
* @model default=""
*/
public String getDescription();
/**
* @model default=""
*/
public String getKeywords();
/**
* @model containment="true"
*/
public ListgetCategories();
}
package sawan.modi.emf.webpage.model;
import java.util.List;
/**
* @model
*/
public interface MyWeb {
/**
* @model default=""
*/
public String getName();
/**
* @model default=""
*/
public String getTitle();
/**
* @model default=""
*/
public String getDescription();
/**
* @model default=""
*/
public String getKeywords();
/**
* @model containment="true"
*/
public ListgetPages();
}
Create a new EMF meta model "website.genmodel" based on these interfaces in folder "metamodel".
Select your metamodel folder, right click and select Other. Select Eclipse Modeling Framework -> EMF Generator Model
Press next and select the following.
Press next and you should be able to select your package. Change the name of the ecore model to "website.ecore".
Press finish. You have created your EMF model! We will discuss this model in the next chapter.
To use your model in an plugin environment later. Add the util package to your exported packages in MANIFEST.MF on tab Runtime.
Thank you for practicing with this tutorial.
I maintain this tutorial in my private time. If you like the information please help me by donating or by