Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » programmatic access to the Sirius model via the EMF API(I am not sure how the Java clients able to traverse the models created from the Eclipse Modeling Project or created from a Sirius diagram should be created)
programmatic access to the Sirius model via the EMF API [message #1779038] Fri, 29 December 2017 16:26 Go to next message
graph researcher is currently offline graph researcherFriend
Messages: 8
Registered: March 2017
Junior Member
I am following the Sirius tutorials. And my questions regarding this one
https://wiki.eclipse.org/Sirius/Tutorials/DomainModelTutorial
and this one:
https://wiki.eclipse.org/Sirius/Tutorials/StarterTutorial
are:
- what should I do after finishing "Create a new Modeling Project" section of the first one to be able to traverse the eCore model programmatically through the EMF API (perhaps via ECoreUtil.getRootContainer() method to get acces to the root model object) [what kind of the Eclipse project, how created - from which Eclipse instance, how executed,...]?
- are the steps exactly the same in the case of creating the model from the Sirius diagram or the Sirius must be used as a proxy for accessing the model in such the case?
Thank you in advance for the answers.
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 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
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 #1779210 is a reply to message #1779078] Wed, 03 January 2018 21:01 Go to previous messageGo to next message
graph researcher is currently offline graph researcherFriend
Messages: 8
Registered: March 2017
Junior Member
Thank you for your great and quick answer.

My question was however connected to accessing not the eCore metamodel (domain-specific modeling language definition) but the model (the instance of the DSML defined in the form of the diagram with notation defined in Sirius in the form of the eCore model) created in Sirius. I am interested in accessing the model and not the diagram. Sorry if my question was too laconic.

Should I ask the question directly on EMF forum or there are some Sirius-specific issues you may help me to identify before?

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 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
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
Re: programmatic access to the Sirius model via the EMF API [message #1779732 is a reply to message #1779260] Thu, 11 January 2018 21:38 Go to previous message
graph researcher is currently offline graph researcherFriend
Messages: 8
Registered: March 2017
Junior Member
Hi Pierre,
your explanation was very useful and your solution works perfectly. Thank you so much :)
Regards
Previous Topic:Hide a password attribute content
Next Topic:Question about advanced configuration in Sirius
Goto Forum:
  


Current Time: Thu Apr 25 05:05:32 GMT 2024

Powered by FUDForum. Page generated in 0.03643 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top