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 |
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 22:02 |
Daniel van 't Oever 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 |
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
|
|
| | | | | | |
Goto Forum:
Current Time: Wed Apr 24 17:47:57 GMT 2024
Powered by FUDForum. Page generated in 0.03869 seconds
|