Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » ATL transformation from EObject
ATL transformation from EObject [message #907097] Mon, 03 September 2012 09:31 Go to next message
José Miguel P. is currently offline José Miguel P.Friend
Messages: 66
Registered: March 2010
Member

Hello!

First all, thank you for your help and your time!

I'm trying execute an ATL transformation from Java, I have found some information and examples here:

http://wiki.eclipse.org/ATL/Developer_Guide#Core_API
https://github.com/101companies/101repo/blob/master/contributions/atl/src/atl/RunTransfoJava.java

but I only have found examples, where the input/output models are in a file. In my case, I have the input models in EMF EObject and I would like have the output model also in a EObject.

Is there any way for to do it? Where can I see an example?

Thanks you very much!!

José Miguel.
Re: ATL transformation from EObject [message #907101 is a reply to message #907097] Mon, 03 September 2012 09:43 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

When dealing with EMF, ATL makes use of the standard ways for identifying/locating resources (in this case models).
You can take a look to the Javadoc of the ATL EMFInjector.inject (or EMFExtractor.extract) method to see the different possibilities (file in the file system, EMF URI, workspace resource, plugin resource).
Note that in EMF the base container (model) is a Resource stored in a ResourceSet, and not an EObject which has to be stored in a Resource.

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: ATL transformation from EObject [message #907190 is a reply to message #907101] Mon, 03 September 2012 13:38 Go to previous messageGo to next message
José Miguel P. is currently offline José Miguel P.Friend
Messages: 66
Registered: March 2010
Member

Hello Hugo

Thanks so much for your reply and for the execution Java example. It have been very usefull.

I have been looking those method, but all of them are looking for a file. I have seen the follow form:

 public void inject(IModel targetModel,
                   java.io.InputStream source,
                   java.util.Map<java.lang.String,java.lang.Object> options)
            throws ATLCoreException


Perhaps I can get a InputStream from the Resource of my model and use it.

Thanks Very Happy
Re: ATL transformation from EObject [message #907205 is a reply to message #907190] Mon, 03 September 2012 14:18 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
If you handle an EMFInjector, you have several implementations of the "inject" method, for instance:

  • inject(IModel targetModel, String source, Map<String, Object> options) - the "source" parameter can be an EMF URI (among other possible options as I told you before, cf. the Javadoc of that method)
  • inject(IModel targetModel, Resource mainResource) - the "mainResource" parameter directly corresponds to the EMF model you want to load

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: ATL transformation from EObject [message #908937 is a reply to message #907205] Thu, 06 September 2012 09:08 Go to previous messageGo to next message
José Miguel P. is currently offline José Miguel P.Friend
Messages: 66
Registered: March 2010
Member

Hello Hugo.

Thanks for your reply. I was not seen this method because I was using EMFInjector form the interface IInjector, and there, this method don't exists.

I have been trying this form of inject a model (inject(IModel targetModel, Resource mainResource)) but I don't know what happen, It's not working::

For test it, I have create a very simple metamodel, and I have instance it using EMF:

Persona p = MailFactory.eINSTANCE.createPersona();
p.setName("Jose");
p.setEmail("jose@jose.com");
			
Persona p2 = MailFactory.eINSTANCE.createPersona();
p2.setName("Marta");
p2.setEmail("marta@marta.com");
			
Mail m = MailFactory.eINSTANCE.createMail();
m.setMessage("hello, how are you?");
m.setFrom(p);
m.getTo().add(p2);



Them I create a resource, and I add this model to it.

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createURI("file:/home/jozemi/output.prueba"));
resource.getContents().add(m);


(I don't registry the extension and other, because I thinks it's not necessary for the example, Isn't it?)


Well, I have a very short transformation only for try:

When I use this method:

IModel mailModel = modelFactory.newModel(mailMetamodel);
injector.inject(mailModel,resource);


It's like if may model was empty, however, if I persist the model:


try {
resource.save(null);
} catch (IOException e) {
e.printStackTrace();
}


And I use this other form:

IModel mailModel = modelFactory.newModel(mailMetamodel);
injector.inject(mailModel,"file:/home/jozemi/output.prueba");


It works perfectly.

I don't know if I'm forgetting something or I'm doing something wrong Sad

Thanks in advance for your time Very Happy

Best regards,

José Miguel.
Re: ATL transformation from EObject [message #909164 is a reply to message #908937] Thu, 06 September 2012 16:54 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

Both methods should give the same behavior in theory.
Maybe there is a small bug here, could you please raise a new Bugzilla bug explaining this?

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: ATL transformation from EObject [message #909492 is a reply to message #909164] Fri, 07 September 2012 08:31 Go to previous message
José Miguel P. is currently offline José Miguel P.Friend
Messages: 66
Registered: March 2010
Member

Done.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=389028

Thanks you for all!
Previous Topic:Metamodel to metamodel transformation
Next Topic:Troubles with ATL API
Goto Forum:
  


Current Time: Thu Apr 18 11:50:31 GMT 2024

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

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

Back to the top