|
|
|
|
|
|
Re: Using M2M in C# [message #538168 is a reply to message #537913] |
Sun, 06 June 2010 00:57 |
Ton Tu Messages: 16 Registered: June 2010 |
Junior Member |
|
|
I still cannot use those namespaces to run ATL rules successfully. Could you please give me a snippet of code to run those namespaces ? I will appreciate you a lot ...
I'm getting tired of not being able to run ATL rules which are neccessary for my university thesis ... I've come through many articles instructing how to wrap ATL but none of them is compilable ... I wonder if there's any problem with Eclipse configuration ? Would you mind helping me ?
[Updated on: Sun, 06 June 2010 00:59] Report message to a moderator
|
|
|
Re: Using M2M in C# [message #538269 is a reply to message #538168] |
Mon, 07 June 2010 07:50 |
Vincent MAHE Messages: 129 Registered: July 2009 |
Senior Member |
|
|
Le 06/06/2010 02:57, Ton Tu a écrit :
> I still cannot use those namespaces to run ATL rules successfully. Could
> you please give me a snippet of code to run those namespaces ? I will
> appreciate you a lot ... I'm getting tired of not being able to run ATL
> rules which are neccessary for my university thesis ...
As an example of ATL Java launcher :
> import java.net.URL;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.Map;
>
> import org.eclipse.core.runtime.NullProgressMonitor;
> import org.eclipse.core.runtime.Platform;
> 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.launch.ILauncher;
> import org.eclipse.m2m.atl.core.service.CoreService;
>
> public class ATLInterface
> {
> /**
> * The injector used to load models to XMI files
> */
> private static IInjector injector;
>
> /**
> * The extractor used to save models in XMI files
> */
> private static IExtractor extractor;
>
> /**
> * The URL of the compiled transformation
> */
> private static URL transfoURL;
>
> /*
> * This initializes the ATL interface at first load
> */
> static {
> transfoURL = Platform.getBundle("org.xx.zz.my.plugin")
> .getEntry("transformation/myTransfo.asm");
>
> try {
> injector = CoreService.getInjector(EMF);
> extractor = CoreService.getExtractor(EMF);
> } catch (ATLCoreException e) {
> e.printStackTrace();
> }
> }
>
> /**
> * Call the transformation onto the <code>inFilePath</code> and store the result in the
> * <code>outFilePath</code> file.
> *
> * @param inFilePath
> * The path to the input model
> * @param outFilePath
> * The path to the output model
> */
> public static void transform(String inFilePath, String outFilePath)
> {
> try
> {
> ModelFactory factory = CoreService.getModelFactory(EMF);
>
> ILauncher launcher = CoreService.getLauncher(EMF-specific VM);
> launcher.initialize(Collections.<String, Object> emptyMap()) ;
>
> IReferenceModel inMM = factory.newReferenceModel();
> injector.inject(inMM, "**inMetamodelUri**");
>
> IReferenceModel outMM = factory.newReferenceModel();
> injector.inject(outMM, "**outMetamodelUri**");
>
> // get/create models
> IModel inModel = factory.newModel(inMM);
> injector.inject(inModel, inFilePath);
> launcher.addInModel(inModel, "IN", "IN_MM"); // use ATL transfo codes
>
> IModel outModel = factory.newModel(outMM);
> launcher.addOutModel(outModel, "OUT", "OUT_MM");
>
> // add the continue after errors options
> Map<String, Object> options = new HashMap<String, Object>();
> options.put("continueAfterError", "true");
> options.put("printExecutionTime", "true");
>
> // launch the transformation
> launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(),
> options, transfoURL.openStream());
>
> extractor.extract(outModel, outFilePath);
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
> }
--
Cordialement
Vincent MAHÉ
Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
|
|
|
|
Powered by
FUDForum. Page generated in 0.03524 seconds