[ATL] identity of EClass instances in ASMEMFModel.loadASMEMFModel? [message #81973] |
Wed, 21 May 2008 21:17 |
Bruno Haible Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Hi,
Is there any way to create an ASMEMFModel from a *.ecore file,
while at the same time reusing the EClass instances already in memory
from an EMF-generated Ecore model?
I have a set of Java classes, generated by EMF for an Ecore model.
I also have a set of instances of these Java classes, and wish to use
them as input to an ATL transformation, without serializing to XML and
back.
The source model is in fact the 'extlibrary' model from the
org.eclipse.emf.examples.library plugin; nothing of my own.
When I use the following code:
Library lib = EXTLibraryFactory.eINSTANCE.createLibrary();
URL sourceModelFile =
EXTLibraryFactory.class.getClassLoader()
.getResource("/extlibrary.ecore");
AtlEMFModelHandler modelHandler =
(AtlEMFModelHandler)
AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
ASMEMFModel metaModel = (ASMEMFModel)modelHandler.getMof();
EMFModelLoader loader = new EMFModelLoader();
ASMEMFModel sourceModel =
ASMEMFModel.loadASMEMFModel("extlibrary", metaModel,
sourceModelFile, loader);
ASMEMFModel source =
(ASMEMFModel)loader.newModel("IN", "IN", sourceModel);
the 'lib' variable will be an instance of LibraryImpl, and its
Ecore class is an instance of EClassImpl which has a non-null
'instanceClass' field (namely the LibraryImpl class).
The loadASMEMFModel statement, however, creates new EClassImpl
instances. The EClassImpl for "Library" created here will have a
null 'instanceClass' field and a null 'instanceClassName' field.
This has the negative effect that when I add the 'lib' object
to the 'source' model, it will not be recognized correctly:
After I do
source.getASMModelElement(lib);
source.getExtent().getContents().add(lib);
the call
source.getElementsByType("Library")
still returns null, because from the string "Library" it
fetched the EClassImpl that was created during loadASMEMFModel,
which is *different* from the class to which the 'lib' object
belongs.
I can not use the 'source' model as input to ATL in such a
situation - the ATL output is empty.
I believe this is the same problem as mentioned in
http://www.sciences.univ-nantes.fr/lina/atl/www/atl_discussi on_archive/1021.html
The same problem is also blocking on the target side: I want
to generate instances of an EMF-compiled target model, not
instances of org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
the latter is likely to be the outcome when instantiating an EClass
which has a null 'instanceClass' and null 'instanceClassName'.
What's the solution? Can loadASMEMFModel be made to reuse existing
EClass instances?
Bruno
|
|
|
Powered by
FUDForum. Page generated in 0.02943 seconds