Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Calling an ATL transfo. in Java(NullPointerException while loading model with modelHandler )
[ATL] Calling an ATL transfo. in Java [message #665614] Fri, 15 April 2011 09:26
Cesar Caves is currently offline Cesar Caves
Messages: 22
Registered: July 2009
Junior Member
Hello forum !

Some time ago I posted this: 0&S=124e1298f56f875872ce17ae5931e0e6#msg_649240

First of all, I want to thank Vincent Mahe for his reply. His advice has been a great help for me. Now that I have 3 transfos. working fine:

1.- XML_2_MMa
2.- MMa_2_MMb
3.- MMb_2_XML

I face the problem of automate this chain, because right now I need to execute the process step by step, I mean, creating a launch configuration for each transfo and executing them separatedly. I have though in writing a Java program for this purpose, so I have searched the web looking for documentation about that. Instead of finding general information, I have found examples like this one: TL_transformation_in_java_.28e.g._in_a_transformation_plugin .29

So, from this basis, I have attempted to customize it. Now, my own code is:

note1: I have used the metamodels and models from the ATL documentation basic example "The in/out ports example" e.php?file=Port/index.html

note2: I recognize that using absolute locations is not a good pracsis, but trying to avoid secondary problems, I chose to use them temporarily.

note3: the code breaks down when trying to load the input model.
Could someone help me? I think is a problem related to URI conversion, maybe a simple issue, but I am a bit lost at the moment.
Any help with this concrete problem or with the perspective of the automation of the transfo. chain would be very appreciated.
Thanks in advance !!

public class ATLTransformation {

public static final String MMs_PATH = "c:/My_workspace/My_project/MetaModels/";
public static final String MODELS_PATH = "c:/My_workspace/My_project/SampleModels/";
public static final String TRANSFOS_PATH = "c:/My_workspace/My_project/Transformation/";

public static void main(String[] args) {

// I get a model handler
AtlEMFModelHandler modelHandler = (AtlEMFModelHandler)AtlModelHandler.getDefault(AtlModelHandl er.AMH_EMF);

/* MMs */

// I get URIs from the MMs *.ecore files
URI sourceMM_URI = URI.createFileURI(MMs_PATH + "TypeA.ecore");
URI targetMM_URI = URI.createFileURI(MMs_PATH + "TypeB.ecore");

// I load the MMs
ASMEMFModel sourceMM = (ASMEMFModel)modelHandler.loadModel("TypeA", modelHandler.getMof(), sourceMM_URI);
ASMEMFModel targetMM = (ASMEMFModel)modelHandler.loadModel("TypeB", modelHandler.getMof(), targetMM_URI);

/* Models */

// I get URIs from the models *.xmi files
URI inputURI = URI.createFileURI(MODELS_PATH + "sample-TypeA.xmi");
URI outputURI = URI.createFileURI(MODELS_PATH + "sample-TypeB.xmi");

// I load the input model and create the output one
ASMEMFModel inputModel = (ASMEMFModel)modelHandler.loadModel("sample-TypeA", sourceMM, inputURI);
ASMEMFModel outputModel = (ASMEMFModel)modelHandler.newModel("sample-TypeB", outputURI.toFileString(), targetMM);

// A map to store models (and MMs)
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put(sourceMM.getName(), sourceMM);
modelMap.put(targetMM.getName(), targetMM);
modelMap.put(inputModel.getName(), inputModel);
modelMap.put(outputModel.getName(), outputModel);

// I get URLs from the transformation *.atl file
URL transfoURL = ATLTransformation.class.getResource(TRANSFOS_PATH + "TypeA2TypeB_v2.asm");

// I launch the transfo.

modelHandler.saveModel(outputModel, MODELS_PATH + "sample-TypeB.xmi");

// I dispose the models (and MMs)
for (Object model : modelMap.values()) {

Previous Topic:PackageNotFound error - ATL and EMF
Next Topic:[ATL] Passing parameters from XML in Query
Goto Forum:

Current Time: Fri Oct 24 08:07:32 GMT 2014

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

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