Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output
[ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #697901] Mon, 18 July 2011 10:08 Go to next message
Eszter Hofmann is currently offline Eszter Hofmann
Messages: 16
Registered: July 2011
Junior Member
Hello,

I am experimenting with ATL these days. As far as I understood the input and the output of a transformation is an XMIResourceImpl instance. I have as input the instance of my source metamodel and I also need as output an instance of the target metamodel and not DynamicEObjectImpl instances. Is there an elegant way to do this? How can I make the conversion between DynamicEObjImpl instances and "MyModelImpl" instances?

Thanks,
Eszter
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #698018 is a reply to message #697901] Mon, 18 July 2011 15:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
Eszter,

As long as your models are available/registered in the package registry,
the deserializer should find a use them.


On 18/07/2011 3:08 AM, Eszter Hofmann wrote:
> Hello,
>
> I am experimenting with ATL these days. As far as I understood the
> input and the output of a transformation is an XMIResourceImpl
> instance. I have as input the instance of my source metamodel and I
> also need as output an instance of the target metamodel and not
> DynamicEObjectImpl instances. Is there an elegant way to do this? How
> can I make the conversion between DynamicEObjImpl instances and
> "MyModelImpl" instances?
>
> Thanks,
> Eszter
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #698404 is a reply to message #698018] Tue, 19 July 2011 12:32 Go to previous messageGo to next message
Eszter Hofmann is currently offline Eszter Hofmann
Messages: 16
Registered: July 2011
Junior Member
Hi,

for launching the transformation I am using the main method generated by the New > ATL Plugin Wizard.
In the method loadModels I registered my packages:
public void loadModels(String inModelPath) throws ATLCoreException {
  ModelFactory factory = new EMFModelFactory();
  ResourceSet resourceSet = factory.getResourceSet();
  Registry registry = factory.getResourceSet().getPackageRegistry();
  
  Map<String, Object> extMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
  extMap.put("ecore", new EcoreResourceFactoryImpl()); //$NON-NLS-1$
  extMap.put("cache", new CacheResourceFactoryImpl());
  extMap.put("om", new OMResourceFactoryImpl());

  CachePackage.eINSTANCE.eClass();
  OmPackage.eINSTANCE.eClass();

  registry.put(CachePackage.eNS_URI, CachePackage.eINSTANCE);
  registry.put(OmPackage.eNS_URI, OmPackage.eINSTANCE);

  // the generated code
  IInjector injector = new EMFInjector();
  IReferenceModel cacheMetamodel = factory.newReferenceModel();
  injector.inject(cacheMetamodel, getMetamodelUri("cache"));
  IReferenceModel omMetamodel = factory.newReferenceModel();
  injector.inject(omMetamodel, getMetamodelUri("om"));
  this.inModel = factory.newModel(cacheMetamodel);
  injector.inject(inModel, inModelPath);
  this.outModel = factory.newModel(omMetamodel);
}

Now loading works fine, but as result I still get DynamicEObjImpl instances.
I also tried to register my packages to the global package registry, but the result didn't change.
What else am I missing?

Eszter
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #698537 is a reply to message #698404] Tue, 19 July 2011 16:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
What's the nsURI of the model for which you're ending up with dynamic
instances, i.e., what's the value of
eObject.eClass().getEPackage().getNsURI() for the problematic
instance? Is that URI registered?


On 19/07/2011 5:32 AM, Eszter Hofmann wrote:
> Hi,
>
> for launching the transformation I am using the main method generated
> by the New > ATL Plugin Wizard.
> In the method loadModels I registered my packages:
> public void loadModels(String inModelPath) throws ATLCoreException {
> ModelFactory factory = new EMFModelFactory();
> ResourceSet resourceSet = factory.getResourceSet();
> Registry registry = factory.getResourceSet().getPackageRegistry();
>
> Map<String, Object> extMap =
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
> extMap.put("ecore", new EcoreResourceFactoryImpl()); //$NON-NLS-1$
> extMap.put("cache", new CacheResourceFactoryImpl());
> extMap.put("om", new OMResourceFactoryImpl());
>
> CachePackage.eINSTANCE.eClass();
> OmPackage.eINSTANCE.eClass();
>
> registry.put(CachePackage.eNS_URI, CachePackage.eINSTANCE);
> registry.put(OmPackage.eNS_URI, OmPackage.eINSTANCE);
>
> // the generated code
> IInjector injector = new EMFInjector();
> IReferenceModel cacheMetamodel = factory.newReferenceModel();
> injector.inject(cacheMetamodel, getMetamodelUri("cache"));
> IReferenceModel omMetamodel = factory.newReferenceModel();
> injector.inject(omMetamodel, getMetamodelUri("om"));
> this.inModel = factory.newModel(cacheMetamodel);
> injector.inject(inModel, inModelPath);
> this.outModel = factory.newModel(omMetamodel);
> }
>
> Now loading works fine, but as result I still get DynamicEObjImpl
> instances.
> I also tried to register my packages to the global package registry,
> but the result didn't change.
> What else am I missing?
>
> Eszter
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #698932 is a reply to message #698537] Wed, 20 July 2011 13:56 Go to previous messageGo to next message
Eszter Hofmann is currently offline Eszter Hofmann
Messages: 16
Registered: July 2011
Junior Member
The NS_URI of the instances is http://www.eh.com/ducx/model/2011/om, same as OmPackage.eNS_URI that I used here
registry.put(OmPackage.eNS_URI, OmPackage.eINSTANCE);

I also added these lines, but still no improvement:
Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
uriMap.put(URI.createURI("http://www.eh.com/ducx/cache"),
	URI.createFileURI("E:/workspaces/workspacemodelling/org.eclipse.m2m.atl.cachetoomplugin/Resource/cache.ecore"));
uriMap.put(URI.createURI("http://www.eh.com/ducx/model/2011/om"),
 	URI.createFileURI("E:/workspaces/workspacemodelling/org.eclipse.m2m.atl.cachetoomplugin/Resource/om.ecore"));
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #698952 is a reply to message #698932] Wed, 20 July 2011 14:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
Eszter,

Comments below.

On 20/07/2011 6:56 AM, Eszter Hofmann wrote:
> The NS_URI of the instances is http://www.eh.com/ducx/model/2011/om,
> same as OmPackage.eNS_URI that I used here
> registry.put(OmPackage.eNS_URI, OmPackage.eINSTANCE);
Set a breakpoint in XMLHandler.getPackageForURI and see why it's not
finding the package for that URI.
> I also added these lines, but still no improvement:
>
> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
> uriMap.put(URI.createURI("http://www.eh.com/ducx/cache"),
> URI.createFileURI("E:/workspaces/workspacemodelling/org.eclipse.m2m.atl.cachetoomplugin/Resource/cache.ecore"));
>
> uriMap.put(URI.createURI("http://www.eh.com/ducx/model/2011/om"),
This is exactly the type of thing that could cause it to use a dynamic
model.
> URI.createFileURI("E:/workspaces/workspacemodelling/org.eclipse.m2m.atl.cachetoomplugin/Resource/om.ecore"));
>
>
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #699294 is a reply to message #698952] Thu, 21 July 2011 09:46 Go to previous messageGo to next message
Eszter Hofmann is currently offline Eszter Hofmann
Messages: 16
Registered: July 2011
Junior Member
Hi Ed,

million thanks for this precious breakpoint location! I figured out a few things:
1. In my cache2om.properties file I had to use instead of the metamodel paths the nrUris, otherwise the EMFInjector replaces my OmPackageImpl and CachePackageImpl with ObjectEPackageImpl.
2. Also without all the initialization source code that I wrote in the previous posts the packages were correctly registered ... which I don't understand exactly yet.
3. The method XMLHandler.getPackageForURI method was not called at all for my http://www.eh.com/ducx/model/2011/om but in the end now I get om istances!!

So my problem is solved, but I still need to figure out a few things, otherwise I end up thinking that there is some black magic inthere Razz

Thanks a lot!
Re: [ATL] Using own model implementation instances instead of DynamicEObjImpl as in/output [message #699311 is a reply to message #699294] Thu, 21 July 2011 10:15 Go to previous message
Eszter Hofmann is currently offline Eszter Hofmann
Messages: 16
Registered: July 2011
Junior Member
Ok. point 2 is no black magic, I didn't delete my package registration lines.
Previous Topic:[ATL] Calling methods defined in Java in ATL transformations
Next Topic:Helper returns a sequence or set
Goto Forum:
  


Current Time: Sun Sep 21 12:22:11 GMT 2014

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

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