Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL Launch] ATL from JAVA whithout serialization(Using ATL Launcher provided by ATL SDK)
[ATL Launch] ATL from JAVA whithout serialization [message #666687] Thu, 21 April 2011 15:34 Go to next message
Antoine  is currently offline Antoine
Messages: 22
Registered: February 2011
Location: Toulouse, France
Junior Member
Hello everybody !

I use ATL 3.1.2 and when I create an ATL Plugin from my ATL transformation, ATL SDK generates a very useful Java Class to launch an ATL transformation. So I can call my transformation from Java simply using:
/* sourceModelPath and destModelPath are path Strings */
String args [] = {sourceModelPath, destModelPath};

I would like to make more:
- I want to call my ATL transformation from Java but instead of using file path, I want to use directly my EMF Model (Ecore Objects). I don't want to use serialization, physical files.
To resume, I want a class (or a function I don't know) who consumes an EMF Model, made the transformation, and provides a new model.

I want to know if we can do this with the actual ATL API, or if I have to re-write the ATL Launcher ?

Thank you for those who have some ideas to make this !!

Re: [ATL Launch] ATL from JAVA whithout serialization [message #669781 is a reply to message #666687] Wed, 11 May 2011 14:10 Go to previous message
Antoine  is currently offline Antoine
Messages: 22
Registered: February 2011
Location: Toulouse, France
Junior Member
Hello !

I up this topic because I advanced but there is something very strange with EMF Resource.

I wrote all the code to manage myself the ATL transformation with the EMFVMLauncher, this is the code :
//Factory to create models and metamodels, injector to inject data in models
ModelFactory factory = new EMFModelFactory();
IInjector injector = new EMFInjector();

//MetaModelA, ModelA and injection of data from my resource (resourceModelA)
IReferenceModel metaModelA = factory.newReferenceModel();
injector.inject(metaModelA, metaModelAEcorePath); /* metaModelAEcorePath is the string path of my ecore file */
IModel modelA = factory.newModel(metaModelA);
((EMFInjector)injector).inject(modelA, resourceModelA); 
/* My resourceModelA is already created and filled (I checked this by saving it and verifying the XMI file */	

//MetaModelB, ModelB but no injection (it's the destination model)
IReferenceModel metaModelB = factory.newReferenceModel();
injector.inject(metaModelB, metaModelBEcorePath); /* metaModelAEcorePath is the string path of my ecore file */
IModel modelB = factory.newModel(metaModelB);

//Parameterization of the launcher (adding models, ASM File) and launch
ILauncher launcher = new EMFVMLauncher();
launcher.addInModel(modelA, "ModelA", "MyFirstModelA");
launcher.addOutModel(modelB, "ModelB", "MyFirstModelB");

InputStream tabIS[] = new InputStream[1];
tabIS[0] = new URL(asmFilePath).openStream(); /* asmFilePath is the complete string path of my transformation (the asm file) */
Map<String, Object> launcherOptions = new HashMap<String, Object>();

launcher.launch("run", null, launcherOptions, (Object[]) tabIS);

//Extraction of data in the ModelB
IExtractor extractor = new EMFExtractor();
extractor.extract(modelB, fileModelB); /* fileModelB is the path string of my result modelB */

If I run this, my fileModelB is empty. When I try by using the Java Class ModelA2ModelB generated by ATL, it works good (but I must save my resourceModelA in a file before... and it's precisely this that I want to avoid...)

But if I save my resourceModelA, then I reload it like this, it works :
_resourceSet = ((EMFModelFactory)modelA.getModelFactory()).getResourceSet();
_resourceModelA = _resourceSet.getResource(modelAFilePath, true);

/* Then I use it in my injector (replacing the 6th line) */
((EMFInjector)injector).inject(modelA, _resourceModelA);

This works good but I must save my file and reload it, I don't know why. I want to only inject my resource without save it before... !

If anybody have some ideas to fix this, I would appreciate very much!

Thanks to all,


[Updated on: Wed, 11 May 2011 14:18]

Report message to a moderator

Previous Topic:[QVT] Traversing relationship links and finding connected elements
Next Topic:an executable file of ATL project
Goto Forum:

Current Time: Mon Sep 22 00:24:55 GMT 2014

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

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