Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to use 2 implementations of the same model ?
icon5.gif  How to use 2 implementations of the same model ? [message #1239076] Mon, 03 February 2014 09:43 Go to next message
Nicolas Boulay is currently offline Nicolas BoulayFriend
Messages: 5
Registered: February 2014
Junior Member
In a project with historical background, we need to use the same model in 2 places. But the model is used "as is" in a case, and is a kind of "proxy", in the other one case.

EMF did not support an easy way to do that, it's hard to have 2 implementations of the same interface, EPackage and Efactory are hard to change. Some static fonctions or object can't be replaced easly.

Creating a new model seems to be a solution by subclassing every concept of the first model. Then the new model are only use with the factory and the package, the object will be fully compatible with the first model.

I supposed that this kind of problem is not rare, did anybody try this solution or some other one ?
Re: How to use 2 implementations of the same model ? [message #1239577 is a reply to message #1239076] Tue, 04 February 2014 14:17 Go to previous messageGo to next message
Nicolas Boulay is currently offline Nicolas BoulayFriend
Messages: 5
Registered: February 2014
Junior Member
Nobody knows the right way to use 2 implementations but for a single model ?
Re: How to use 2 implementations of the same model ? [message #1239849 is a reply to message #1239577] Wed, 05 February 2014 07:36 Go to previous messageGo to next message
Patrick Tournet is currently offline Patrick TournetFriend
Messages: 17
Registered: July 2009
Location: Aix-en-Provence, FRANCE
Junior Member
I know how frustrating it is when you get no answer to one of your question, so, I'm giving yours a try... I'm no expert (far from that, as I'm currently discovering EMF), but if model inheritance seems to be a valid option, as you'd have to modify the inherited one every time you alter your model. That's how you get some inconsistencies...

My best guess, would be to use the exact same model in two different plug-ins. This way, you'd have the same interfaces in two different packages, and should be able to use either one of them depending on where you're in your app.

But as I didn't fully understand your use case it might not be the answer you're looking for... a little more details on what you're up to might be a good idea, then...


I can do anything and I can do it better than anyone. Be as I am : be the best ! Wink

[Updated on: Wed, 05 February 2014 07:38]

Report message to a moderator

Re: How to use 2 implementations of the same model ? [message #1239878 is a reply to message #1239849] Wed, 05 February 2014 08:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I don't think yiou need two plugins.

Two *.genmodels for one *.ecore is why *.genmodel needs to be separate.

If you're careful you can probably arrange for the two generations to
share the same interface and vary only in the *Impl's.

Regards

Ed Willink

On 05/02/2014 07:36, Patrick TOURNET wrote:
> I'm no expert (far from that, as I'm currently discovering EMF), but
> if model inheritance seems to be a valid option, as you'd have to
> modify the inherited one every time you alter your model. That's how
> you get some inconsistencies...
>
> My best guess, would be to use the exact same model in two different
> plug-ins. This way, you'd have the same interfaces in two different
> packages, and should be able to use either one of them depending on
> where you're in your app.
>
> But as I didn't fully understand your use case it might not be the
> answer you're looking for... a little more details on what you're up
> to might be a good idea, then...
Re: How to use 2 implementations of the same model ? [message #1239895 is a reply to message #1239878] Wed, 05 February 2014 09:29 Go to previous messageGo to next message
Mikael Barbero is currently offline Mikael BarberoFriend
Messages: 55
Registered: July 2009
Member
Short answer:
You can't. Even with two genmodels.

Long answer:
This issue is not rare. Actually, I think many users of CDO would be happy to be able to have CDO's implementation along with standard EMF's implementation. It would make obsolete the CDO legacy mode.

Here is the reason. The static singletons initialized with instances of the generated implementation within the XXXPackage and XXXFactory interfaces leaks the implementation into the interfaces. The interfaces are only there to provide to the developer a simpler API to manipulate, but does not give him a chance to swap the implementations for another one.

I did some trials on creating new generators and new EObject implementations to get rid of this static singletons. You can find a presentation about this http://fr.slideshare.net/mikaelbarbero/3mf-infinityandbeyond and the code https://github.com/mbarbero/emf/tree/3mf

You can get some backgrounds on this blog post http://alblue.bandlem.com/2010/11/using-emf-for-osgi-service-creation.html and this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=329209


Best regards,

Mikael Barbero
Obeo
Re: How to use 2 implementations of the same model ? [message #1239914 is a reply to message #1239878] Wed, 05 February 2014 10:13 Go to previous messageGo to next message
Nicolas Boulay is currently offline Nicolas BoulayFriend
Messages: 5
Registered: February 2014
Junior Member
@Patrick:
If i duplicate the model, the object will not be compatible each other. This will be strange for the user.

@Ed:
Using 2 genmodels look great. I will look at it.
Re: How to use 2 implementations of the same model ? [message #1239933 is a reply to message #1239914] Wed, 05 February 2014 10:44 Go to previous messageGo to next message
Nicolas Boulay is currently offline Nicolas BoulayFriend
Messages: 5
Registered: February 2014
Junior Member
@Mikael Barbero: "The static singletons initialized with instances of the generated implementation within the XXXPackage and XXXFactory interfaces leaks the implementation into the interfaces. The interfaces are only there to provide to the developer a simpler API to manipulate, but does not give him a chance to swap the implementations for another one."

I have notice this problem. But do you think that having a second model, where every class are subclass of the first model could do the job ? It looks easier than subclassing Epackage and Efactory to reexecute init() function.
Re: How to use 2 implementations of the same model ? [message #1239999 is a reply to message #1239933] Wed, 05 February 2014 13:49 Go to previous messageGo to next message
Mikael Barbero is currently offline Mikael BarberoFriend
Messages: 55
Registered: July 2009
Member
It depends on your usage of the other 'kind of proxy' model. There are some drawbacks in your solution: it is tedious to maintain, you will certainly have to introduce multiple inheritances in your model so you have to be careful about all code change (e.g. for derived features). Thus, I can't say it will or will not do the job.

If you could describe your use case and why you "need to use the same model in 2 places", we may provide you some help.



Best regards,

Mikael Barbero
Obeo
Re: How to use 2 implementations of the same model ? [message #1240015 is a reply to message #1239999] Wed, 05 February 2014 14:29 Go to previous message
Nicolas Boulay is currently offline Nicolas BoulayFriend
Messages: 5
Registered: February 2014
Junior Member
The model used is a legacy one, that is reused. But the real data are not present inside the EMF class. So you have the legacy EMF model for a previous usage. And some new implementation for the new usage. Same model, same interface, but some different "impl" class.
Previous Topic:Re: [JFace Databinding] Bind EMap value to Text
Next Topic:Create own PropertyDescriptor
Goto Forum:
  


Current Time: Fri Apr 19 08:12:41 GMT 2024

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

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

Back to the top