Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Inject a resource instead of loading it
Inject a resource instead of loading it [message #1795311] Thu, 20 September 2018 09:18 Go to next message
Gunnar Arndt is currently offline Gunnar ArndtFriend
Messages: 82
Registered: June 2012
Member
I perform an ATL transformation programatically in an Eclipse application. That works perfectly with the code generated by the ATL plugin, but this way, it is necessary to provide only the path to the input Resource, which is then loaded automatically in
EMFInjector#inject(IModel targetModel, String source, Map<String, Object> options){ /*...*/}

As the Resource has been created previously and is thus still loaded and connected to another ResourceSet, I would prefer to inject that readily available Resource in order to gain some performance. In order to do so, I have replaced this generated code in Transformate2otx:
public void loadModels(final String inModelPath) throws ATLCoreException {
        final ModelFactory factory = new EMFModelFactory();
        final EMFInjector injector = new EMFInjector();
        final IReferenceModel otxMetamodel = factory.newReferenceModel();
        injector.inject(otxMetamodel, getMetamodelUri("otx"));
        final IReferenceModel transformateMetamodel = factory.newReferenceModel();
        injector.inject(transformateMetamodel, getMetamodelUri("transformate"));
        this.inModel = factory.newModel(transformateMetamodel);
        injector.inject(inModel, inModelPath);
        this.outModel = factory.newModel(otxMetamodel);
    }

by this:
    public void loadModels(final Resource inModelResource) throws ATLCoreException { // Change path to existing resource...
        final ModelFactory factory = new EMFModelFactory();
        final EMFInjector injector = new EMFInjector();
        final IReferenceModel otxMetamodel = factory.newReferenceModel();
        injector.inject(otxMetamodel, getMetamodelUri("otx"));
        final IReferenceModel transformateMetamodel = factory.newReferenceModel();
        injector.inject(transformateMetamodel, getMetamodelUri("transformate"));
        this.inModel = factory.newModel(transformateMetamodel);
        injector.inject(inModel, inModelResource); // ... and use another method to inject it.
        this.outModel = factory.newModel(otxMetamodel);
    }

It fails, however, with the following exception:
Caused by: org.eclipse.m2m.atl.engine.emfvm.VMException
	at org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:643)
	at org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:388)
	at org.eclipse.m2m.atl.engine.emfvm.ASM.run(ASM.java:208)
	at org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher.internalLaunch(EMFVMLauncher.java:170)
	at org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher.launch(EMFVMLauncher.java:139)
	at com.daimler.dat.modeltransformation.atl.files.Transformate2otx.doTransformate2otx(Transformate2otx.java:240)
	at modeltransformation.tasks.DefaultTransformate2OtxTaskStrategy.run(DefaultTransformate2OtxTaskStrategy.java:131)
	... 6 more
Caused by: java.util.NoSuchElementException
	at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:721)
	at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:742)
	at org.eclipse.m2m.atl.engine.emfvm.lib.ExecEnv$100.exec(ExecEnv.java:994)
	at org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:391)
	... 

I assume the problem is that the EMFInjector uses the EMFModelFactory, which creates its own fresh ResourceSet, which has no relationship to the passed Resource - but I am totally uncertain if that is true, and what I might do about it.
Do you have any suggestions how to manage the injection of a previously loaded Resouce? Thanks!

[Updated on: Thu, 20 September 2018 15:20]

Report message to a moderator

Re: Inject a resource instead of loading it [message #1796967 is a reply to message #1795311] Tue, 23 October 2018 09:59 Go to previous messageGo to next message
Gunnar Arndt is currently offline Gunnar ArndtFriend
Messages: 82
Registered: June 2012
Member
Update: The issue does not seem to be caused by the freshly created ResourceSet. I replaced the relevant code by adding a new implementation of EMFModelFactory that uses the "correct", existing ResourceSet and accepts a prevously loaded Resource from that ResourceSet, but that does not change anything about the described bug.

[Updated on: Tue, 23 October 2018 11:01]

Report message to a moderator

Re: Inject a resource instead of loading it [message #1798449 is a reply to message #1796967] Mon, 19 November 2018 10:37 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

The EMFTVM API allows you to work directly with EMF Resources.
The error mentioned is caused by invoking "first()" on an empty OrderedSet.


Cheers,
Dennis
Previous Topic:containment in atl
Next Topic:Using profiles as Metamodels in ATL EMFTVM
Goto Forum:
  


Current Time: Sat Nov 11 08:20:27 GMT 2023

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

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

Back to the top