-
Notifications
You must be signed in to change notification settings - Fork 6
TP1 ((meta(meta))model
Some resources are available in the "TP1-solution" folder, including:
- spreadsheet.ecore (tableur metamodel, see Question 1)
- xmi files (tableur models, see Question 2)
- model transformation (for Ecore files, e.g., spreadsheet.ecore, see Question 3)
- model transformation (for tableur models, see Question 4)
Model transformations are written in Xtend. EcoreHelper.xtend implements flat, short, and flatShort as well as the case with identifiers. TestEcoreHelper.xtend shows how it works on spreadsheet.ecore but in fact it can work on any metamodel written in the Ecore language.
TestEcoreHelper.xtend also shows how to process an XMI file (here a tableur model). Before processing an XMI file, we need to generate a Java API from the metamodel (here spreadsheet.ecore). A great resource is this article: http://eclipsesource.com/blogs/tutorials/emf-tutorial/ The basic steps are as follows:
- generate a .genmodel from the .ecore file
- from the .genmodel generate the API
- use the generated API
In the repository I have already included the generated artefacts (in TP1_Solution.edit, TP1_Solution.editor, TP1_Solution.tests). There is also the .genmodel included. Please refer to http://eclipsesource.com/blogs/tutorials/emf-tutorial/ for further information.
The specific code for loading the XMI file is very technical and not that interesting. The basic idea is to register a factory (for ".xmi" files) and then load the resource. The return type is "Tableur" (the root class of spreadsheet.ecore)
def Tableur loadTableModel(String path) {
//Load an instance of spreadsheet MM (a model of a tableur, xmi format)
doEMFRegistration()
var res = new ResourceSetImpl().getResource(URI::createURI(path), true);
res.contents.get(0) as Tableur
}
def doEMFRegistration() {
SpreadsheetPackage.eINSTANCE.eClass();
val reg = Resource.Factory.Registry.INSTANCE;
val m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
}