Skip to main content



      Home
Home » Modeling » ATL » Running an ATL Transformation from Java
Running an ATL Transformation from Java [message #1220718] Fri, 13 December 2013 04:28 Go to next message
Eclipse UserFriend
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();
		}
	}

}
Re: Running an ATL Transformation from Java [message #1220726 is a reply to message #1220718] Fri, 13 December 2013 04:59 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

Have you refreshed your project after running the Java program launching the transformation to ensure that the output model has not been created at the expected location?
If yes, then there may be an error with the given path according to the program's base directory.
Re: Running an ATL Transformation from Java [message #1220788 is a reply to message #1220726] Fri, 13 December 2013 10:25 Go to previous message
Eclipse UserFriend
It was only a refresh issue, Smile.
Thanks!
Previous Topic:[ATL] Containment references cannot span across models
Next Topic:Is there a way to stop a running ATL transformation {and, or} return something to the launcher?
Goto Forum:
  


Current Time: Tue Jul 22 21:02:08 EDT 2025

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

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

Back to the top