Home » Modeling » ATL » Launch transformation by java returns different output compared to atl run
Launch transformation by java returns different output compared to atl run [message #973416] |
Tue, 06 November 2012 10:04 |
Mauro Faella Messages: 31 Registered: June 2012 |
Member |
|
|
Hi,
I'm trying to launch an ATL transformation by java. I started from here and I changed the code for my purpose.
The problem is that the result of the transformation launching the java code is different (and not the expected) compared to the result of the transformation launching the run configuration of atl.
I think that my problem is in the fact that the input model has references to another uml model, specified into a dedicated uml file. These references aren't resolved in the "java execution", while in the "atl execution" they are.
I would explain better the situation...
First of all I initialize a ResourceSet with references to my metamodels , then I load the following resources with an EMFInjector:
- all metamodels I need: uml2.4 (http://www.eclipse.org/uml2/4.0.0/UML) that is metamodel for input, a custom metamodel in ecore that is the metamodel for output, an UML profile into a .uml file that is used for input model
- UML model to transform (IN)
- UML model that is referenced by IN (REF).
I also used these options:
Map<String, Object> options = new HashMap<String,Object>();
options.put("supportUML2Stereotypes", "true");
options.put("allowInterModelReferences","true");
After I use the EMFVMLauncher to perform the transformation in the same way of the example (here) using the options defined before.
At the end I extract the output model with the EMFExtractor and unload everything.
Here the code
public class RunTransfoJava {
private static final String PROFILE_PATH = new String("metamodels/profile.uml");
public static void main(String[] args) {
try {
/*
* Initializations
*/
ResourceSet resSet = new ResourceSetImpl();
MyUMLResourceSet.init(resSet);
MyUMLResourceSet.initProfile(resSet,PROFILE_PATH);
ILauncher transformationLauncher = new EMFVMLauncher();
ModelFactory modelFactory = new EMFModelFactory();
IInjector injector = new EMFInjector();
IExtractor extractor = new EMFExtractor();
/*
* Load metamodels
*/
Map<String, Object> options = new HashMap<String,Object>();
options.put("supportUML2Stereotypes", "true");
options.put("allowInterModelReferences","true");
IReferenceModel outputMetamodel = modelFactory.newReferenceModel();
injector.inject(outputMetamodel, "metamodels/outputMeta.ecore", options);
IReferenceModel umlMetamodel = modelFactory.newReferenceModel();
injector.inject(umlMetamodel, "http://www.eclipse.org/uml2/4.0.0/UML", options);
IReferenceModel profileModel = modelFactory.newReferenceModel();
injector.inject(profileModel, PROFILE_PATH, options);
IModel refModel = modelFactory.newModel(umlMetamodel);
injector.inject(refModel,"models/ref.uml",options);
IModel inModel = modelFactory.newModel(umlMetamodel);
injector.inject(inModel,"models/in.uml", options);
IModel outputModel = modelFactory.newModel(outputMetamodel);
/*
* Run transformation
*/
transformationLauncher.initialize(new HashMap<String,Object>());
transformationLauncher.addInModel(inModel, "IN", "UML");
transformationLauncher.addOutModel(outputModel, "OUT", "OUTMETA");
transformationLauncher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), options,
new FileInputStream("transformation/transformation.asm"));
extractor.extract(outputModel, "results/out.xmi", options);
/*
* Unload all models and metamodels (EMF-specific)
*/
EMFModelFactory emfModelFactory = (EMFModelFactory) modelFactory;
emfModelFactory.unload((EMFModel) inModel);
emfModelFactory.unload((EMFModel) outputModel);
emfModelFactory.unload((EMFModel) profileModel);
emfModelFactory.unload((EMFModel) refModel);
emfModelFactory.unload((EMFReferenceModel) outputMetamodel);
emfModelFactory.unload((EMFReferenceModel) umlMetamodel);
} catch (ATLCoreException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
MyUMLResourceSet is an utility class done by me to initialize a ResourceSet for my purpose.
The output is the transformation of all the elements included into IN, without the specific information that must be taken from REF. I repeat myself: the same transformation launched by ATL run configurator returns the right output model.
Any suggestions? Thanks in advance,
Mauro
[Updated on: Tue, 06 November 2012 10:05] Report message to a moderator
|
|
| | | | | | | | | | |
Re: Launch transformation by java returns different output compared to atl run [message #986445 is a reply to message #986304] |
Tue, 20 November 2012 12:54 |
Fernanda R.F. Messages: 64 Registered: May 2012 |
Member |
|
|
Mauro, I was seeing your answer and code again, so did you use uml url as in metamodel, right?
I need to use an UML file, maybe using ant build file won't help me with it. Actually, there are two bugs opened because of it, so when I saw your topic I thought maybe I could use it, however, as I said, as I'm using an UML file as in metamodel it won't work properly.
Thanks
|
|
| |
Goto Forum:
Current Time: Thu Sep 19 10:40:43 GMT 2024
Powered by FUDForum. Page generated in 0.04012 seconds
|