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 11:51  |
Eclipse User |
|
|
|
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 17:02   |
Eclipse User |
|
|
|
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 04:30   |
Eclipse User |
|
|
|
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 #73947 is a reply to message #73155] |
Wed, 30 January 2008 11:35  |
Eclipse User |
|
|
|
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.
|
|
|
Goto Forum:
Current Time: Thu May 08 14:22:17 EDT 2025
Powered by FUDForum. Page generated in 0.04094 seconds
|