Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Launching ATL from Java
[ATL] Launching ATL from Java [message #528621] Wed, 21 April 2010 10:13 Go to next message
dany is currently offline danyFriend
Messages: 3
Registered: April 2010
Junior Member
hello everyone

i 'm trying to launch an ATL transformation from java code but it doesn't work and i don't understand why

this my program :

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IProject;
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.EMFModelFactory;
import org.eclipse.m2m.atl.core.emf.EMFInjector;
import org.eclipse.m2m.atl.core.emf.EMFReferenceModel;
import org.eclipse.m2m.atl.core.launch.ILauncher;
import org.eclipse.m2m.atl.core.service.CoreService;
import org.eclipse.m2m.atl.core.ui.vm.asm.ASMFactory;
import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
import org.eclipse.m2m.atl.common.*;

public class TransformTest {
private static URL asmURL;
public static final String IN_META = "file:/Users/me/Desktop/ProjetBi/impl proj/Families2persons/Families2Persons/Families.ecore";
public static final String OUT_META = "file:/Users/me/Desktop/ProjetBi/impl proj/Families2persons/Families2Persons/Persons.ecore";
public static final String IN_MODEL = "file:/Users/me/Desktop/ProjetBi/impl proj/Families2persons/Families2Persons/sample-Families.xmi";
public static final String OUT_MODEL = "file:/Users/me/Desktop/ProjetBi/impl proj/Families2persons/Families2Persons/WorkPlease.xmi";



public TransformTest() throws Exception {
System.out.println("c");
EMFVMLauncher launcher = new EMFVMLauncher();
Map<String, Object> launcherOptions = new HashMap<String,Object>();
launcherOptions.put("allowInterModelReferences", "true");
launcher.initialize(launcherOptions);
CoreService.registerLauncher(launcher);

CoreService.registerFactory("EMF", EMFModelFactory.class);
ModelFactory factory = CoreService.createModelFactory("EMF");

CoreService.registerExtractor("EMF", new EMFExtractor());
CoreService.registerInjector("EMF", new EMFInjector());
System.out.println("d");

EMFInjector injector = new EMFInjector();
IExtractor extractor = CoreService.getExtractor(factory.getDefaultExtractorName());

// Metamodels && models

System.out.println("e");
EMFReferenceModel Metamodel1 = (EMFReferenceModel)factory.newReferenceModel();
System.out.println("e0");
//System.out.println(""+IN_META);
injector.inject(Metamodel1,IN_META);

System.out.println("e1");
IModel model1 = factory.newModel(Metamodel1);
injector.inject(model1, IN_MODEL);
System.out.println("f");
EMFReferenceModel Metamodel2 = (EMFReferenceModel)factory.newReferenceModel();
System.out.println("g");
injector.inject(Metamodel2,OUT_META);
System.out.println("h");
IModel model2 = factory.newModel(Metamodel2);
System.out.println("i");

// Launching
launcher.addInModel(model1, IN_MODEL, IN_META); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("j");
launcher.addOutModel(model2, OUT_MODEL, OUT_META); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("k");

URL asmURL = new URL("file:/Users/me/Desktop/ProjetBi/impl proj/Families2persons/Families2Persons/Families2Persons.asm");
System.out.println("l");
InputStream asmInputStream = asmURL.openStream();
System.out.println("l1");
InputStream[] modules = new InputStream[1];
System.out.println("l2");
modules[0] = asmInputStream;
System.out.println("l3");
launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), Collections.<String, Object> emptyMap(),(Object[])modules);

System.out.println("l4");


}
}


i put some system.out.println to know where the problem com from
and this the result i have so far

a
c
d
e
e0
e1
f
g
h
i
j
k
l
l1
l2
l3

any help is welcome

[Updated on: Wed, 21 April 2010 10:15]

Report message to a moderator

Re: [ATL] Launching ATL from Java [message #528896 is a reply to message #528621] Thu, 22 April 2010 10:34 Go to previous messageGo to next message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 268
Registered: March 2010
Senior Member


HI,

I yhink perhaps that the problem come from the white space that you make beteen impl and proj

file:/Users/me/Desktop/ProjetBi/[B]impl proj[/B]/Families2persons/Families2Persons/Families.ecore

and i have an other question, why its display an "a" is there a code missing?

mahmoud
Re: [ATL] Launching ATL from Java [message #528975 is a reply to message #528621] Thu, 22 April 2010 14:17 Go to previous messageGo to next message
dany is currently offline danyFriend
Messages: 3
Registered: April 2010
Junior Member
it didn't change anything .

the "a" come from my main class :

public static void main(String[] args) throws Exception {

System.out.println("a");
TransformTest tr= new TransformTest();
System.out.println("b");
}
Re: [ATL] Launching ATL from Java [message #529150 is a reply to message #528975] Fri, 23 April 2010 08:33 Go to previous messageGo to next message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 268
Registered: March 2010
Senior Member

HI,

may be this link could help you?
http://code.google.com/p/atl-commons/

Good Luck
mahmoud
Re: [ATL] Launching ATL from Java [message #529304 is a reply to message #528621] Fri, 23 April 2010 18:17 Go to previous messageGo to next message
dany is currently offline danyFriend
Messages: 3
Registered: April 2010
Junior Member
thanks . it help me a lot Very Happy
Re: [ATL] Launching ATL from Java [message #537876 is a reply to message #529304] Fri, 04 June 2010 01:44 Go to previous message
Ton Tu is currently offline Ton TuFriend
Messages: 16
Registered: June 2010
Junior Member
Hi danny,
Could you show your snippet of code ? I really need your help. I have problems executing ATL from Java ...
Thanks in advance
Previous Topic:[QVTO] standalone qvt stereotypes in profile not recognized
Next Topic:[ATL]problem accessing elements in the target model
Goto Forum:
  


Current Time: Tue Apr 13 20:52:07 GMT 2021

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

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

Back to the top