Inject a resource instead of loading it [message #1795311] |
Thu, 20 September 2018 09:18 |
Gunnar Arndt 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01471 seconds