Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] retrieve cross-model-referenced object(problem with java code on retrieving referenced objects )
[EMF] retrieve cross-model-referenced object [message #1282794] Wed, 02 April 2014 20:00 Go to next message
daniele Mising name is currently offline daniele Mising nameFriend
Messages: 48
Registered: July 2009
Member
hello.
I am using an ATL transformation to transform one model (WFG) in two models (SYS, PEER). The two output models are referenced, in the specific an object of SYS has the references "transitions.source" and "transitions.target" to objects of PEER.
When I run the transformation, the path of the referenced model is wrong. I get this:
<systembehavior:SYS xmlns:PEER="http://peerbehavior/1.0" xmlns:SYS="http://systembehavior/1.0">
  <transitions xsi:type="systembehavior:Send">
    <source href="new-model#Participant_1"/>
    <target href="new-model#Participant_5"/>
  </transitions>


instead of this:

<systembehavior:SYS xmlns:PEER="http://peerbehavior/1.0" xmlns:SYS="http://systembehavior/1.0">
  <transitions xsi:type="systembehavior:Send">
    <source href="./mymodel.peer#Participant_1"/>
    <target href="./mymodel.peer#Participant_5"/>
  </transitions>


Anyway.. even if I change manually the href attribute with the right path, I can't retrieve the referenced object in java code.


// register SYS metamodel
EPackage.Registry.INSTANCE.put(SystembehaviorPackage.eNS_URI, SystembehaviorPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("systembehavior", new XMIResourceFactoryImpl());
	
// register PEER metamodel	
EPackage.Registry.INSTANCE.put(PeerbehaviorPackage.eNS_URI, PeerbehaviorPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("peerbehavior", new XMIResourceFactoryImpl());
		
// retrieve a sys object
ResourceSet resSet = new ResourceSetImpl(); 
Resource resource = resSet.getResource(URI.createURI("./sys.systembehavior"), true); 
SystemBehavior sys = ((SystemBehavior) resource.getContents().get(0));

// retrieve peer objects
resource = resSet.getResource(URI.createURI("./peers.peerbehavior"), true); 
EList<EObject> peers = resource.getContents();


In this way I have the sys object in sys, and the peers objects in peers. But sys.getPeers() is a list of peer instances with all the attributes set to null.. so there is no a real reference.
Debugin element sys.getPeers(), I saw that each peer has the attribute eStorage with the right value (something like ./peers.peerbehavior#Participant_5).

How can I load right java instances of Peer into sys?
thank you

[Updated on: Wed, 02 April 2014 20:11]

Report message to a moderator

Re: [EMF] retrieve cross-model-referenced object [message #1283088 is a reply to message #1282794] Thu, 03 April 2014 03:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Daniele,

Comments below.

On 02/04/2014 10:00 PM, daniele Mising name wrote:
> hello.
> I am using an ATL transformation to transform one model (WFG) in two
> models (SYS, PEER). The two output models are referenced, in the
> specific the an object of SYS has a reference 1..* with an object of
> PEER.
> When I run the transformation, the path of the referenced model is
> wrong. I get this:
> <systembehavior:SYS xmlns:PEER="http://peerbehavior/1.0"
> xmlns:SYS="http://systembehavior/1.0">
> <transitions xsi:type="systembehavior:Send">
> <source href="new-model#Participant_1"/>
> <target href="new-model#Participant_5"/>
> </transitions>
>
> instead of this:
>
> <systembehavior:SYS xmlns:PEER="http://peerbehavior/1.0"
> xmlns:SYS="http://systembehavior/1.0">
> <transitions xsi:type="systembehavior:Send">
> <source href="./mymodel.peer#Participant_1"/>
> <target href="./mymodel.peer#Participant_5"/>
> </transitions>
>
> Anyway.. even if I change manually the href attribute with the right
> path, I can't retrieve the referenced object in java code.
The each URI you see in the serialization reflects the URI of the
referenced resource relative to the URI of the referencing resource. So
the fact that you get the first result suggests to me the referenced
resource was named "new-model" and was relatively in the same folder and
the referencing resource.
>
>
> EPackage.Registry.INSTANCE.put(SystembehaviorPackage.eNS_URI,
> SystembehaviorPackage.eINSTANCE);
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("systembehavior",
> new XMIResourceFactoryImpl());
>
> EPackage.Registry.INSTANCE.put(PeerbehaviorPackage.eNS_URI,
> PeerbehaviorPackage.eINSTANCE);
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("peerbehavior",
> new XMIResourceFactoryImpl());
>
> ResourceSet resSet = new ResourceSetImpl(); Resource resource
> = resSet.getResource(URI.createURI("./sys.systembehavior"), true);
That looks like a bad idea. Use absolute URIs for resources, e.g., if
you have a file system path, use File.getAbsolutePath and use
URI.createFileURI from that result.
> SystemBehavior sys = ((SystemBehavior) resource.getContents().get(0));
> resource =
> resSet.getResource(URI.createURI("./peers.peerbehavior"), true);
> EList<EObject> peers = resource.getContents();
>
> In this way I have the sys object in sys, and the peers objects in
> peers. But sys.getPeers() is a list of peer instances with all the
> attributes set to null.. so there is no a real reference.
> Debugin element sys.getPeers(), I saw that each peer has the
> attribute eStorage with the right value (something like
> ./peers.peerbehavior#Participant_5).
By the time you have a proxy URI, that URI should be absolute. EMF
serialization and deserialization will take care for deresolving (to
make serialized references relative if possible) and resolving (to make
the deserialized reference absolute, if necessary). That's only
possible if both URIs are absolute on serialization.
>
> How can I load right java instances of Peer into sys?
Absolute URIs are your answer.
> thank you


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] retrieve cross-model-referenced object [message #1283719 is a reply to message #1283088] Thu, 03 April 2014 19:04 Go to previous messageGo to next message
daniele Mising name is currently offline daniele Mising nameFriend
Messages: 48
Registered: July 2009
Member
Hello Ed,
thank you for your answer. I have tried your solution but it doesn't work. I explain you what I have done:

Quote:
The each URI you see in the serialization reflects the URI of the
referenced resource relative to the URI of the referencing resource. So
the fact that you get the first result suggests to me the referenced
resource was named "new-model" and was relatively in the same folder and
the referencing resource.


No, my referenced model is not named "new-model" . I must change manually it with the right name. Probably it's a default name defined somewhere. I don't know why it doesn't use the real name, since it's defined.


Quote:
That looks like a bad idea. Use absolute URIs for resources, e.g., if
you have a file system path, use File.getAbsolutePath and use
URI.createFileURI from that result.


Ok, so in the sys model I put manually the absolute path of the referenced peer model.

<systembehavior:SYS xmlns:PEER="http://peerbehavior/1.0" xmlns:SYS="http://systembehavior/1.0">
  <transitions xsi:type="systembehavior:Send">
    <source href="/Users/deLac/Desktop/mymodel.peer#Participant_1"/>
    <target href="/Users/deLac/Desktop/mymodel.peer#Participant_5"/>
  </transitions>


and use the the absolute path to retrieve the resource.

ResourceSet resSet = new ResourceSetImpl(); 
	    Resource resource = resSet.getResource(URI.createFileURI(new File("/Users/deLac/Desktop/sys.systembehavior").getAbsolutePath()), true); 
	    SystemBehavior sys = ((SystemBehavior) resource.getContents().get(0));


but it's the same situation as before. I can retrieve the object sys, but the reference to the peer objects it's fake.. objects are not null, but are empty.

If I try to retrieve the object peers, there are not problems, I can retrieve them directly. The only problem is the cross-reference. If I try to retrieve peers from sys, peers are empty (all attributes = null)

[Updated on: Thu, 03 April 2014 19:07]

Report message to a moderator

Re: [EMF] retrieve cross-model-referenced object [message #1283884 is a reply to message #1283719] Thu, 03 April 2014 23:08 Go to previous message
daniele Mising name is currently offline daniele Mising nameFriend
Messages: 48
Registered: July 2009
Member
Oh sorry, you have right! It works ! Let consider SYS a sys object.
If I would do SYS.getTransitions().get(0).getSource() should give me a PEER object. Well, debugging the referenced peer objects are empty, but if I invoke that method I can retrieve the attributes of the Peer object.
Now I get what you meant with
Quote:
EMF serialization and deserialization will take care for deresolving (to
make serialized references relative if possible) and resolving (to make
the deserialized reference absolute, if necessary).

It does the work only when it's necessary, it doesn't recreate all the referenced objects (yeah... obviously). So your solution of using absolute paths it's correct. Many thanks.
Now remains just the problem of why, during the ATL transformation, it uses the "new-model" instead of the real model name I specify as output...

[Updated on: Fri, 04 April 2014 00:41]

Report message to a moderator

Previous Topic:[CDO] exposing the DB name for the DBStore
Next Topic:[oomph] let users open custom setup file
Goto Forum:
  


Current Time: Mon Sep 23 17:44:12 GMT 2024

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

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

Back to the top