Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Xtext as input for ATL M2M
[ATL] Xtext as input for ATL M2M [message #503928] Wed, 16 December 2009 14:06 Go to next message
Tim  is currently offline Tim Friend
Messages: 7
Registered: December 2009
Junior Member
Hi,

I would like to use my file created with Xtext and the ecore meta-model derived from the xtext grammar as input for my ATL M2M transformation. Does anybody have some experience with this?

Currently I receive the error message: " No Resource Found, unable to extract .." So I am wondering if this is at all possible?

Cheers,

Tim
Re: [ATL] Xtext as input for ATL M2M [message #503952 is a reply to message #503928] Wed, 16 December 2009 15:33 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 35
Registered: July 2009
Member
Hi Tim,

Did you try giving as metamodel uri: http://www.eclipse.org/2008/Xtext
and as model the .xmi file in the src-gen directory of your xtext project?

Regards,

Alfons


On 12/16/09 3:06 PM, in article hgaph1$k8b$1@build.eclipse.org, "Tim"
<tim1985z@yahoo.com> wrote:

> Hi,
>
> I would like to use my file created with Xtext and the ecore meta-model
> derived from the xtext grammar as input for my ATL M2M transformation. Does
> anybody have some experience with this?
>
> Currently I receive the error message: " No Resource Found, unable to extract
> .." So I am wondering if this is at all possible?
>
> Cheers,
>
> Tim
Re: [ATL] Xtext as input for ATL M2M [message #503959 is a reply to message #503952] Wed, 16 December 2009 15:53 Go to previous messageGo to next message
Tim  is currently offline Tim Friend
Messages: 7
Registered: December 2009
Junior Member
Hi Alfons,

I made the changes you suggested. But now I receive the error message that certain classes (defined in my metamodel) can not be found in reference model Xtext.

And if I use the .xmi file as model file, what do I do with my actual model. The .xmi was automatically generated from the Xtext. The model that I made afterwards in the created text editor, is probably not incorporated in the .xmi, is it?

Do you have any other suggestions?

Regards,

Tim

[Updated on: Wed, 16 December 2009 16:13]

Report message to a moderator

Re: [ATL] Xtext as input for ATL M2M [message #503988 is a reply to message #503959] Wed, 16 December 2009 17:41 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 35
Registered: July 2009
Member
You will have to provide us with more info on what you are doing.


Alfons


On 12/16/09 4:53 PM, in article hgavp4$52m$1@build.eclipse.org, "Tim"
<tim1985z@yahoo.com> wrote:

> Hi Alfons,
>
> I made the changes you suggested. But now I receive the error message that
> certain classes (defined in my metamodel) can not be found in reference model
> Xtext.
>
> Do you have any other suggestions?
>
> Regards,
>
> Tim
Re: [ATL] Xtext as input for ATL M2M [message #504091 is a reply to message #503988] Thu, 17 December 2009 08:39 Go to previous messageGo to next message
Tim  is currently offline Tim Friend
Messages: 7
Registered: December 2009
Junior Member
I am trying to do apply an ATL M2M transformation to a file created with a text editor created with Xtext.

In order to do that I started with an Xtext project. In that project I changed the available (standard) .xtext file so that I could define my own grammar. Then using GenerateCif.mwe (Cif is the file-extension I have defined), the ecore metamodel, genmodel and .xmi file are automatically created in the src-gen folder of the Xtext project.

When I start a second Eclipse application, so that the plugins I just created are available, I can open a text file in the cif text editor. In this text file I typed the model that I would like to transform. All this goes well, I can even open the model (text file) with Sample Ecore Model editor.

But if I want to transform this model(text file) using an ATL M2M transformation I receive the error that No Resource can be found. I have used the automatically created ecore metamodel in the src-gen folder of the Xtext project as metamodel in the transformation and the model(text file) as input file.

So I think that the problem is that the model(text file) can not be read correctly by ATL. So does anybody have an idea to fix this.

I hope this clarifies the problem.

Regards,

Tim
Re: [ATL] Xtext as input for ATL M2M [message #504119 is a reply to message #504091] Thu, 17 December 2009 11:13 Go to previous messageGo to next message
Guillaume Hillairet is currently offline Guillaume HillairetFriend
Messages: 83
Registered: July 2009
Member
Hi,

Your model needs to be loaded as an XtextResource, you can do it easily in Java, see:
http://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_ a_standalone_Java_application_.3F
Once you got the Resource, you can execute the ATL transformation with the Java ATL API.

Best Regards,
Guillaume
Re: [ATL] Xtext as input for ATL M2M [message #504127 is a reply to message #504091] Thu, 17 December 2009 11:23 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 35
Registered: July 2009
Member
The problem is indeed that you use the text file as input. Somehow you have
to get a hold of the parsed xmi version, which is used behind the scenes by
the the sample reflective ecore editor.
For a simple solution you better ask the xtext guys in the tmf group. A
dirty option is to edit the generated plugins.


Regards,

Alfons

On 12/17/09 9:39 AM, in article hgcqni$281$1@build.eclipse.org, "Tim"
<tim1985z@yahoo.com> wrote:

> I am trying to do apply an ATL M2M transformation to a file created with a
> text editor created with Xtext.
>
> In order to do that I started with an Xtext project. In that project I changed
> the available (standard) .xtext file so that I could define my own grammar.
> Then using GenerateCif.mwe (Cif is the file-extension I have defined), the
> ecore metamodel, genmodel and .xmi file are automatically created in the
> src-gen folder of the Xtext project.
>
> When I start a second Eclipse application, so that the plugins I just created
> are available, I can open a text file in the cif text editor. In this text
> file I typed the model that I would like to transform. All this goes well, I
> can even open the model (text file) with Sample Ecore Model editor.
>
> But if I want to transform this model(text file) using an ATL M2M
> transformation I receive the error that No Resource can be found. I have used
> the automatically created ecore metamodel in the src-gen folder of the Xtext
> project as metamodel in the transformation and the model(text file) as input
> file.
>
> So I think that the problem is that the model(text file) can not be read
> correctly by ATL. So does anybody have an idea to fix this.
>
> I hope this clarifies the problem.
>
> Regards,
>
> Tim
Re: [ATL] Xtext as input for ATL M2M [message #504137 is a reply to message #503928] Thu, 17 December 2009 12:03 Go to previous messageGo to next message
Tim  is currently offline Tim Friend
Messages: 7
Registered: December 2009
Junior Member
Thanks guys,

Hopefully the xtext guys have a simple solution to fix this problem.

Regards,

Tim
Re: [ATL] Xtext as input for ATL M2M [message #505637 is a reply to message #504137] Sun, 03 January 2010 23:05 Go to previous messageGo to next message
Shannon is currently offline ShannonFriend
Messages: 6
Registered: December 2009
Location: Wellington, NZ
Junior Member
Hi Tim,

Did the Xtext guys offer a solution for this problem? This is exactly the issue that I am having.


Cheers,

Shannon

[Updated on: Sun, 03 January 2010 23:27]

Report message to a moderator

Re: [ATL] Xtext as input for ATL M2M [message #505677 is a reply to message #505637] Mon, 04 January 2010 07:58 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 35
Registered: July 2009
Member
Hi Shannon,

Guillaume offered the right solution:

" Your model needs to be loaded as an XtextResource, you can do it easily in
Java, see:
http://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_ a_standalone_Jav
a_application_.3F
Once you got the Resource, you can execute the ATL transformation with the
Java ATL API. "

Although I don't think that directly supplying the loaded model to the ATL
API will work. ATL requires models to be loaded with a internal model
handler. This model handler, in my experience, cannot cope with EMF
generated models.
I created this feature request for the issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=298328

A temporary solution for you would be to store the model to disk first and
then use it in your ATL transformation.


Cheers,

Alfons

On 1/4/10 12:05 AM, in article hhr7rh$1bl$1@build.eclipse.org, "Shannon"
<shannonbay@gmail.com> wrote:

> Hi Tim,
>
> Did the Xtext guys offer a solution for this problem? This is exactly the
> issue that I am having.
>
> Cheers,
>
> Shannon
Re: [ATL] Xtext as input for ATL M2M [message #505723 is a reply to message #505677] Mon, 04 January 2010 16:32 Go to previous messageGo to next message
Guillaume Hillairet is currently offline Guillaume HillairetFriend
Messages: 83
Registered: July 2009
Member
Hi,

Quote:

Although I don't think that directly supplying the loaded model to the ATL
API will work. ATL requires models to be loaded with a internal model
handler. This model handler, in my experience, cannot cope with EMF
generated models.
I created this feature request for the issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=298328

A temporary solution for you would be to store the model to disk first and
then use it in your ATL transformation.



You dont't need to save the model on disk before launching the transformation.
The following code load the model as an XtextResource:

Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(
    URI.createURI("platform:/resource/org.xtext.example.mydsl/src/example.mydsl"), true);


Then you inject this XtextResource into the ATL wrapper for Resource, i.e. EMFModel (emf-vm api) like this:

// Create factory and injector
EMFModelFactory factory = new EMFModelFactory();
EMFInjector injector = new EMFInjector();
// Load the DSL metamodel
EMFReferenceModel metamodel = factory.newReferenceModel();
injector.inject(metamodel, YourDslResource);
// Load the XtextResource as an EMFModel
EMFModel model = factory.newModel(metamodel);
injector.inject(model, resource);
// Launch the transformation as usual
... 
Re: [ATL] Xtext as input for ATL M2M [message #506328 is a reply to message #505723] Thu, 07 January 2010 01:26 Go to previous messageGo to next message
Shannon is currently offline ShannonFriend
Messages: 6
Registered: December 2009
Location: Wellington, NZ
Junior Member
Hm, I couldn't get the ATL wrapper code that Guillaume suggested to work. I guess I don't have that api or something? I'm using the full Eclipse modelling package though so it seems odd.

Anyway, I'm reasonably happy for now... I was able to save the ecore xmi model to disk as Alfons suggested, using the following code:

package org.xtext.example;

import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.xtext.resource.XtextResourceSet;

public class ModelGenerator {

    /**
     * @param args
     */
    public static void main(String[] args) {
        PropStandaloneSetup.doSetup();
        XtextResourceSet resourceSet = new XtextResourceSet();
        URI uri = URI.createURI("src/test.prop");
        Resource xtextResource = resourceSet.getResource(uri , true);
        Resource xmiResource = new EcoreResourceFactoryImpl().createResource(URI.createURI("src/test.ecore"));
        xmiResource.getContents().add(xtextResource.getContents().get(0));
        try {
            xmiResource.save(null);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
               
    }

}


I can then run transformations on that code in either my DSL plugin version of eclipse, if I also copy over the metamodel, or in the normal version.

This is not a long term solution, but for now I am simply evaluating ATL + xText.

Cheers,

Shannon
Re: [ATL] Xtext as input for ATL M2M [message #506629 is a reply to message #506328] Fri, 08 January 2010 12:40 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 35
Registered: July 2009
Member
Shannon,

You should import the right plugins for your project:
- org.eclipse.m2m.atl.engine.emfvm
- org.eclipse.m2m.atl.core.service.CoreService

At least in my setup, I couldnt get Guillaumes code to run yet. I did a
bunch of function calls to the EMFModelFactory to make sure the right
EPackages are registered etc. Now I run into nasty bugs, which im currently
debugging. In my opinion there are like a kazillion ways to use the
CoreService in the wrong way, just because the interface doesn't make enough
EMF things implicit.
So I would advice you to store the model and reload it when you call ATL
programmatically. An example of how to do that, you can find in the ATL
example privatization.
If you however make progress with using the model directly, please keep me
posted.


Regards,

Alfons


On 1/7/10 2:27 AM, in article hi3d97$1cq$1@build.eclipse.org, "Shannon"
<shannonbay@gmail.com> wrote:

> Hm, I couldn't get the ATL wrapper code that Guillaume suggested to work. I
> guess I don't have that api or something? I'm using the full Eclipse
> modelling package though so it seems odd.
>
> Anyway, I'm reasonably happy for now... I was able to save the ecore xmi
> model to disk as Alfons suggested, using the following code:
>
> package org.xtext.example;
>
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
> import org.eclipse.xtext.resource.XtextResourceSet;
>
> public class ModelGenerator {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> PropStandaloneSetup.doSetup();
> XtextResourceSet resourceSet = new XtextResourceSet();
> URI uri = URI.createURI("src/test.prop");
> Resource xtextResource = resourceSet.getResource(uri , true);
> Resource xmiResource = new
> EcoreResourceFactoryImpl().createResource(URI.createURI("src/test.ecore "));
> xmiResource.getContents().add(xtextResource.getContents().ge t(0));
> try {
> xmiResource.save(null);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> }
>
> }
>
> I can then run transformations on that code in either my DSL plugin version of
> eclipse, if I also copy over the metamodel, or in the normal version.
>
> This is not a long term solution, but for now I am simply evaluating ATL +
> xText.
>
> Cheers,
>
> Shannon
Re: [ATL] Xtext as input for ATL M2M [message #506695 is a reply to message #506629] Fri, 08 January 2010 20:19 Go to previous messageGo to next message
Guillaume Hillairet is currently offline Guillaume HillairetFriend
Messages: 83
Registered: July 2009
Member
Hi all,

The code i provided works on generated packages, that's maybe why you can't make it work.

I have updated the code example here http://gist.github.com/272357

hope it will help.

Best regards,
Guillaume
Re: [ATL] Xtext as input for ATL M2M [message #540528 is a reply to message #506695] Wed, 16 June 2010 13:05 Go to previous messageGo to next message
Guillaume  is currently offline Guillaume Friend
Messages: 1
Registered: June 2010
Junior Member
Hi all,

Would anyone happen to know if the code sample proposed by Guillaume (http://gist.github.com/272357) still works with the latest XText release (1.0M7) ?

Regards,

Guillaume
Re: [ATL] Xtext as input for ATL M2M [message #541099 is a reply to message #540528] Fri, 18 June 2010 10:55 Go to previous messageGo to next message
Guillaume Hillairet is currently offline Guillaume HillairetFriend
Messages: 83
Registered: July 2009
Member
Hi,

The code should work, there were no changes in how XtextResource are intialized.

BRs,
Guillaume
Re: [ATL] Xtext as input for ATL M2M [message #552424 is a reply to message #503928] Thu, 12 August 2010 08:10 Go to previous message
Jorge Carballo is currently offline Jorge CarballoFriend
Messages: 7
Registered: July 2010
Junior Member
Hi all,

I use the code sample proposed by Guillaume, but at line:

outModel.getResource().setURI(URI.createURI("src/ExampleFinal.mycontroller"));


outModel is a org.eclipse.m2m.atl.core.emf.EMFModel, ...
but outModel.getResource() is NULL ....

Does anyone know why?

Regards,
Jorge.
Previous Topic:[ATL] Using profile with ATL
Next Topic:[QVTo] how to check cyclic references easily (use 'closure'?)
Goto Forum:
  


Current Time: Sun Dec 21 10:01:25 GMT 2014

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

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