Home » Modeling » GMF (Graphical Modeling Framework) » Sharing the same domain between different diagrams
|Re: Sharing the same domain between different diagrams [message #1718245 is a reply to message #1718164]
||Mon, 21 December 2015 15:10
| Paul C. Brown
Registered: October 2013
What you describe is the default behavior of EMF models. If you have a model element in one resource (file) that has an EMF reference to a model element in another resource, the file containing the element reference will end up with a URL referencing the other element in the other file. This is all managed by the infrastructure that stores and loads resources.
There are, however, two considerations about which you need to be aware, one regarding the URL and the other regarding the nature of the element reference.
With respect to the URL, it is important that you use the URI.createPlatoformResourceURI() method to create the URI for each resource. Doing so will result in relative pathnames, giving your model files some portability. If you use a "file:\\" prefix for your URL, the file locations will be absolute. Your code should look something like:
URI changeResourceURI = URI.createPlatformResourceURI("/CRL/Change.crl",true);
Resource changeResource = resourceSet.getResource(changeResourceURI,true);
A second consideration is the manner in which individual elements are identified within a resource. By default, the reference uses a count of the number of that type of object. In other words, if you have a model class Foo and you have three instances of Foo, your reference will be to the the 1st, 2nd, or 3rd instance of Foo. It's not an issue if all of the resources are loaded all the time, but if your referenced resource gets edited independently, the sequence number may no longer reference the instance you intended.
To avoid this problem, designate one of the element attributes as being an identifier in your EMF model and provide a unique ID. I use guids for mine. That way the identity of the referenced object does not change. Of course, you are now obligated to provide that unique identity.
One more thing to be aware of: the folder structure is baked into the URI, and thus into the references. If you have a reference to an element and you move the file to a sub-folder, the references are now broken. It's not a big deal to edit the file containing the reference to change the pathname, but it's a pain. I have not yet found an automated way of moving the files and fixing up the references.
Current Time: Fri Jun 22 06:00:32 GMT 2018
Powered by FUDForum
. Page generated in 0.02512 seconds