Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] a working example of a programmatic launch(a working example of a programmatic launch)
[ATL] a working example of a programmatic launch [message #632793] Thu, 14 October 2010 09:49
valerio c. is currently offline valerio c.Friend
Messages: 5
Registered: October 2010
Junior Member
Hi, i created a little example to show how to work a programmatic launch

Valerio

import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.m2m.atl.drivers.emf4atl.AtlEMFModelHandler; 
import org.eclipse.m2m.atl.engine.vm.AtlLauncher;
import org.eclipse.m2m.atl.engine.vm.AtlModelHandler;
import org.eclipse.m2m.atl.engine.vm.ModelLoader;
import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;

public class Families2PersonsProgrammaticLaunch {
    
    public static void main(String[] args) {
    	try {
    		//AtlModelHandler and ModelLoader init
    		AtlModelHandler.registerDefaultHandler("EMF", new AtlEMFModelHandler());   		
	    	AtlModelHandler amh = AtlModelHandler.getDefault("EMF");
	    	ModelLoader ml = amh.createModelLoader();
	    	
	    	//stores metamodels and models
	    	Map models = new HashMap();
	    	//used to locate metamodels,models and trasformation file
	    	URL url;
	    	
	    	//URL where Families.ecore (input metamodel) is located
	    	url = new URL("file:/C:/Documents and Settings/Administrator/workspace2/Families2Persons/Families.ecore");	    	
	    	//load Families metamodel (the name is the same in the ATL file  [ex.: ATL CODE-> create OUT : Persons from IN : *Families*;])
	    	ASMModel metamodel_families = ml.loadModel("Families", ml.getMOF(), url.openStream());
	    	//store   
	    	models.put("Families", metamodel_families);
	    	
	    	//URL where Persons.ecore (output metamodel) is located
	    	url = new URL("file:/C:/Documents and Settings/Administrator/workspace2/Families2Persons/Persons.ecore");
	    	//load Persons metamodel (the name is the same in the ATL file  [ex.: ATL CODE-> create OUT : *Persons* from IN : Families;])
	    	ASMModel metamodel_persons = ml.loadModel("Persons", ml.getMOF(), url.openStream());
	    	//store 
	    	models.put("Persons", metamodel_persons);
	    	
	    	//URL where sample-Families.xmi (input model) is located
	    	url = new URL("file:/C:/Documents and Settings/Administrator/workspace2/Families2Persons/sample-Families.xmi");
	    	//load Families model (the name is the same in the ATL file  [ex.: ATL CODE-> create OUT : Persons from *IN* : Families;])
	    	ASMModel model_families = ml.loadModel("IN", metamodel_families, url.openStream());
	    	//store 
	    	models.put("IN", model_families);
	    	
	    	//URL where sample-Persons.xmi (output model) is located
	    	url = new URL("file:/C:/Documents and Settings/Administrator/workspace2/Families2Persons/sample-Persons.xmi");
	    	//create a new output model (the name is the same in the ATL file  [ex.: ATL CODE-> create *OUT* : Persons from IN : Families;])
	    	ASMModel outputModel = ml.newModel("OUT", "C:/Documents and Settings/Administrator/workspace2/Families2Persons/sample-Persons.xmi", metamodel_persons);
	    	//store 
	    	models.put("OUT", outputModel);
	    	
	    	//URL where Families2Persons.asm (transformation .asm) is located
	    	url = new URL("file:/C:/Documents and Settings/Administrator/workspace2/Families2Persons/Families2Persons.asm");
	    	//get an AtlLauncher
	    	AtlLauncher myLauncher = AtlLauncher.getDefault();
	    	//execute the transformation (in this case we pass just the map "models")
	    	myLauncher.launch(url, Collections.EMPTY_MAP, models, Collections.EMPTY_MAP, Collections.EMPTY_LIST, Collections.EMPTY_MAP);
	    	
	    	//save the outputModel in "file://C:/Documents and Settings/Administrator/workspace2/Families2Persons/sample-Persons.xmi"
	    	outputModel.getModelLoader().save(outputModel, "file://C:/Documents and Settings/Administrator/workspace2/Families2Persons/sample-Persons.xmi");
	    	
	    	//once executed this file make a refresh on the destination folder
    	}
    	catch (Exception e) {
    		e.printStackTrace();
    	}
    	
    	
    }
	
}
Previous Topic:[Qvto] Error saving
Next Topic:QVTo log writer gets strings instead of objects, making custom loggers useless/impossible
Goto Forum:
  


Current Time: Fri Apr 26 06:36:18 GMT 2024

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

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

Back to the top