Running an ATL Transformation from Java [message #1220718] |
Fri, 13 December 2013 09:28 |
Daniele G Messages: 6 Registered: October 2013 |
Junior Member |
|
|
Hi all,
I am trying to run an ATL Transformation using the ATL Core API as described in http://wiki.eclipse.org/ATL/Developer_Guide#ATL_Source_Code.
To get a feel about the process, I modified the RunTransfoJava program: it seems to work (no errors/exceptions) but it does not produce the output model.
Anyone can help?
I'm using:
Eclipse Modeling Tools
Version: Juno Service Release 2
Build id: 20130225-0426
And here is my code:
package com.greco.myfirstjavaatl;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2m.atl.core.ATLCoreException;
import org.eclipse.m2m.atl.core.IExtractor;
import org.eclipse.m2m.atl.core.IInjector;
import org.eclipse.m2m.atl.core.IModel;
import org.eclipse.m2m.atl.core.IReferenceModel;
import org.eclipse.m2m.atl.core.ModelFactory;
import org.eclipse.m2m.atl.core.emf.EMFExtractor;
import org.eclipse.m2m.atl.core.emf.EMFInjector;
import org.eclipse.m2m.atl.core.emf.EMFModel;
import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
import org.eclipse.m2m.atl.core.emf.EMFReferenceModel;
import org.eclipse.m2m.atl.core.launch.ILauncher;
import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
import org.eclipse.emf.common.notify.Notifier;
public class RunTransfoJava {
public static void main(String[] args) {
try {
System.out.println("Running...");
/*
* Paths
*/
String inModelPath = "models/Example.drd";
String outModelPath = "models/Example.ai";
String DRDMetamodelPath = "metamodels/DRD.ecore";
String AIdMetamodelPath = "metamodels/AI.ecore";
System.out.println("inModelPath: " + inModelPath);
System.out.println("outModelPath: " + outModelPath);
System.out.println("DRDMetamodelPath: " + DRDMetamodelPath);
System.out.println("AIdMetamodelPath: " + AIdMetamodelPath);
/*
* Initializations
*/
ILauncher transformationLauncher = new EMFVMLauncher();
ModelFactory modelFactory = new EMFModelFactory();
IInjector injector = new EMFInjector();
IExtractor extractor = new EMFExtractor();
/*
* Load metamodels
*/
IReferenceModel drdMetamodel = modelFactory.newReferenceModel();
injector.inject(drdMetamodel, DRDMetamodelPath);
IReferenceModel aiMetamodel = modelFactory.newReferenceModel();
injector.inject(aiMetamodel, AIdMetamodelPath);;
System.out.println("Metamodels loaded.");
/*
* Load models and run transformation
*/
IModel inModel = modelFactory.newModel(drdMetamodel);
injector.inject(inModel,inModelPath);
IModel outModel = modelFactory.newModel(aiMetamodel);
System.out.println("IN, OUT models loaded.");
System.out.print("Running ATL trasformation...");
transformationLauncher.initialize(new HashMap<String,Object>());
transformationLauncher.addInModel(inModel, "IN", "DRD");
transformationLauncher.addOutModel(outModel, "OUT", "AI");
transformationLauncher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), new HashMap<String,Object>(),
new FileInputStream("transformations/DRD2AI.asm"));
System.out.println("Done.");
System.out.print("Extracting OUT model...");
extractor.extract(outModel, outModelPath);
System.out.println("Done.");
/*
* Unload all models and metamodels (EMF-specific)
*/
EMFModelFactory emfModelFactory = (EMFModelFactory) modelFactory;
emfModelFactory.unload((EMFModel) inModel);
emfModelFactory.unload((EMFModel) outModel);
emfModelFactory.unload((EMFReferenceModel) drdMetamodel);
emfModelFactory.unload((EMFReferenceModel) aiMetamodel);
} catch (ATLCoreException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04252 seconds