0

I have created the ecore file for basic family and i have generated the model,edit and editor code and i run the application now i am able to create the family model file in the run time.But now i want to read that model file to get the serialized objects stored in the family model file.

Model file is of type

?xml version="1.0" encoding="UTF-8"?

NVN
  • 107
  • 1
  • 13

2 Answers2

0

This is a plain EMF question (I mean, it's not Sirius-related). If you are new to EMF, this references some documentation. In particular, this PDF is a sample chapter of the "EMF book", which gives a high level overview of the framework. In particular, the section called Object Persistence should answer your question (in particular the code snippet on page 31 which shows how to load a resource/model in memory).

pcdavid
  • 306
  • 1
  • 4
0

If you have a basic family metamodel and if you have generated its model, edit and editor code and if you have created a ".basicfamily" model from it, you could read it using this piece of code:

URI uri = URI.createURI(new File("path of your file").getAbsolutePath());
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(BasicfamilyPackage.eNS_URI, BasicfamilyPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("basicfamily", new XMIResourceFactoryImpl());
Resource resource = resourceSet.getResource(uri, true);
List<EObject> contents = resource.getContents();
// now you can iterate on the root objects of your model, use EObject#getContents() to
// retrieve the children of an EObject and thus navigate in your data

If this code is running in an Eclipse plugin with your metamodel installed, some parts of this code may not be necessary (the addition of the basic family EPackage in the package registry and the registration of the resource factory) since they are handled by the plugin.xml of the generated projects.

sbegaudeau
  • 1,504
  • 13
  • 18