[Resolved] Import emf model in another [message #716402] |
Wed, 17 August 2011 10:09 |
nicolas h Messages: 60 Registered: February 2011 Location: Grenoble, France |
Member |
|
|
Hi,
I've a little question about emf models.
I've designed a metamodel "myMetamodel", and I created some models conformed to it.
I'm wondering whether I can import a model in another like this :
model1.model conformed to "myMetamodel"
<?xml version="1.0" encoding="UTF-8"?>
<mm:MyMM xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mm="http://myMetamodel/1.0">
<!-- Somes entities from my metamodel -->
<object name="object 1">
<associations links="//@object.2"/>
</object>
<object name="object 2" />
<object name="object 3" />
</mm:MyMM>
model2.model conformed to "myMetamodel"
<?xml version="1.0" encoding="UTF-8"?>
<mm:MyMM xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mm="http://myMetamodel/1.0">
<!-- Something like this -->
<import href="platform:/resource/model1.model" />
<object name="object 4">
<!-- Link object 4 to "object 2" from "model 1" -->
<associations links="//@object.2"/>
</object>
</mm:MyMM>
I wish I imported entities from "model 1" to "model 2" and it was transparent for emf editor and next for generated gmf editor.
Is that possible ?
Regards,
--
Nicolas
[Updated on: Fri, 19 August 2011 08:29] Report message to a moderator
|
|
|
|
Re: Import emf model in another [message #716726 is a reply to message #716474] |
Thu, 18 August 2011 08:51 |
nicolas h Messages: 60 Registered: February 2011 Location: Grenoble, France |
Member |
|
|
Hi Ed,
Thanks for the help.
Cross document references is obviously what I need.
I looked for information about cross document references and I found it inside the EMF-Book second edition p.466-467.
I tried to create an example to test document references, but it doesn't work: my resources were well-created but didn't contain any reference between them.
Below is my restricted metamodel, my java code for test, and the output.
restricted metamodel:
test.java:
public static void main(String[] args) {
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMLResourceFactoryImpl());
URI uri1 = URI.createPlatformResourceURI("/project/subModel1.model", true);
Resource resource1 = rs.createResource(uri1);
SubModel1 root1 = MyMetamodelFactory.eINSTANCE.createSubModel1();
resource1.getContents().add(root1);
try {
resource1.save(System.out, null);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println();
URI uri2 = URI.createPlatformResourceURI("/project/subModel2.model", true);
Resource resource2 = rs.createResource(uri2);
SubModel2 root2 = MyMetamodelFactory.eINSTANCE.createSubModel2();
resource2.getContents().add(root2);
try {
resource2.save(System.out, null);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println();
URI uri3 = URI.createPlatformResourceURI("/project/model.model", true);
Resource resource3 = rs.createResource(uri3);
Model root3 = MyMetamodelFactory.eINSTANCE.createModel();
root3.setSubModel1(root1);
root3.setSubModel2(root2);
/* I also tried this :
root3.setSubModel1((SubModel1)resource1.getContents().get(0));
root3.setSubModel2((SubModel2)resource2.getContents().get(0));
// */
resource3.getContents().add(root3);
try {
resource3.save(System.out, null);
} catch (IOException e) {
e.printStackTrace();
}
}
output:
<?xml version="1.0" encoding="ASCII"?>
<mm:SubModel1 xmlns:mm="http://myMetamodel/1.0"/>
<?xml version="1.0" encoding="ASCII"?>
<mm:SubModel2 xmlns:mm="http://myMetamodel/1.0"/>
<?xml version="1.0" encoding="ASCII"?>
<mm:Model xmlns:mm="http://myMetamodel/1.0">
<requirementModel/>
<analysisModel/>
</mm:Model>
Regards,
--
Nicolas
-
Attachment: example.png
(Size: 5.71KB, Downloaded 287 times)
[Updated on: Thu, 18 August 2011 09:41] Report message to a moderator
|
|
|
Re: Import emf model in another [message #716885 is a reply to message #716726] |
Thu, 18 August 2011 16:58 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Nicolas,
Comments below.
On 18/08/2011 1:51 AM, nicolas wrote:
> Hi Ed,
> Thanks for the help.
> Cross document references is obviously what I need.
>
> I looked for information about cross document references and I found it inside the EMF-Book second edition p.466-467.
>
> I tried to create an example to test document references, but it doesn't work: my resources were well-created but didn't contain any reference between them.
>
> Below is my restricted metamodel, my java code for test, and the output.
>
> restricted metamodel:
>
>
> test.java:
>
> public static void main(String[] args) {
> ResourceSet rs = new ResourceSetImpl();
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMLResourceFactoryImpl());
>
> URI uri1 = URI.createPlatformResourceURI("/project/subModel1.model", true);
> Resource resource1 = rs.createResource(uri1);
> SubModel1 root1 = MyMetamodelFactory.eINSTANCE.createSubModel1();
>
> resource1.getContents().add(root1);
> try {
> resource1.save(System.out, null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> System.out.println();
>
> URI uri2 = URI.createPlatformResourceURI("/project/subModel2.model", true);
> Resource resource2 = rs.createResource(uri2);
> SubModel2 root2 = MyMetamodelFactory.eINSTANCE.createSubModel2();
>
> resource2.getContents().add(root2);
> try {
> resource2.save(System.out, null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> System.out.println();
>
> URI uri3 = URI.createPlatformResourceURI("/project/model.model", true);
> Resource resource3 = rs.createResource(uri3);
> Model root3 = MyMetamodelFactory.eINSTANCE.createModel();
>
> root3.setSubModel1(root1);
> root3.setSubModel2(root2);
>
> resource3.getContents().add(root3);
> try {
> resource3.save(System.out, null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
>
> output:
>
> <?xml version="1.0" encoding="ASCII"?>
> <mm:SubModel1 xmlns:mm="http://myMetamodel/1.0"/>
>
> <?xml version="1.0" encoding="ASCII"?>
> <mm:SubModel2 xmlns:mm="http://myMetamodel/1.0"/>
>
> <?xml version="1.0" encoding="ASCII"?>
> <mm:Model xmlns:mm="http://myMetamodel/1.0">
> <requirementModel/>
These look like they're containment references. To support cross
document containment you have to ensure the reference has resolveProxies
true (which is the case by default) and in the GenModel you have
Containment Proxies also set to true.
> <analysisModel/>
> </mm:Model>
>
>
> Regards,
>
> --
> Nicolas
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Import emf model in another [message #717075 is a reply to message #716885] |
Fri, 19 August 2011 08:27 |
nicolas h Messages: 60 Registered: February 2011 Location: Grenoble, France |
Member |
|
|
Hi Ed,
Quote:These look like they're containment references. To support cross
document containment you have to ensure the reference has resolveProxies
true (which is the case by default) and in the GenModel you have
Containment Proxies also set to true.
Indeed, Containment Proxies was set to false. Setting it to true resolved my issue.
Thank you for your help.
Regards
--
Nicolas
[Updated on: Fri, 19 August 2011 08:28] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03462 seconds