Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Using ATL in a "standalone" Software(Using ATL in a non-development software)
[ATL] Using ATL in a "standalone" Software [message #655532] Mon, 21 February 2011 15:58 Go to next message
Sebastian is currently offline SebastianFriend
Messages: 11
Registered: February 2011
Junior Member
Hello Forum,
i'd like to use ATL in a software that is not part of the development process. Instead i'd like to use ATL to convert data from one data model to another data model (which involves some non-trivial transformation).

Is it possible to use ATL "without eclipse"? By that I mean without using eclipse to start the transformation (the libraries are obviously required). I'd like to be able to trigger an ATL transformation from my own GUI on dynamically provided data.

Any suggestions on how to accomplish this (or why it cannot be done) are very welcome.

Thanks in advance,
Sebastian
Re: [ATL] Using ATL in a "standalone" Software [message #657313 is a reply to message #655532] Wed, 02 March 2011 12:14 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi Sebastian,
You can run ATL as part of an Eclipse headless configuration. This means you can get OSGI to load the required bundles and kick off the required transformations. Do some googling on "Eclipse Headless".

I wouldn't think you will have much luck running ATL without Eclipse as ATL is reliant on alot of EMF.

Regards,
Ronan
icon14.gif  [ATL] [SOLVED] Using ATL in a "standalone" Software [message #657581 is a reply to message #655532] Thu, 03 March 2011 11:10 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
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 Wink
Sebastian

@Ronan: Thanks anyway for your effort.
Re: [ATL] [SOLVED] Using ATL in a "standalone" Software [message #657918 is a reply to message #657581] Fri, 04 March 2011 15:24 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hello, Sebastian!
Thank you for this implementation sample.

I have 2 questions:

1. Does it run ONLY WITHOUT Eclipse, or it does also with?

2. Which Plugins have I to install to get the jars in my build path?
I cant find these jars you listed below in the plugins-Directory of my 3.5.2 Eclipse Version.

Thanks!

Alexey
Re: [ATL] [SOLVED] Using ATL in a "standalone" Software [message #657928 is a reply to message #657918] Fri, 04 March 2011 16:35 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
Messages: 11
Registered: February 2011
Junior Member
Hello Alexey,
I will try to answer your questions.

Alexey wrote on Fri, 04 March 2011 10:24
1. Does it run ONLY WITHOUT Eclipse, or it does also with?

It runs inside AND outside eclipse! I have an eclipse project that includes models, transformation, input data and the source code. Now I can

- run the transformation inside eclipse (Run the ATL-File as "ATL Transformation" with a Run Configuration where the models and data paths are configured)
- use my code from above to run the same models and transformation on the same data from inside eclipse (as Java Application)
- create a JAR with that class and a Manifest (Main-Class and Libraries referenced in here) inside and run that JAR from outside eclipse.

So I can keep developing and testing my transformation in eclipse and always be able to take the current version and create a standalone application from it.


Alexey wrote on Fri, 04 March 2011 10:24

2. Which Plugins have I to install to get the jars in my build path?
I cant find these jars you listed below in the plugins-Directory of my 3.5.2 Eclipse Version.


Good question. I avoided this question in my post above since I may not be able to answer it completely since I am no eclipse expert.
The version number of the files need to be changed obviously to whatever version of eclipse/the plug-ins you have. My eclipse version seems to be 3.6.2.
The easiest way might be to describe what I did to get the eclipse I currently have:
- Get the "Eclipse Modeling Tools" version of Eclipse
- Use Help -> Install Modeling Components to install ATL
I believe that does the job. If it does not please tell me and I will post a complete list of installed plug-ins.

I hope this helps. Regards,
Sebastian
Re: [ATL] Using ATL in a "standalone" Software [message #657931 is a reply to message #655532] Fri, 04 March 2011 16:40 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
Messages: 11
Registered: February 2011
Junior Member
On second thought this example project could be included in the (quite sparse) user guide and tutorial section of the ATL project. I haven't been involved with any eclipse project before but if someone from the ATL project would take this in hand I am happy to supply a sample project.

Regards,
Sebastian
Re: [ATL] Using ATL in a "standalone" Software [message #657932 is a reply to message #655532] Fri, 04 March 2011 16:40 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hello, Sebastian!

Thanks a lot.

I added all jars needed and got it compiled.
But now I get this run time error:


Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.eclipse.m2m.atl.core.emf.EMFModelFactory.getMetametamodel(EMFModelFactory.java:80)
	at org.eclipse.m2m.atl.core.emf.EMFModelFactory.newReferenceModel(EMFModelFactory.java:104)
	at test.RunTransformation.main(RunTransformation.java:57)
Caused by: java.lang.UnsupportedOperationException
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl.eBasicAdapters(MinimalEObjectImpl.java:300)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotificationRequired(BasicNotifierImpl.java:243)
	at org.eclipse.emf.ecore.impl.EFactoryImpl.basicSetEPackage(EFactoryImpl.java:143)
	at org.eclipse.emf.ecore.impl.EFactoryImpl.eInverseAdd(EFactoryImpl.java:700)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eInverseAdd(BasicEObjectImpl.java:1415)
	at org.eclipse.emf.ecore.impl.EPackageImpl.setEFactoryInstance(EPackageImpl.java:383)
	at org.eclipse.emf.ecore.impl.EPackageImpl.<init>(EPackageImpl.java:182)
	at org.eclipse.emf.ecore.impl.EcorePackageImpl.<init>(EcorePackageImpl.java:85)
	at org.eclipse.emf.ecore.impl.EcorePackageImpl.init(EcorePackageImpl.java:483)
	at org.eclipse.emf.ecore.EcorePackage.<clinit>(EcorePackage.java:73)
	... 3 more




I have no idea how to manage that.
I think it is the 3.5.2 which is guilty.
I guess I have to try it with 3.6.2 now.

Did you test your app. on 3.6.2?

Thanks
Alexey
Re: [ATL] Using ATL in a "standalone" Software [message #657936 is a reply to message #657932] Fri, 04 March 2011 16:47 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
Messages: 11
Registered: February 2011
Junior Member
Hello Alexey,
I am sorry but I am unable to help you with that error. I am struggling with the EMF Framework myself. I am working with version 3.6.2.

Just one idea: Did you fix the names of your model and metamodel in the launcher.addInModel / launcher.addOutModel lines?

Good luck,
Sebastian
Re: [ATL] Using ATL in a "standalone" Software [message #657946 is a reply to message #657936] Fri, 04 March 2011 17:09 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
I didnt fill them yet! Beacuse this runtime-error i get - evolves BEFORE it comes to these lines.

So, I try to install the 3.6.2 properly as modelling tools, import all jars You listed - and then try to run it.

I will report then, what I did get.

Thanks a lot for a small, comprehensive code anyway. Im sure, this will work by me at last! Razz

Alexey
Re: [ATL] [SOLVED] Using ATL in a "standalone" Software [message #658125 is a reply to message #657581] Sun, 06 March 2011 19:06 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
Actually what you have done is exactly what I would call an Eclipse headless configuration, as you are using equinox as the OSGi container. I assumed you meant you wanted to run ATL without any Eclipse/Equinox support. Nice to have a good example for people to follow though so good work Smile
Regards,
Ronan
Re: [ATL] Using ATL in a "standalone" Software [message #658942 is a reply to message #655532] Thu, 10 March 2011 14:20 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hello, Sebastian!

I tryed your code with my source file path an got this error:

Quote:

Exception in thread "main" org.eclipse.m2m.atl.core.ATLCoreException: Error loading INPUT_M_MM/klima-XML.ecore: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'XML' not found. ( file:///D:/eclipse_installationen/3.6.2_modelling/workspace/ ATL_java/INPUT_M_MM/klima-XML.ecore, 5, 79)




Dont know what it could be. Doe you have an idea maybe?

Thank you,
Alexey
Re: [ATL] Using ATL in a "standalone" Software [message #661606 is a reply to message #655532] Fri, 25 March 2011 14:52 Go to previous messageGo to next message
nicholas pacini is currently offline nicholas paciniFriend
Messages: 31
Registered: December 2010
Member
hello all,

maybe you can help me. I've tried this solution to run a transformation from UML to another metamodel and it works fine. However my aim is to have, as input, an UML model with some applied stereotypes defined in a custom profile and when i try to run this code i get a org.eclipse.emf.ecore.xmi.PackageNotFoundException. This package comes from the profile and I have registered it using the extension point: org.eclipse.emf.ecore.dynamic_package but it doesn't seem to work: i still get a PackageNotFoundException.

Any idea of what's causing this? do you have other solutions i can try other than register it as a dynamic package? Thanks

best regards,
Nicholas

Re: [ATL] Using ATL in a "standalone" Software [message #661625 is a reply to message #661606] Fri, 25 March 2011 15:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Nicholas,

When running stand alone, plugin.xml registrations don't take effect and
you have to do all those things manually, in this case you'd have to
register the profile (it's nsURI mapping to the EPackage) in the
EPackage.Registry.INSTANCE.


nicholas wrote:
> hello all,
>
> maybe you can help me. I've tried this solution to run a
> transformation from UML to another metamodel and it works fine.
> However my aim is to have, as input, an UML model with some applied
> stereotypes defined in a custom profile and when i try to run this
> code i get a org.eclipse.emf.ecore.xmi.PackageNotFoundException. This
> package comes from the profile and I have registered it using the
> extension point: org.eclipse.emf.ecore.dynamic_package but it doesn't
> seem to work: i still get a PackageNotFoundException.
>
> Any idea of what's causing this? do you have other solutions i can try
> other than register it as a dynamic package? Thanks
>
> best regards,
> Nicholas
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [ATL] Using ATL in a "standalone" Software [message #661626 is a reply to message #661606] Fri, 25 March 2011 15:34 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
Messages: 11
Registered: February 2011
Junior Member
Hi Nicholas,
when you try to use my example code for UML, I expect that there need to be done several changes. I explicitly use EMF specific classes in most cases.
Maybe reading through this http://wiki.eclipse.org/index.php/EMF-FAQ and the associated entries might help.

Good luck and sorry that I cannot provide more detailed help as I have never used UML with EMF/ATL,
Sebastian
Re: [ATL] Using ATL in a "standalone" Software [message #662161 is a reply to message #661625] Tue, 29 March 2011 14:59 Go to previous messageGo to next message
nicholas pacini is currently offline nicholas paciniFriend
Messages: 31
Registered: December 2010
Member
hello Ed,

does this mean that the profile should be a static one?


Ed Merks wrote on Fri, 25 March 2011 11:28
Nicholas,

When running stand alone, plugin.xml registrations don't take effect and
you have to do all those things manually, in this case you'd have to
register the profile (it's nsURI mapping to the EPackage) in the
EPackage.Registry.INSTANCE.

Re: [ATL] Using ATL in a "standalone" Software [message #663551 is a reply to message #655532] Tue, 05 April 2011 15:16 Go to previous messageGo to next message
nicholas pacini is currently offline nicholas paciniFriend
Messages: 31
Registered: December 2010
Member
Hello All,

I've managed to register the profile in the EPackage.Registry.INSTANCE. Now I can run the transformation without exceptions, but still something is not right.

In fact when I run the transformation calling it from Eclipse I can access correctly all the stereotypes defined in the profile. Instead, when I call it from the Java code all the elements appear without stereotypes.

Anyone has any idea of what could be wrong?

Thanks.
Bye
Re: [ATL] Using ATL in a "standalone" Software [message #664616 is a reply to message #663551] Mon, 11 April 2011 12:08 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hallo, Nicholas!

Please, could you put here the code, which registers XML at EMF?

Thank you very much!

Alexey
Re: [ATL] Using ATL in a "standalone" Software [message #664856 is a reply to message #664616] Tue, 12 April 2011 10:00 Go to previous messageGo to next message
nicholas pacini is currently offline nicholas paciniFriend
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] Using ATL in a "standalone" Software [message #665303 is a reply to message #664856] Thu, 14 April 2011 08:43 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hello, Nicholas!

Thank You very much for Your help!

I have a question:

Here: njector.inject(marteMetamodel, martePath); - as I understood, You take your model as xml and inject it towards xml.ecore (or another one) metamodell?

Thanks!
Re: [ATL] Using ATL in a "standalone" Software [message #665683 is a reply to message #655532] Fri, 15 April 2011 13:44 Go to previous messageGo to next message
nicholas pacini is currently offline nicholas paciniFriend
Messages: 31
Registered: December 2010
Member
well, in the line:
injector.inject(marteMetamodel, martePath);


marteMetamodel is a IReferenceModel initialized with:
marteMetamodel = factory.newReferenceModel();


while martePath is a String initialized with the nsURI of the MARTE profile
String martePath = "http://www.eclipse.org/papyrus/MARTE/1";


I hope this can answer your question

Regards

Re: [ATL] [SOLVED] Using ATL in a "standalone" Software [message #668590 is a reply to message #657581] Fri, 06 May 2011 11:14 Go to previous message
Cesar Caves is currently offline Cesar CavesFriend
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

Previous Topic:[ATL] Support to arbitrary number of output models??
Next Topic:[ATL] How to handle meta-model dependencies ???
Goto Forum:
  


Current Time: Fri Apr 19 20:12:33 GMT 2024

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

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

Back to the top