Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Running ATL Transformation from JAVA
[ATL] Running ATL Transformation from JAVA [message #106812] Thu, 18 June 2009 10:30 Go to next message
Miguel Beca is currently offline Miguel BecaFriend
Messages: 11
Registered: July 2009
Junior Member
Hello,

I am in the process of writing an application, which after compiling an
ATL file, will then run the transformation.

I had some difficulties, since some of the examples available in the "ATL
How to" web page seem to be out-of-date. In particular, I had some
difficulties with the model handlers.

Attached is the code that I managed to put together after looking at other
examples, however, I get errors when trying to run the transformation.

Here is my code:

package org.ATLCodeGenerator.test1;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.gmt.tcs.injector.ASMModelHandler;
import org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel;
import org.eclipse.m2m.atl.drivers.emf4atl.AtlEMFModelHandler;
import org.eclipse.m2m.atl.drivers.emf4atl.EMFModelLoader;
import org.eclipse.m2m.atl.engine.vm.*;
import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;



class ATLTransformation {

private static ATLTransformation instance = null;

private final static String resourcePath =
"C:/Users/Miguel/Documents/TESE - FCT/ATL/ATL Code Generation/Metamodels";

private AtlEMFModelHandler modelHandler;
private EMFModelLoader ml;
private URI FootwearResource;
private URI ShoesResource;


private ASMEMFModel footMetamodel;
private ASMEMFModel shoesMetamodel;


private URL Footwear2Shoes_TransfoResource;


static public ATLTransformation getInstance() {
if (instance == null)
instance = new ATLTransformation();
return instance;
}


private void createResources() {
//modelHandler = AtlModelHandler.getDefault("EMF");
FootwearResource = URI.createPlatformPluginURI(resourcePath +
"Footwear.ecore", false);
ShoesResource = URI.createPlatformPluginURI(resourcePath +
"Shoes.ecore", false);

Footwear2Shoes_TransfoResource =
ATLTransformation.class.getResource("Footwear2Shoes.asm");

}

private void initMetamodels(Map<String, Object> models) throws
IOException {
AtlModelHandler emfamh =
AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
ml = (EMFModelLoader) emfamh.createModelLoader();
footMetamodel = (ASMEMFModel) ml.loadModel("Footwear", ml.getMOF(),
FootwearResource);
models.put("Footwear", footMetamodel);

}

public void foot2shoes(String inFilePath, String outFilePath) {
try {
Map<String, Object> models = new HashMap<String, Object>();
createResources();
initMetamodels(models);

// get/create models
ASMEMFModel footInputModel = (ASMEMFModel) ml.loadModel("IN",
footMetamodel, URI.createFileURI(inFilePath));
ASMEMFModel shoesOutputModel = (ASMEMFModel) ml.newModel("OUT",
URI.createFileURI(outFilePath).toFileString(), shoesMetamodel);
// load models
models.put("IN", footInputModel);
models.put("OUT", shoesOutputModel);
// launch
AtlLauncher.getDefault().launch(this.JWT2BPMN_Pool_TransfoRe source,
Collections.EMPTY_MAP, models, Collections.EMPTY_MAP,
Collections.EMPTY_LIST, Collections.EMPTY_MAP);

ml.save(shoesOutputModel, outFilePath);
//dispose(models);
} catch (Exception e) {
e.printStackTrace();
}
}

}


These are the errors that I am getting after calling the transformation
from the main method:

Exception in thread "main" java.lang.SecurityException: class
"org.eclipse.core.runtime.IStatus"'s signer information does not match
signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(Unknown Source)
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at
org.eclipse.m2m.atl.engine.compiler.AtlDefaultCompiler.inter nalCompile(AtlDefaultCompiler.java:204)
at
org.eclipse.m2m.atl.engine.compiler.AtlDefaultCompiler.compi le(AtlDefaultCompiler.java:64)
at
org.ATLCodeGenerator.test1.ATLCodeGenerator.main(ATLCodeGene rator.java:56)


Any help would be greatly appreciated.

Thank you,

Miguel Beça
Re: [ATL] Running ATL Transformation from JAVA [message #106848 is a reply to message #106812] Fri, 19 June 2009 07:36 Go to previous messageGo to next message
William Piers is currently offline William PiersFriend
Messages: 301
Registered: July 2009
Senior Member
Hello,

Using the latest ATL version (3.0.x), you can refer to this
doccumentation: http://wiki.eclipse.org/ATL/Developer_Guide#Examples_of_use

Regards,

William

Miguel Beca a écrit :
> Hello,
>
> I am in the process of writing an application, which after compiling an
> ATL file, will then run the transformation.
>
> I had some difficulties, since some of the examples available in the
> "ATL How to" web page seem to be out-of-date. In particular, I had some
> difficulties with the model handlers.
>
> Attached is the code that I managed to put together after looking at
> other examples, however, I get errors when trying to run the
> transformation.
>
> Here is my code:
>
> package org.ATLCodeGenerator.test1;
> import java.io.IOException;
> import java.net.URL;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.Map;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.gmt.tcs.injector.ASMModelHandler;
> import org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel;
> import org.eclipse.m2m.atl.drivers.emf4atl.AtlEMFModelHandler;
> import org.eclipse.m2m.atl.drivers.emf4atl.EMFModelLoader;
> import org.eclipse.m2m.atl.engine.vm.*;
> import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
>
>
>
> class ATLTransformation {
>
> private static ATLTransformation instance = null;
> private final static String resourcePath =
> "C:/Users/Miguel/Documents/TESE - FCT/ATL/ATL Code Generation/Metamodels";
>
> private AtlEMFModelHandler modelHandler;
> private EMFModelLoader ml;
> private URI FootwearResource;
> private URI ShoesResource;
>
>
> private ASMEMFModel footMetamodel;
> private ASMEMFModel shoesMetamodel;
>
>
> private URL Footwear2Shoes_TransfoResource;
>
>
> static public ATLTransformation getInstance() {
> if (instance == null)
> instance = new ATLTransformation();
> return instance;
> }
>
>
> private void createResources() {
> //modelHandler = AtlModelHandler.getDefault("EMF");
> FootwearResource = URI.createPlatformPluginURI(resourcePath +
> "Footwear.ecore", false);
> ShoesResource = URI.createPlatformPluginURI(resourcePath +
> "Shoes.ecore", false);
>
> Footwear2Shoes_TransfoResource =
> ATLTransformation.class.getResource("Footwear2Shoes.asm");
>
> }
>
> private void initMetamodels(Map<String, Object> models) throws
> IOException {
> AtlModelHandler emfamh =
> AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
> ml = (EMFModelLoader) emfamh.createModelLoader();
> footMetamodel = (ASMEMFModel) ml.loadModel("Footwear",
> ml.getMOF(), FootwearResource);
> models.put("Footwear", footMetamodel);
>
> }
>
> public void foot2shoes(String inFilePath, String outFilePath) {
> try {
> Map<String, Object> models = new HashMap<String,
> Object>();
> createResources();
> initMetamodels(models);
>
> // get/create models
> ASMEMFModel footInputModel = (ASMEMFModel)
> ml.loadModel("IN", footMetamodel, URI.createFileURI(inFilePath));
> ASMEMFModel shoesOutputModel = (ASMEMFModel)
> ml.newModel("OUT", URI.createFileURI(outFilePath).toFileString(),
> shoesMetamodel);
> // load models
> models.put("IN", footInputModel);
> models.put("OUT", shoesOutputModel);
> // launch
>
> AtlLauncher.getDefault().launch(this.JWT2BPMN_Pool_TransfoRe source,
> Collections.EMPTY_MAP, models, Collections.EMPTY_MAP,
> Collections.EMPTY_LIST, Collections.EMPTY_MAP);
>
> ml.save(shoesOutputModel, outFilePath);
> //dispose(models);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
>
>
> These are the errors that I am getting after calling the transformation
> from the main method:
>
> Exception in thread "main" java.lang.SecurityException: class
> "org.eclipse.core.runtime.IStatus"'s signer information does not match
> signer information of other classes in the same package
> at java.lang.ClassLoader.checkCerts(Unknown Source)
> at java.lang.ClassLoader.preDefineClass(Unknown Source)
> at java.lang.ClassLoader.defineClass(Unknown Source)
> at java.security.SecureClassLoader.defineClass(Unknown Source)
> at java.net.URLClassLoader.defineClass(Unknown Source)
> at java.net.URLClassLoader.access$000(Unknown Source)
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClassInternal(Unknown Source)
> at
> org.eclipse.m2m.atl.engine.compiler.AtlDefaultCompiler.inter nalCompile(AtlDefaultCompiler.java:204)
>
> at
> org.eclipse.m2m.atl.engine.compiler.AtlDefaultCompiler.compi le(AtlDefaultCompiler.java:64)
>
> at
> org.ATLCodeGenerator.test1.ATLCodeGenerator.main(ATLCodeGene rator.java:56)
>
>
> Any help would be greatly appreciated.
>
> Thank you,
>
> Miguel Beça
>
Re: [ATL] Running ATL Transformation from JAVA [message #106977 is a reply to message #106848] Fri, 19 June 2009 15:53 Go to previous messageGo to next message
Miguel Beca is currently offline Miguel BecaFriend
Messages: 11
Registered: July 2009
Junior Member
Dear William,

Thank you for your suggestion.

I tried using the PrivatizeAction.java example and adapted it to my case.
However, I am now getting this error:

org.eclipse.m2m.atl.core.ATLCoreException:
org.eclipse.m2m.atl.core.injector EMF not found, check the spelling or
register it manually.

My code is below. Any help is appreciated.

Thanks,

Miguel

import java.net.URL;
import java.util.Collections;
import java.util.Iterator;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
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;
import org.osgi.framework.Bundle;


public class ATLTransformationLauncher {

private static IInjector injector;

private static IExtractor extractor;

private static IReferenceModel umlMetamodel;

private static IReferenceModel refiningTraceMetamodel;

private static IReferenceModel footMetamodel;
private static IReferenceModel shoesMetamodel;

private static URL asmURL;


static {

try {
asmURL = new URL("Footwear2Shoes.asm");
} catch (Exception e) {
// TODO: handle exception
}

try {
injector = CoreService.getInjector("EMF"); //$NON-NLS-1$
extractor = CoreService.getExtractor("EMF"); //$NON-NLS-1$
} catch (ATLCoreException e) {
e.printStackTrace();
}
}

/**
* Constructor for Action1.
*/
public ATLTransformationLauncher(){
super();
}



public void Foot2ShoesLaunch(IFile file) throws Exception {
// Defaults
ModelFactory factory = CoreService.createModelFactory("EMF");
//$NON-NLS-1$

// Metamodels

footMetamodel = factory.newReferenceModel();
injector.inject(footMetamodel,
" file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Footwear.ecore ");
//$NON-NLS-1$
shoesMetamodel =
factory.getBuiltInResource(" file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Shoes.ecore ");
//$NON-NLS-1$



// Getting launcher
ILauncher launcher = null;
launcher = CoreService.getLauncher("EMF-specific VM"); //$NON-NLS-1$
launcher.initialize(Collections.<String, Object> emptyMap());

// Creating models
IModel shoesModel = factory.newModel(shoesMetamodel);
IModel footModel = factory.newModel(footMetamodel);

// Loading existing model
injector.inject(footModel, file.getFullPath().toString());

// Launching

launcher.addOutModel(shoesModel, "shoes", "Shoes"); //$NON-NLS-1$
//$NON-NLS-2$
launcher.addInModel(footModel, "foot", "Footwear"); //$NON-NLS-1$
//$NON-NLS-2$

launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(),
Collections
.<String, Object> emptyMap(), asmURL.openStream());

// Saving model
extractor.extract(shoesModel, file.getFullPath().toString());

// Refresh workspace
file.getParent().refreshLocal(IProject.DEPTH_INFINITE, null);

}


}
Re: [ATL] Running ATL Transformation from JAVA [message #107056 is a reply to message #106977] Wed, 24 June 2009 13:53 Go to previous messageGo to next message
William Piers is currently offline William PiersFriend
Messages: 301
Registered: July 2009
Senior Member
Hi,

Could you please explain how do you launch your project ?
e.g. :
- Eclipse with EMF and ATL installed
- a workspace containing your project
- a runtime where you launch the transformation (e.g. with a popup)
Or something else ?

The CoreService uses Eclipse's extension points to retrieve injectors,
extractors etc..
To work out of Eclipse you have to manually register injectors and
extractors (see CoreService.registerInjector(String name, IInjector
injector) for example).

William

Miguel Beca a écrit :
> Dear William,
>
> Thank you for your suggestion.
>
> I tried using the PrivatizeAction.java example and adapted it to my
> case. However, I am now getting this error:
>
> org.eclipse.m2m.atl.core.ATLCoreException:
> org.eclipse.m2m.atl.core.injector EMF not found, check the spelling or
> register it manually.
>
> My code is below. Any help is appreciated.
>
> Thanks,
>
> Miguel
>
> import java.net.URL;
> import java.util.Collections;
> import java.util.Iterator;
>
> import org.eclipse.core.resources.IFile;
> import org.eclipse.core.resources.IProject;
> 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;
> import org.osgi.framework.Bundle;
>
>
> public class ATLTransformationLauncher {
>
> private static IInjector injector;
>
> private static IExtractor extractor;
>
> private static IReferenceModel umlMetamodel;
>
> private static IReferenceModel refiningTraceMetamodel;
>
> private static IReferenceModel footMetamodel;
> private static IReferenceModel shoesMetamodel;
>
> private static URL asmURL;
>
>
> static {
>
> try {
> asmURL = new URL("Footwear2Shoes.asm");
> } catch (Exception e) {
> // TODO: handle exception
> }
>
> try {
> injector = CoreService.getInjector("EMF"); //$NON-NLS-1$
> extractor = CoreService.getExtractor("EMF");
> //$NON-NLS-1$
> } catch (ATLCoreException e) {
> e.printStackTrace();
> }
> }
>
> /**
> * Constructor for Action1.
> */
> public ATLTransformationLauncher(){
> super();
> }
>
>
>
> public void Foot2ShoesLaunch(IFile file) throws Exception {
> // Defaults
> ModelFactory factory = CoreService.createModelFactory("EMF");
> //$NON-NLS-1$
>
> // Metamodels
>
> footMetamodel = factory.newReferenceModel();
> injector.inject(footMetamodel,
> " file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Footwear.ecore ");
> //$NON-NLS-1$
> shoesMetamodel =
> factory.getBuiltInResource(" file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Shoes.ecore ");
> //$NON-NLS-1$
>
>
>
> // Getting launcher
> ILauncher launcher = null;
> launcher = CoreService.getLauncher("EMF-specific VM");
> //$NON-NLS-1$
> launcher.initialize(Collections.<String, Object> emptyMap());
>
> // Creating models
> IModel shoesModel = factory.newModel(shoesMetamodel);
> IModel footModel = factory.newModel(footMetamodel);
>
> // Loading existing model
> injector.inject(footModel, file.getFullPath().toString());
>
> // Launching
>
> launcher.addOutModel(shoesModel, "shoes", "Shoes");
> //$NON-NLS-1$ //$NON-NLS-2$
> launcher.addInModel(footModel, "foot", "Footwear");
> //$NON-NLS-1$ //$NON-NLS-2$
>
> launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(),
> Collections
> .<String, Object> emptyMap(), asmURL.openStream());
>
> // Saving model
> extractor.extract(shoesModel, file.getFullPath().toString());
>
> // Refresh workspace
> file.getParent().refreshLocal(IProject.DEPTH_INFINITE, null);
>
> }
>
>
> }
>
>
Re: [ATL] Running ATL Transformation from JAVA [message #107071 is a reply to message #107056] Wed, 24 June 2009 14:09 Go to previous messageGo to next message
Miguel Beca is currently offline Miguel BecaFriend
Messages: 11
Registered: July 2009
Junior Member
Hi William,

Thank you for your help.

I am writing an application in Eclipse and using EMF and ATL. The final
objective is to write a program that will both compile an ATL file and the
execute the compiled .asm file.

Is this sufficient information for you?

Thanks,

Miguel

William Piers wrote:

> Hi,

> Could you please explain how do you launch your project ?
> e.g. :
> - Eclipse with EMF and ATL installed
> - a workspace containing your project
> - a runtime where you launch the transformation (e.g. with a popup)
> Or something else ?

> The CoreService uses Eclipse's extension points to retrieve injectors,
> extractors etc..
> To work out of Eclipse you have to manually register injectors and
> extractors (see CoreService.registerInjector(String name, IInjector
> injector) for example).

> William

> Miguel Beca a écrit :
>> Dear William,
>>
>> Thank you for your suggestion.
>>
>> I tried using the PrivatizeAction.java example and adapted it to my
>> case. However, I am now getting this error:
>>
>> org.eclipse.m2m.atl.core.ATLCoreException:
>> org.eclipse.m2m.atl.core.injector EMF not found, check the spelling or
>> register it manually.
>>
>> My code is below. Any help is appreciated.
>>
>> Thanks,
>>
>> Miguel
>>
>> import java.net.URL;
>> import java.util.Collections;
>> import java.util.Iterator;
>>
>> import org.eclipse.core.resources.IFile;
>> import org.eclipse.core.resources.IProject;
>> 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;
>> import org.osgi.framework.Bundle;
>>
>>
>> public class ATLTransformationLauncher {
>>
>> private static IInjector injector;
>>
>> private static IExtractor extractor;
>>
>> private static IReferenceModel umlMetamodel;
>>
>> private static IReferenceModel refiningTraceMetamodel;
>>
>> private static IReferenceModel footMetamodel;
>> private static IReferenceModel shoesMetamodel;
>>
>> private static URL asmURL;
>>
>>
>> static {
>>
>> try {
>> asmURL = new URL("Footwear2Shoes.asm");
>> } catch (Exception e) {
>> // TODO: handle exception
>> }
>>
>> try {
>> injector = CoreService.getInjector("EMF"); //$NON-NLS-1$
>> extractor = CoreService.getExtractor("EMF");
>> //$NON-NLS-1$
>> } catch (ATLCoreException e) {
>> e.printStackTrace();
>> }
>> }
>>
>> /**
>> * Constructor for Action1.
>> */
>> public ATLTransformationLauncher(){
>> super();
>> }
>>
>>
>>
>> public void Foot2ShoesLaunch(IFile file) throws Exception {
>> // Defaults
>> ModelFactory factory = CoreService.createModelFactory("EMF");
>> //$NON-NLS-1$
>>
>> // Metamodels
>>
>> footMetamodel = factory.newReferenceModel();
>> injector.inject(footMetamodel,
>>
" file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Footwear.ecore ");
>> //$NON-NLS-1$
>> shoesMetamodel =
>>
factory.getBuiltInResource(" file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Shoes.ecore ");
>> //$NON-NLS-1$
>>
>>
>>
>> // Getting launcher
>> ILauncher launcher = null;
>> launcher = CoreService.getLauncher("EMF-specific VM");
>> //$NON-NLS-1$
>> launcher.initialize(Collections.<String, Object> emptyMap());
>>
>> // Creating models
>> IModel shoesModel = factory.newModel(shoesMetamodel);
>> IModel footModel = factory.newModel(footMetamodel);
>>
>> // Loading existing model
>> injector.inject(footModel, file.getFullPath().toString());
>>
>> // Launching
>>
>> launcher.addOutModel(shoesModel, "shoes", "Shoes");
>> //$NON-NLS-1$ //$NON-NLS-2$
>> launcher.addInModel(footModel, "foot", "Footwear");
>> //$NON-NLS-1$ //$NON-NLS-2$
>>
>> launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(),
>> Collections
>> .<String, Object> emptyMap(), asmURL.openStream());
>>
>> // Saving model
>> extractor.extract(shoesModel, file.getFullPath().toString());
>>
>> // Refresh workspace
>> file.getParent().refreshLocal(IProject.DEPTH_INFINITE, null);
>>
>> }
>>
>>
>> }
>>
>>
Re: [ATL] Running ATL Transformation from JAVA [message #108273 is a reply to message #106977] Sat, 11 July 2009 19:58 Go to previous message
Pantanowitz is currently offline PantanowitzFriend
Messages: 3
Registered: July 2009
Junior Member
Hello Miguel,
I'm also on a quest to invoke ATL from Java. Where did you import
org.eclipse.gmt.tcs.injector and
org.eclipse.core.runtime.NullProgressMonitor from? I can't seem to find
any packages that has them! org.eclipse.core.runtime_3.4.0.v20080512.jar
does not seem to have NullProgressMonitor!
Thanks in advance,

Panto

Miguel Beca wrote:
> Dear William,
>
> Thank you for your suggestion.
>
> I tried using the PrivatizeAction.java example and adapted it to my
> case. However, I am now getting this error:
>
> org.eclipse.m2m.atl.core.ATLCoreException:
> org.eclipse.m2m.atl.core.injector EMF not found, check the spelling or
> register it manually.
>
> My code is below. Any help is appreciated.
>
> Thanks,
>
> Miguel
>
> import java.net.URL;
> import java.util.Collections;
> import java.util.Iterator;
>
> import org.eclipse.core.resources.IFile;
> import org.eclipse.core.resources.IProject;
> 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;
> import org.osgi.framework.Bundle;
>
>
> public class ATLTransformationLauncher {
>
> private static IInjector injector;
>
> private static IExtractor extractor;
>
> private static IReferenceModel umlMetamodel;
>
> private static IReferenceModel refiningTraceMetamodel;
>
> private static IReferenceModel footMetamodel;
> private static IReferenceModel shoesMetamodel;
>
> private static URL asmURL;
>
>
> static {
>
> try {
> asmURL = new URL("Footwear2Shoes.asm");
> } catch (Exception e) {
> // TODO: handle exception
> }
>
> try {
> injector = CoreService.getInjector("EMF"); //$NON-NLS-1$
> extractor = CoreService.getExtractor("EMF");
> //$NON-NLS-1$
> } catch (ATLCoreException e) {
> e.printStackTrace();
> }
> }
>
> /**
> * Constructor for Action1.
> */
> public ATLTransformationLauncher(){
> super();
> }
>
>
>
> public void Foot2ShoesLaunch(IFile file) throws Exception {
> // Defaults
> ModelFactory factory = CoreService.createModelFactory("EMF");
> //$NON-NLS-1$
>
> // Metamodels
>
> footMetamodel = factory.newReferenceModel();
> injector.inject(footMetamodel,
> " file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Footwear.ecore ");
> //$NON-NLS-1$
> shoesMetamodel =
> factory.getBuiltInResource(" file:/C:/Users/Miguel/workspace/ATLTransformationGenerator/m etamodels/Shoes.ecore ");
> //$NON-NLS-1$
>
>
>
> // Getting launcher
> ILauncher launcher = null;
> launcher = CoreService.getLauncher("EMF-specific VM");
> //$NON-NLS-1$
> launcher.initialize(Collections.<String, Object> emptyMap());
>
> // Creating models
> IModel shoesModel = factory.newModel(shoesMetamodel);
> IModel footModel = factory.newModel(footMetamodel);
>
> // Loading existing model
> injector.inject(footModel, file.getFullPath().toString());
>
> // Launching
>
> launcher.addOutModel(shoesModel, "shoes", "Shoes");
> //$NON-NLS-1$ //$NON-NLS-2$
> launcher.addInModel(footModel, "foot", "Footwear");
> //$NON-NLS-1$ //$NON-NLS-2$
>
> launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(),
> Collections
> .<String, Object> emptyMap(), asmURL.openStream());
>
> // Saving model
> extractor.extract(shoesModel, file.getFullPath().toString());
>
> // Refresh workspace
> file.getParent().refreshLocal(IProject.DEPTH_INFINITE, null);
>
> }
>
>
> }
>
>
Previous Topic:How to duplicate an element
Next Topic:add an element to a sequence
Goto Forum:
  


Current Time: Thu Apr 25 16:25:09 GMT 2024

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

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

Back to the top