|
|
[ATL] [SOLVED] Using ATL in a "standalone" Software [message #657581 is a reply to message #655532] |
Thu, 03 March 2011 11:10 |
Sebastian Messages: 11 Registered: February 2011 |
Junior Member |
|
|
Hello everyone,
I did some research and experimenting and found a solution. It works perfectly well to use ATL Transformations in a Java Application without Eclipse.
Since I stumbled upon similar questions in eclipse forums I am posting my solution here for further discussion.
package test;
import java.io.File;
import java.net.URL;
import java.util.Collections;
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.EMFInjector;
import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
import org.eclipse.m2m.atl.core.launch.ILauncher;
import org.eclipse.m2m.atl.core.service.CoreService;
import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
public class RunTransformation {
private static IInjector injector;
private static IExtractor extractor;
private static IReferenceModel sourceMetamodel;
private static IReferenceModel targetMetamodel;
/*
* My test data
*/
private static String transformationFilepath = "transformation/TestATL.asm";
private static String sourceFilepath = "model/TestSourceModel.ecore";
private static String targetFilepath = "model/TestTargetModel.ecore";
private static String dataSourceFilepath = "data/sourceData.xmi";
private static String dataTargetfilepath = "data/targetData.xmi";
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
try {
CoreService.registerLauncher("EMF-specific VM", EMFVMLauncher.class);
CoreService.registerFactory("EMF", EMFModelFactory.class);
CoreService.registerExtractor("EMF", EMFExtractor.class);
CoreService.registerInjector("EMF", EMFInjector.class);
injector = CoreService.getInjector("EMF");
extractor = CoreService.getExtractor("EMF");
} catch (ATLCoreException e) {
e.printStackTrace();
}
// Defaults
ModelFactory factory = CoreService.getModelFactory("EMF");
// Metamodels
sourceMetamodel = factory.newReferenceModel();
targetMetamodel = factory.newReferenceModel();
injector.inject(sourceMetamodel, sourceFilepath);
injector.inject(targetMetamodel, targetFilepath);
// Getting launcher
ILauncher launcher = null;
launcher = (EMFVMLauncher)CoreService.getLauncher("EMF-specific VM");
launcher.initialize(Collections.<String, Object> emptyMap());
// Creating models
IModel sourceModel = factory.newModel(sourceMetamodel);
IModel targetModel = factory.newModel(targetMetamodel);
// Loading existing model
injector.inject(sourceModel, dataSourceFilepath);
// Launching
launcher.addInModel(sourceModel, "IN", "MM");
launcher.addOutModel(targetModel, "OUT", "MM1");
/*
* As a reference for this I provide the first two lines of my TestATL.atl file:
* module TestATL;
* create OUT : MM1 from IN : MM;
*/
// the loadModule function requires an absolute path to the ASM file
// this is my dirty (?) way to transform a relative path (inside the project) to an absolute path
URL asmFile = new File(transformationFilepath).toURI().toURL();
Object loadedModule = launcher.loadModule(asmFile.openStream());
launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), Collections
.<String, Object> emptyMap(), loadedModule);
// Saving model
extractor.extract(targetModel, dataTargetfilepath);
System.out.println("DONE!");
}
}
And here is the list of required libraries (all can be found in the eclipse/plug-in directory if you have the necessary plug-ins installed). Simply copy them to your project folder and add them as "Referenced Libraries".
org.eclipse.uml2.uml_3.1.2.v201010261927.jar
org.eclipse.emf.ecore_2.6.1.v20100914-1218.jar
org.eclipse.emf.common_2.6.0.v20100914-1218.jar
org.eclipse.emf.ecore.xmi_2.5.0.v20100521-1846.jar
org.eclipse.uml2.common_1.5.0.v201005031530.jar
org.eclipse.m2m.atl.core_3.1.2.v20110119-0755.jar
org.eclipse.core.runtime_3.6.0.v20100505.jar
org.eclipse.m2m.atl.core.emf_3.1.2.v20110119-0755.jar
org.eclipse.m2m.atl.engine.emfvm_3.1.2.v20110119-0755.jar
org.eclipse.equinox.common_3.6.0.v20100503.jar
org.eclipse.m2m.atl.common_3.1.2.v20110119-0755.jar
org.eclipse.m2m.atl.engine.emfvm.launch_3.1.2.v20110119-0755.jar
org.eclipse.m2m.atl.drivers.emf4atl_3.1.2.v20110119-0755.jar
org.eclipse.m2m.atl.engine_3.1.2.v20110119-0755.jar
Since my whole program is going to be released under the EPL, I believe that this inclusion does not violate the license.
May it help everyone in need out there
Sebastian
@Ronan: Thanks anyway for your effort.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: [ATL] Using ATL in a "standalone" Software [message #664856 is a reply to message #664616] |
Tue, 12 April 2011 10:00 |
nicholas pacini Messages: 31 Registered: December 2010 |
Member |
|
|
Alexey wrote on Mon, 11 April 2011 08:08 | Hallo, Nicholas!
Please, could you put here the code, which registers XML at EMF?
Thank you very much!
Alexey
|
i've done something like this:
EPackage.Registry.INSTANCE.put("http://www.eclipse.org/papyrus/MARTE/1", org.eclipse.papyrus.MARTE.MARTEPackage.eINSTANCE);
to register MARTE, and an analogue line for my custom profile, both before injecting the metamodels
then i've added a line to inject it:
injector.inject(marteMetamodel, martePath);
then another one to create the model:
IModel marteModel = factory.newModel(marteMetamodel);
and finally this one to load the model:
injector.inject(marteModel, SourceModelPath);
hope it can help, if you need more informations feel free to ask, i'll try to help
for anyone else:
i still have the problem i've explained two post before. Here's an example:
module prova;
create OUT : IM from IN1 : CHESS, IN3 : MARTE, IN2 : UML2;
rule Prova{
from p : UML2!Component (p.getAppliedStereotypes().debug('stereotypes')->exists(e | e.name = 'StatefulSoftware'))
to c : IM!Component (Name <- p.name)
}
running the transformation from eclipse it works, e.g:
...
stereotypes: Sequence {<unknown>!StatefulHardware, <unknown>!HwComputingResource}
...
from Java all I got is:
...
stereotypes: Sequence {}...
any ideas of what could be wrong?
|
|
|
|
|
Re: [ATL] [SOLVED] Using ATL in a "standalone" Software [message #668590 is a reply to message #657581] |
Fri, 06 May 2011 11:14 |
Cesar Caves Messages: 29 Registered: July 2009 |
Junior Member |
|
|
Hi Sebastian and others.
Thank you very much for showing your code. I have tried it, literally exact as it is, and adding to the build path the same required libraries you mention (working, like you, with Eclipse Helios 3.6.2. In my case the "modeling" package, having downloaded and installed the ATL component, which I don't understand why, if it is a modeling oriented package, this component is not installed by default... Anyway, this is another issue...).
My problem is that the execution breaks down at the instruction
sourceMetamodel = factory.newReferenceModel();
printing the stack trace at the end of the post.
Can you or anybody else help me to understand what is happening/how to solve it????
Thanks in advance.
César
Exception in thread "main" java.lang.SecurityException: class "org.eclipse.emf.ecore.EGenericType"'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.core.emf.EMFReferenceModel.addAllReferen cedResources(EMFReferenceModel.java:227)
at org.eclipse.m2m.atl.core.emf.EMFReferenceModel.register(EMFR eferenceModel.java:118)
at org.eclipse.m2m.atl.core.emf.EMFModelFactory.getMetametamode l(EMFModelFactory.java:82)
at org.eclipse.m2m.atl.core.emf.EMFModelFactory.newReferenceMod el(EMFModelFactory.java:104)
at atl.RunTransformation.main(RunTransformation.java:51)
[Updated on: Fri, 06 May 2011 11:17] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.08751 seconds