Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Ecore2Ecore Mapping when target has multiple packages
Ecore2Ecore Mapping when target has multiple packages [message #542582] Fri, 25 June 2010 11:31 Go to next message
Nirmal SasidharanFriend
Messages: 120
Registered: July 2009
Location: Germany
Senior Member
I am trying to use Ecore2Ecore to migrate Ecore models. In my source model I have only a single package, but in my target I have multiple packages. I am able to use the Ecore2Écore editor to do the mapping, but I am not sure how to register the namespace URIs when I create ExtendedMetadata in such a case. (The EMF recipe talks about the scenario of single packages).

I am trying to register both my target packages as below. But of course, this doesn't work.

EPackage sourcePackage = SourcePackage.eINSTANCE;
EPackage targetPackage1 = TargetPackage1.eINSTANCE;
EPackage targetPackage2 = TargetPackage2.eINSTANCE;
EPackage.Registry ePackageRegistry = resourceSet.getPackageRegistry();
ePackageRegistry.put(sourcePackage.getNsURI(), targetPackage1);
ePackageRegistry.put(sourcePackage.getNsURI(), targetPackage2);
ePackageRegistry.put(TARGET_PLATFORM_URI, targetPackage1);
ePackageRegistry.put(TARGET_PLATFORM_URI, targetPackage2);
Ecore2XMLRegistry ecore2xmlRegistry = new Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
ecore2xmlRegistry.put(sourcePackage.getNsURI(), EcoreUtil.getObjectByType(
           resourceSet.getResource(URI.createURI(SOURCE2TARGET_PLATFORM_URI), true)
            .getContents(), Ecore2XMLPackage.Literals.XML_MAP));
extendedMetaData = new Ecore2XMLExtendedMetaData(ePackageRegistry,
          ecore2xmlRegistry);


Do you think Ecore2Ecore could be used in such cases?

Thanks in advance,

Regards,
Nirmal
Re: Ecore2Ecore Mapping when target has multiple packages [message #543220 is a reply to message #542582] Mon, 28 June 2010 17:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Nirmal,

Comments below.

Nirmal Sasidharan wrote:
> I am trying to use Ecore2Ecore to migrate Ecore models. In my source
> model I have only a single package, but in my target I have multiple
> packages. I am able to use the Ecore2Écore editor to do the mapping,
> but I am not sure how to register the namespace URIs when I create
> ExtendedMetadata in such a case. (The EMF recipe talks about the
> scenario of single packages).
>
> I am trying to register both my target packages as below. But of
> course, this doesn't work.
>
>
> EPackage sourcePackage = SourcePackage.eINSTANCE;
> EPackage targetPackage1 = TargetPackage1.eINSTANCE;
> EPackage targetPackage2 = TargetPackage2.eINSTANCE;
> EPackage.Registry ePackageRegistry = resourceSet.getPackageRegistry();
> ePackageRegistry.put(sourcePackage.getNsURI(), targetPackage1);
> ePackageRegistry.put(sourcePackage.getNsURI(), targetPackage2);
That's going to replace the previous setting...
> ePackageRegistry.put(TARGET_PLATFORM_URI, targetPackage1);
> ePackageRegistry.put(TARGET_PLATFORM_URI, targetPackage2);
Same here.
> Ecore2XMLRegistry ecore2xmlRegistry = new
> Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
> ecore2xmlRegistry.put(sourcePackage.getNsURI(),
> EcoreUtil.getObjectByType(
>
> resourceSet.getResource(URI.createURI(SOURCE2TARGET_PLATFORM _URI), true)
> .getContents(), Ecore2XMLPackage.Literals.XML_MAP));
> extendedMetaData = new Ecore2XMLExtendedMetaData(ePackageRegistry,
> ecore2xmlRegistry);
I think you'll have to write more specialized code for looking up
EClasses so that more than one package is considered.
>
>
> Do you think Ecore2Ecore could be used in such cases?
It's more an issue with the XML mapping.
>
> Thanks in advance,
>
> Regards,
> Nirmal
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Ecore2Ecore Mapping when target has multiple packages [message #543408 is a reply to message #543220] Tue, 29 June 2010 11:15 Go to previous messageGo to next message
Nirmal SasidharanFriend
Messages: 120
Registered: July 2009
Location: Germany
Senior Member
Hello Ed,

Thanks for your reply.

My requirement has changed slightly. This might make the multiple target package issue slightly simpler.

This is what I need to do.

I need to persist "Model A" as "Model B". "Model A" is already loaded. It is in a resource which is not XMI based, but rather connects to a database. I need to serialize this into "Model B" (a subset of "Model A") which would be in a XMI resource.

This is what I am trying to do.

1. In my Ecore2Ecore mapping I take "Model A" as target as "Model B" as source.
2. I create BasicExtendedMetadata and set it to the DefaultSaveOptions.
3. I create a new resource with the BasicExtendedMetadata above attached and add all contents from "Model A" to the new resource.
4. I save the new resource

Now I have "Model A" saved as "Model B". This works fine. The only problem is, even unmapped features appear in the output.

I tried using my own ResourceHandler and look into the resource during preSave(), but there are no AnyType to remove.

Could you please let me know if my overall approach is correct and what do I need to do to make the last part (ignoring unmapped features) work?

Thanks in advance,

Nirmal

[Updated on: Tue, 29 June 2010 11:52]

Report message to a moderator

Re: Ecore2Ecore Mapping when target has multiple packages [message #543479 is a reply to message #543408] Tue, 29 June 2010 14:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Nirmal,

You'll have to dig more deeply into XMLSaveImpl to specialize methods
like shouldSaveFeature.


Nirmal Sasidharan wrote:
> Hello Ed,
>
> Thanks for your reply.
> My requirement has changed slightly. This might make the multiple
> target package issue slightly simpler.
>
> This is what I need to do.
>
> I need to persist "Model A" as "Model B". "Model A" is already loaded.
> It is in a resource which is not XMI based, but rather connects to a
> database. I need to serialize this into "Model B" (a subset of "Model
> A") which would be in a XMI resource.
>
> This is what I am trying to do.
>
> 1. In my Ecore2Ecore mapping I take "Model A" as target as "Model B"
> as source.
> 2. I create BasicExtendedMetadata and set it to the
> DefaultSaveOptions. 3. I create a new resource with the
> BasicExtendedMetadata above attached and add all contents from "Model
> A" to the new resource.
> 4. I save the new resource
>
> Now I have "Model A" saved as "Model B". This works fine. The only
> problem is, even unmapped features appear in the output.
>
> I tried using my own ResourceHandler and look into the resource during
> preSave(), but there are no AnyType to remove.
>
> Could you please let me know if my overall approach is correct and
> what do I need to do to make the last part (ignoring unmapped features
> work)?
>
> Thanks in advance,
>
> Nirmal
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Ecore2Ecore Mapping when target has multiple packages [message #543502 is a reply to message #543479] Tue, 29 June 2010 15:36 Go to previous messageGo to next message
Nirmal SasidharanFriend
Messages: 120
Registered: July 2009
Location: Germany
Senior Member
Thanks Ed. It worked by extending XMISaveImpl.

Nirmal
Re: Ecore2Ecore Mapping when target has multiple packages [message #623020 is a reply to message #543220] Tue, 29 June 2010 11:15 Go to previous messageGo to next message
Nirmal SasidharanFriend
Messages: 120
Registered: July 2009
Location: Germany
Senior Member
Hello Ed,

Thanks for your reply.

My requirement has changed slightly. This might make the multiple target package issue slightly simpler.

This is what I need to do.

I need to persist "Model A" as "Model B". "Model A" is already loaded. It is in a resource which is not XMI based, but rather connects to a database. I need to serialize this into "Model B" (a subset of "Model A") which would be in a XMI resource.

This is what I am trying to do.

1. In my Ecore2Ecore mapping I take "Model A" as target as "Model B" as source.
2. I create BasicExtendedMetadata and set it to the DefaultSaveOptions.
3. I create a new resource with the BasicExtendedMetadata above attached and add all contents from "Model A" to the new resource.
4. I save the new resource

Now I have "Model A" saved as "Model B". This works fine. The only problem is, even unmapped features appear in the output.

I tried using my own ResourceHandler and look into the resource during preSave(), but there are no AnyType to remove.

Could you please let me know if my overall approach is correct and what do I need to do to make the last part (ignoring unmapped features work)?

Thanks in advance,

Nirmal
Re: Ecore2Ecore Mapping when target has multiple packages [message #623021 is a reply to message #623020] Tue, 29 June 2010 14:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Nirmal,

You'll have to dig more deeply into XMLSaveImpl to specialize methods
like shouldSaveFeature.


Nirmal Sasidharan wrote:
> Hello Ed,
>
> Thanks for your reply.
> My requirement has changed slightly. This might make the multiple
> target package issue slightly simpler.
>
> This is what I need to do.
>
> I need to persist "Model A" as "Model B". "Model A" is already loaded.
> It is in a resource which is not XMI based, but rather connects to a
> database. I need to serialize this into "Model B" (a subset of "Model
> A") which would be in a XMI resource.
>
> This is what I am trying to do.
>
> 1. In my Ecore2Ecore mapping I take "Model A" as target as "Model B"
> as source.
> 2. I create BasicExtendedMetadata and set it to the
> DefaultSaveOptions. 3. I create a new resource with the
> BasicExtendedMetadata above attached and add all contents from "Model
> A" to the new resource.
> 4. I save the new resource
>
> Now I have "Model A" saved as "Model B". This works fine. The only
> problem is, even unmapped features appear in the output.
>
> I tried using my own ResourceHandler and look into the resource during
> preSave(), but there are no AnyType to remove.
>
> Could you please let me know if my overall approach is correct and
> what do I need to do to make the last part (ignoring unmapped features
> work)?
>
> Thanks in advance,
>
> Nirmal
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Ecore2Ecore Mapping when target has multiple packages [message #623022 is a reply to message #543479] Tue, 29 June 2010 15:36 Go to previous message
Nirmal SasidharanFriend
Messages: 120
Registered: July 2009
Location: Germany
Senior Member
Thanks Ed. It worked by extending XMISaveImpl.

Nirmal
Previous Topic:Ecore2Ecore Mapping when target has multiple packages
Next Topic:[EEF] Using Ecore consisting of subpackages fails
Goto Forum:
  


Current Time: Thu Mar 28 11:06:53 GMT 2024

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

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

Back to the top