Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] atl transf. from Java code
[ATL] atl transf. from Java code [message #73028] Mon, 21 January 2008 16:51 Go to next message
Eclipse UserFriend
Originally posted by: francopinchetti.yahoo.it

Hello everyone,
I know this argoument has been treated previosly on this newsgroup, but I
haven't understand so much from the earlier topics and I haven't found an
example of a Java class that launch an atl transformation.
Can someone, please, give me some advices and/or some links?
Many tanks in advance
Best Regards
Franco Pinchetti
Re: [ATL] atl transf. from Java code [message #73065 is a reply to message #73028] Tue, 22 January 2008 22:02 Go to previous messageGo to next message
Daniel van 't Oever is currently offline Daniel van 't OeverFriend
Messages: 6
Registered: July 2009
Junior Member
First you need a whole lot of jars included in your project. These can
be found here http://wiki.eclipse.org/ATL_Howtos

Then you need to do something like:

public ASMModel run( ASMModel inputInstance )
{
final AtlLauncher launcher = AtlLauncher.getDefault();
final Map<String, ASMModel> models = new HashMap<String,
ASMModel>();
final Map<?, ?> asmParams = Collections.EMPTY_MAP;
final List<?> superimpose = Collections.EMPTY_LIST;
final Map<?, ?> options = Collections.EMPTY_MAP;
final Map<?, ?> libs = Collections.EMPTY_MAP;

ASMModel outputInstance = modelHandler.newModel( "OUT", null,
targetMM );

models.put( "nql", sourceMM );
models.put( "ac", targetMM );
models.put( "IN", inputInstance );
models.put( "OUT", outputInstance );

launcher.launch( transformation, libs, models, asmParams,
superimpose, options );

return outputInstance;
}

sourceMM and targetMM must be loaded ASMModel objects, you can load them
like this:

String sourceMMLocation = "/nql.ecore";
AtlModelHandler modelHandler = AtlModelHandler.getDefault(
AtlModelHandler.AMH_EMF );

nqlMM = loadModel( "nql", modelHandler.getMof(), Util.class.getResource(
sourceMMLocation ) );
acMM = loadModel( "ac", modelHandler.getMof(),
Util.class.getResource( targetMMLocation ) );

As you can notice, my source metamodel is nql and my target is ac.

Make sure all these names correspond to the names declared in the first
line of your transformation.atl file!!!

Input instance is an instance model of the source model which can be
loaded the same way. (Either from file or as text run through an injector)

outputInstance is a new empty model that is an instance of the target
metamodel.

I hope this is enough :)

Another thing I noticed is that you should not load the same metamodel
in multiple places. I created a singleton class that loads my metamodels
in order to avoid loading them twice. Loading it twice at several
locations led me to very strange troubles that disappeared when I used
one loader.

Good luck,
Daniel


Franco wrote:
> Hello everyone,
> I know this argoument has been treated previosly on this newsgroup, but I
> haven't understand so much from the earlier topics and I haven't found an
> example of a Java class that launch an atl transformation.
> Can someone, please, give me some advices and/or some links?
> Many tanks in advance
> Best Regards
> Franco Pinchetti
>
>
Re: [ATL] atl transf. from Java code [message #73120 is a reply to message #73065] Wed, 23 January 2008 09:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: francopinchetti.yahoo.it

Thank you very much
Franco


"Daniel van 't Oever" <eclipse@vantoever.nl> ha scritto nel messaggio
news:fn5pa8$1nd$1@build.eclipse.org...
> First you need a whole lot of jars included in your project. These can be
> found here http://wiki.eclipse.org/ATL_Howtos
>
> Then you need to do something like:
>
> public ASMModel run( ASMModel inputInstance )
> {
> final AtlLauncher launcher = AtlLauncher.getDefault();
> final Map<String, ASMModel> models = new HashMap<String,
> ASMModel>();
> final Map<?, ?> asmParams = Collections.EMPTY_MAP;
> final List<?> superimpose = Collections.EMPTY_LIST;
> final Map<?, ?> options = Collections.EMPTY_MAP;
> final Map<?, ?> libs = Collections.EMPTY_MAP;
>
> ASMModel outputInstance = modelHandler.newModel( "OUT", null,
> targetMM );
>
> models.put( "nql", sourceMM );
> models.put( "ac", targetMM );
> models.put( "IN", inputInstance );
> models.put( "OUT", outputInstance );
>
> launcher.launch( transformation, libs, models, asmParams,
> superimpose, options );
>
> return outputInstance;
> }
>
> sourceMM and targetMM must be loaded ASMModel objects, you can load them
> like this:
>
> String sourceMMLocation = "/nql.ecore";
> AtlModelHandler modelHandler = AtlModelHandler.getDefault(
> AtlModelHandler.AMH_EMF );
>
> nqlMM = loadModel( "nql", modelHandler.getMof(), Util.class.getResource(
> sourceMMLocation ) );
> acMM = loadModel( "ac", modelHandler.getMof(),
> Util.class.getResource( targetMMLocation ) );
>
> As you can notice, my source metamodel is nql and my target is ac.
>
> Make sure all these names correspond to the names declared in the first
> line of your transformation.atl file!!!
>
> Input instance is an instance model of the source model which can be
> loaded the same way. (Either from file or as text run through an injector)
>
> outputInstance is a new empty model that is an instance of the target
> metamodel.
>
> I hope this is enough :)
>
> Another thing I noticed is that you should not load the same metamodel in
> multiple places. I created a singleton class that loads my metamodels in
> order to avoid loading them twice. Loading it twice at several locations
> led me to very strange troubles that disappeared when I used one loader.
>
> Good luck,
> Daniel
>
>
> Franco wrote:
>> Hello everyone,
>> I know this argoument has been treated previosly on this newsgroup, but I
>> haven't understand so much from the earlier topics and I haven't found an
>> example of a Java class that launch an atl transformation.
>> Can someone, please, give me some advices and/or some links?
>> Many tanks in advance
>> Best Regards
>> Franco Pinchetti
Re: [ATL] atl transf. from Java code [message #73155 is a reply to message #73120] Wed, 23 January 2008 11:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: milan.milanovic.org

Hi,

actually there is a Java class for launching ATL transformations, you can
download it here (with all necessary libs):
http://milan.milanovic.org/download/atl.zip

--
Best regards, Milan Milanovic
Re: [ATL] atl transf. from Java code [message #73611 is a reply to message #73065] Mon, 28 January 2008 16:30 Go to previous messageGo to next message
wong is currently offline wongFriend
Messages: 54
Registered: July 2009
Member
Hello,

How can I save the instance of a model(EMF) to a file. The example code
only has saveMDRModelToFile()

Thanks,
Wong.
Re: [ATL] atl transf. from Java code [message #73770 is a reply to message #73611] Tue, 29 January 2008 16:17 Go to previous messageGo to next message
wong is currently offline wongFriend
Messages: 54
Registered: July 2009
Member
Hello,

Is there anybody knows how to save the EMF model instance into xmi file. I
am in stuck.

Online waiting...

Thank you very much.

Wong.
Re: [ATL] atl transf. from Java code [message #73787 is a reply to message #73770] Tue, 29 January 2008 16:29 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 33
Registered: July 2009
Member
Hi,

I just use

AtlModelHandler.getHandler([your meta model]).
saveModel([your model], new FileOutputStream([your file name]));



Sebastian

wong schrieb:
> Hello,
>
> Is there anybody knows how to save the EMF model instance into xmi file.
> I am in stuck.
>
> Online waiting...
>
> Thank you very much.
>
> Wong.
>
Re: [ATL] atl transf. from Java code [message #73805 is a reply to message #73787] Tue, 29 January 2008 17:24 Go to previous messageGo to next message
wong is currently offline wongFriend
Messages: 54
Registered: July 2009
Member
Dear Sebastian,

Thank you so much.

Wong.
Re: [ATL] atl transf. from Java code [message #73947 is a reply to message #73155] Wed, 30 January 2008 16:35 Go to previous message
wong is currently offline wongFriend
Messages: 54
Registered: July 2009
Member
Hello,

I want save my EMF outputInsatance file on disk. I added two lines code
after the atlLauncher. But I only got a empty xmi file saved.

AtlLauncher.getDefault().launch(transformation, libs, models, params);
OutputStream out = new FileOutputStream(new
File("zzzz11.ecore")); AtlModelHandler.getHandler(otherMM_EMF).saveModel(outputInst ance,out);

The ASM script is tested. But it seem not working in the .launch() method.

Thank you for any help.

Wong.
Previous Topic:Cannot Find model UML
Next Topic:[ATL] Multiple metamodel for the model "OUT"
Goto Forum:
  


Current Time: Tue Apr 23 08:16:00 GMT 2024

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

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

Back to the top