Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Launch transformation by java returns different output compared to atl run
Launch transformation by java returns different output compared to atl run [message #973416] Tue, 06 November 2012 10:04 Go to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Hi,
I'm trying to launch an ATL transformation by java. I started from here and I changed the code for my purpose.

The problem is that the result of the transformation launching the java code is different (and not the expected) compared to the result of the transformation launching the run configuration of atl.

I think that my problem is in the fact that the input model has references to another uml model, specified into a dedicated uml file. These references aren't resolved in the "java execution", while in the "atl execution" they are.

I would explain better the situation...
First of all I initialize a ResourceSet with references to my metamodels , then I load the following resources with an EMFInjector:

  • all metamodels I need: uml2.4 (http://www.eclipse.org/uml2/4.0.0/UML) that is metamodel for input, a custom metamodel in ecore that is the metamodel for output, an UML profile into a .uml file that is used for input model
  • UML model to transform (IN)
  • UML model that is referenced by IN (REF).

I also used these options:
Map<String, Object> options = new HashMap<String,Object>();
options.put("supportUML2Stereotypes", "true");
options.put("allowInterModelReferences","true");

After I use the EMFVMLauncher to perform the transformation in the same way of the example (here) using the options defined before.
At the end I extract the output model with the EMFExtractor and unload everything.
Here the code
public class RunTransfoJava {
	private static final String PROFILE_PATH = new String("metamodels/profile.uml");
	
	public static void main(String[] args) {
		try {
			/*
			 * Initializations
			 */
			ResourceSet resSet = new ResourceSetImpl();
			MyUMLResourceSet.init(resSet);
			MyUMLResourceSet.initProfile(resSet,PROFILE_PATH);
			ILauncher transformationLauncher = new EMFVMLauncher();
			ModelFactory modelFactory = new EMFModelFactory();
			IInjector injector = new EMFInjector();
			IExtractor extractor = new EMFExtractor();
			/*
			 * Load metamodels
			 */
			Map<String, Object> options = new HashMap<String,Object>();
			options.put("supportUML2Stereotypes", "true");
			options.put("allowInterModelReferences","true");
			
			IReferenceModel outputMetamodel = modelFactory.newReferenceModel();
			injector.inject(outputMetamodel, "metamodels/outputMeta.ecore", options);
			IReferenceModel umlMetamodel = modelFactory.newReferenceModel();
			injector.inject(umlMetamodel, "http://www.eclipse.org/uml2/4.0.0/UML", options);
			
			IReferenceModel profileModel = modelFactory.newReferenceModel();
			injector.inject(profileModel, PROFILE_PATH, options);
			IModel refModel = modelFactory.newModel(umlMetamodel);
			injector.inject(refModel,"models/ref.uml",options);
			
			IModel inModel = modelFactory.newModel(umlMetamodel);
			injector.inject(inModel,"models/in.uml", options);
			IModel outputModel = modelFactory.newModel(outputMetamodel);			
			/*
			 * Run transformation
			 */
			transformationLauncher.initialize(new HashMap<String,Object>());
			transformationLauncher.addInModel(inModel, "IN", "UML");
			transformationLauncher.addOutModel(outputModel, "OUT", "OUTMETA");
			transformationLauncher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), options,
				new FileInputStream("transformation/transformation.asm"));
			
			extractor.extract(outputModel, "results/out.xmi", options);
			/*
			 * Unload all models and metamodels (EMF-specific)
			 */
			EMFModelFactory emfModelFactory = (EMFModelFactory) modelFactory;
			emfModelFactory.unload((EMFModel) inModel);
			emfModelFactory.unload((EMFModel) outputModel);
			emfModelFactory.unload((EMFModel) profileModel);
			emfModelFactory.unload((EMFModel) refModel);
			emfModelFactory.unload((EMFReferenceModel) outputMetamodel);
			emfModelFactory.unload((EMFReferenceModel) umlMetamodel);
			
		} catch (ATLCoreException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

}

MyUMLResourceSet is an utility class done by me to initialize a ResourceSet for my purpose.

The output is the transformation of all the elements included into IN, without the specific information that must be taken from REF. I repeat myself: the same transformation launched by ATL run configurator returns the right output model.
Any suggestions? Thanks in advance,
Mauro

[Updated on: Tue, 06 November 2012 10:05]

Report message to a moderator

Re: Launch transformation by java returns different output compared to atl run [message #973543 is a reply to message #973416] Tue, 06 November 2012 12:23 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

I think it may be a similar error as in https://bugs.eclipse.org/bugs/show_bug.cgi?id=353313.
If that's actually the case, a workaround is proposed from https://bugs.eclipse.org/bugs/show_bug.cgi?id=297718.

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: Launch transformation by java returns different output compared to atl run [message #973592 is a reply to message #973543] Tue, 06 November 2012 13:10 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Hugo,
thanks for the reply.
My problem doesn't seem to be related to the use of the profile, but to the referenced uml model.
I also tried with ANT task but I get an output even worse. Maybe in the latter case the problem is the profile, but I'm interested in the first solution.

Regards,
Mauro
Re: Launch transformation by java returns different output compared to atl run [message #981259 is a reply to message #973592] Mon, 12 November 2012 09:25 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
The workaround (NSUri with platform URI in Ant <atl.loadmodel>) works. Thanks
Re: Launch transformation by java returns different output compared to atl run [message #984425 is a reply to message #981259] Wed, 14 November 2012 17:38 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Hi Mauro,

Did your atl transformation code is running with java? Do using UML as IN metamodel?
How did you do that?

I'm asking because I'm trying to run an atl transformation by java, however I'm getting errors when I use an UML file as IN metamodel.

Thanks
Re: Launch transformation by java returns different output compared to atl run [message #985178 is a reply to message #984425] Thu, 15 November 2012 07:58 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Hi Fernanda,
I'm using an ant build file to run the transformation and, yes, the in metamodel is UML.
It is done by "atl.loadModel" ant task:
<atl.loadModel name="UML" metamodel="MOF" nsUri="http://www.eclipse.org/uml2/4.0.0/UML" />

Anyway, you can find in my first post how to load the UML metamodel in java.

Regards,
Mauro
Re: Launch transformation by java returns different output compared to atl run [message #985717 is a reply to message #985178] Thu, 15 November 2012 19:03 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Thanks for your help Mauro, I'll try it.
Re: Launch transformation by java returns different output compared to atl run [message #985719 is a reply to message #985178] Thu, 15 November 2012 19:46 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Mauro,
I had tried to use your example, changing to get my files, however I'm getting an error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/emf/ecore/xmi/impl/XMIResourceFactoryImpl

I couldn't use the "MyUMLResourceSet" and I don't know how to create an ANT file. I thought that was created automatically by eclipse, but not.

Did you use an existing ant file or did you created one?
Re: Launch transformation by java returns different output compared to atl run [message #985789 is a reply to message #985719] Fri, 16 November 2012 08:07 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Hi Fernanda,
MyUMLResourceSet is an utility class created by myself to initialize the ResourceSet. If you are using only UML resources and last uml2 API, you can initialize the ResourceSet in this way:
ResourceSet resourceSet = new ResourceSetImpl();
UMLResourcesUtil.init(resourceSet);

With ANT I used this wiki to create my build file.

Regards,
Mauro
Re: Launch transformation by java returns different output compared to atl run [message #985898 is a reply to message #985789] Fri, 16 November 2012 15:41 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Right,thanks Mauro.
Re: Launch transformation by java returns different output compared to atl run [message #986304 is a reply to message #985898] Mon, 19 November 2012 19:42 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Hello Mauro,
I had never used ant file, so I would know how you call it in java code?
Or it is not necessary?I couldn't access ant wiki, then I don't know if it is there.
Thanks
Re: Launch transformation by java returns different output compared to atl run [message #986445 is a reply to message #986304] Tue, 20 November 2012 12:54 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Mauro, I was seeing your answer and code again, so did you use uml url as in metamodel, right?
I need to use an UML file, maybe using ant build file won't help me with it. Actually, there are two bugs opened because of it, so when I saw your topic I thought maybe I could use it, however, as I said, as I'm using an UML file as in metamodel it won't work properly.

Thanks
Re: Launch transformation by java returns different output compared to atl run [message #986721 is a reply to message #986304] Wed, 21 November 2012 12:54 Go to previous message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Fernanda R.F. wrote on Mon, 19 November 2012 14:42
Hello Mauro,
I had never used ant file, so I would know how you call it in java code?
Or it is not necessary?I couldn't access ant wiki, then I don't know if it is there.
Thanks

I'm not using ANT by java code because it works as it is.
You can try to google ANT if you can't access the wiki.

Previous Topic:Error loading file - org.eclipse.m2m.atl.core.ATLCoreException
Next Topic:Containment references cannot span across models
Goto Forum:
  


Current Time: Thu Mar 28 17:47:15 GMT 2024

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

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

Back to the top