Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Getting from an EPackage to the EPackage.Registry it was registered with
Getting from an EPackage to the EPackage.Registry it was registered with [message #1231898] Wed, 15 January 2014 17:38 Go to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Hi all,

I'm currently in the process of migrating a library using EMF from using the global EPackage.Registry to using the local registries of ResourceSets. I only use dynamic model instances.

What I do is when loading an instance model, the ecore model's Resource has to be given, too. I create a new ResourceSet, register the ecore model's packages with the ResourceSet's local package registry, and then I load the instance model and add its Resource to the ResourceSet. I do not add the ecore model's Resource to the ResourceSet.

That works, however I'm facing some issues.

Basically, some operations of my library require that I can get to the EClasses defined in the ecore model from (a) EObjects in a conforming instance model and from (b) other EClasses defined in the same ecore model.

I can handle point (a), because from any EObject in an instance model I can navigate up containments until I hit the containing Resource, then get the ResourceSet, and then using that ResourceSet's local package registry to get to the EClasses.

However, I can't handle point (b) right now. As said, I only register the ecore model's packages with the ResourceSet's local package registry, but I do not add the ecore model's resource to the ResourceSet. Of course, I could do that, and then point (b) would be easy, but it would break if I wanted to use the same ecore model Resource in many ResourceSets (because adding a Resource to a ResourceSet removes it from the ResourceSet it was previously in).

So how do I get from an EPackage to the registry it was registered with? Or do I really need to add the Resource with the ecore model to the ResourceSet, and then load it multiple times into new Resources if I want to have many instance models?

Thanks a lot,
Tassilo
Re: Getting from an EPackage to the EPackage.Registry it was registered with [message #1233265 is a reply to message #1231898] Sun, 19 January 2014 04:28 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6445
Registered: July 2009
Senior Member
Am 15.01.2014 18:38, schrieb Tassilo Horn:
> Hi all,
>
> I'm currently in the process of migrating a library using EMF from using the global EPackage.Registry to using the
> local registries of ResourceSets. I only use dynamic model instances.
>
> What I do is when loading an instance model, the ecore model's Resource has to be given, too. I create a new
> ResourceSet, register the ecore model's packages with the ResourceSet's local package registry, and then I load the
> instance model and add its Resource to the ResourceSet.
This "load+add" should be done via:

resourceSet.getResource(URI, true);


> I do not add the ecore model's Resource to the ResourceSet.
Ok.

>
> That works, however I'm facing some issues.
>
> Basically, some operations of my library require that I can get to the EClasses defined in the ecore model from (a)
> EObjects in a conforming instance model and from
That is:

EClass eClass = instance.eClass();

> (b) other EClasses defined in the same ecore model.
That is:

for(EClassifier eClassifier : eClass.getEPackage().getEClassifiers())
{
if (eClassifier instanceof EClass)
...

>
> I can handle point (a), because from any EObject in an instance model I can navigate up containments until I hit the
> containing Resource, then get the ResourceSet, and then using that ResourceSet's local package registry to get to the
> EClasses.
>
> However, I can't handle point (b) right now. As said, I only register the ecore model's packages with the
> ResourceSet's local package registry, but I do not add the ecore model's resource to the ResourceSet. Of course, I
> could do that, and then point (b) would be easy, but it would break if I wanted to use the same ecore model Resource
> in many ResourceSets (because adding a Resource to a ResourceSet removes it from the ResourceSet it was previously in).
>
> So how do I get from an EPackage to the registry it was registered with?
That's not possible unless you put a custom Adapter on the EPackage at the time you register it:

ePackage.eAdapters().add(new MyPackageAdapter(registry));
registry.put(ePackage.getNSURI(), ePackage);

Note that an EPackage can be registered with multiple registries, so you'll have to iterate over the adapters later.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> Or do I really need to add the Resource with the ecore model to the ResourceSet, and then load it multiple times into
> new Resources if I want to have many instance models?
>
> Thanks a lot,
> Tassilo


Re: Getting from an EPackage to the EPackage.Registry it was registered with [message #1233667 is a reply to message #1233265] Mon, 20 January 2014 08:31 Go to previous message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Thanks, Eike!
Previous Topic:Persisting object as XMI using Ecore model
Next Topic:create Proxy objects
Goto Forum:
  


Current Time: Thu Sep 19 18:41:42 GMT 2019

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

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

Back to the top