Using M2M in C# [message #537717] |
Thu, 03 June 2010 09:10  |
Eclipse User |
|
|
|
I've created neccessary models, model rules and transformed successfully in an ATL project. Could you introduce me some ways to call those transformations at runtime in C#. I'm using VS 2008 to develop my application. Thanks in advance
|
|
|
|
|
|
|
|
|
Re: Using M2M in C# [message #538269 is a reply to message #538168] |
Mon, 07 June 2010 03:50   |
Eclipse User |
|
|
|
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.28622 seconds