|
Re: programmatic access to the Sirius model via the EMF API [message #1779078 is a reply to message #1779038] |
Tue, 02 January 2018 09:19 |
Pierre Guilet Messages: 250 Registered: June 2017 |
Senior Member |
|
|
Hi,
If you want to know more about how to use EMF API I highly suggest you reading http://www.informit.com/store/emf-eclipse-modeling-framework-9780321331885
If you want support about how to use the API, the EMF Eclipse forum is more appropriate.
In short, one very simple way to access your own ecore metamodel:
File file = new File(pathToMyEcoreFile);
ResourceSet rs = new ResourceSetImpl();
rs.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE );
Registry r = rs.getResourceFactoryRegistry();
Map<String,Object> m = r.getExtensionToFactoryMap();
m.put("ecore",new XMIResourceFactoryImpl());
URI uri = URI.createFileURI(file.getAbsolutePath());
Resource resource = rs.getResource(uri, true);
The resource contains your metamodel.
The root element is accessible with resource.getContents()
Call this code from a java class in an Eclipse plug-in declaring as dependency the plugin with your metamodel and emf.ecore plugins. Your metamodel plugin can be in the same eclipse instance than your calling plugin.
It works exactly the same with Sirius <.aird> models created with Sirius editors.
You just have to use the right package and extension name.
Though you have some helpers in Sirius allowing to load the session represented by the .aird file.
In your plugin loading models you must add a dependency to org.eclipse.sirius to use it:
Session session = SessionManager.INSTANCE.getSession(airdFileUri, new NullProgressMonitor());
In pure Sirius your session will be a DAnalysisSessionImpl so you can cast it as such to be able to extract contents from EMF API.
Regards,
Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
[Updated on: Tue, 02 January 2018 09:48] Report message to a moderator
|
|
|
|
Re: programmatic access to the Sirius model via the EMF API [message #1779260 is a reply to message #1779210] |
Thu, 04 January 2018 14:52 |
Pierre Guilet Messages: 250 Registered: June 2017 |
Senior Member |
|
|
Hi,
Sorry for the misunderstanding,
Ecore is a metamodel and .ecore files contains the instance models. So to access your models instances it works the same. Just replace what is relative to Ecore metamodel by yours and point at your model instance file. For example with a metamodel producing model instance file with extension "myextension" (file.myextension)
File file = new File(pathToMyEcoreFile);
ResourceSet rs = new ResourceSetImpl();
rs.getPackageRegistry().put([b]MyCustomMetamodelPackage[/b].eNS_URI, [b]MyCustomMetamodelPackage[/b].eINSTANCE );
Registry r = rs.getResourceFactoryRegistry();
Map<String,Object> m = r.getExtensionToFactoryMap();
m.put("[b]myextension[/b]",new XMIResourceFactoryImpl());
URI uri = URI.createFileURI(file.getAbsolutePath());
Resource resource = rs.getResource(uri, true);
For the Sirius part, the Sirius model instances from Sirius metamodels are the .aird files in your modeling projects. They contains graphical representation information of your models. But Sirius uses EMF API to create, access and modify your model. There is nothing specific to Sirius regarding your models.
In conclusion, the first solution with some adaptation specific to your metamodel allows you to read your models from EMF API independently from Sirius.
The second one give you the Sirius object representing the Sirius model instance (Session) containing graphical information and referencing used models of yours as semantic resources. So you can also access your models from the Sirius one with the Session API getSemanticResources() method.
Regards,
Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Powered by
FUDForum. Page generated in 0.03178 seconds