Home » Modeling » EMF » Generated Model Code- ******.impl get, set properties (Set propery code for multiple upper bound references doesn't exist )
|
Re: Generated Model Code- ******.impl get, set properties [message #1488221 is a reply to message #1488141] |
Wed, 26 November 2014 12:14 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Basheer,
Comments below.
On 26/11/2014 11:45 AM, Basheer Jasser wrote:
> Hi,
> I was exploring the get, set properties for the generated model code
> for a specific meta-model I'm working on.
> I observed that the E-reference with 0-1 upper boundary has set, get
> properties, but the E-references with 0-* upper boundary (multiple)
> has only get property while there isn't set property. I need to
> access this set property to get a some intended behavior.
There isn't one and one isn't needed.
>
> is there any idea about how these multiple E-references list values
> being set ?
They're not set. The list that's returned is the state of the model and
you can modify it directly using the List/EList APIs. You might use a
utility like org.eclipse.emf.common.util.ECollections.setEList(EList<T>,
List<? extends T>), but unless the list isn't currently empty,
List.addAll is just as good.
> Thank you in advance Basheer
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Generated Model Code- ******.impl get, set properties [message #1488357 is a reply to message #1488302] |
Wed, 26 November 2014 14:39 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Basheer,
Comments below.
On 26/11/2014 2:43 PM, Basheer Jasser wrote:
> Thanks Ed for your reply. it helped me to start with something for my
> aim. now Actually I'm having some other issue: using the generated
> model code for multiple variable or references, there exists the
> method "public void eSet(int featureID, Object newValue) {}" and it
> is used to set the list as you mentioned (list.addAll).
Yes, it does a clear and an addAll.
> I'm having EClass IncludedMachine which is referencing itself by
> shares EReference which has multiple values (means that every included
> machine may share with more than one). For example I may have three
> instances im1, im2 and im3 of IncludedMachine E-class
> Setting this property of one included machine im1 to the value im2 is
> done only in one side of im1 , and I want to happen in the other side
> im2 to save user time of process repetition. I'm trying to do that
> using eSet(int featureID, Object newValue) method which is generated
> in the model code IncludedMachineimpl.java but I'm not really sure how
> to do that ?
It sounds like you want a bidirectional reference.
> I tried doing that similarly for single valued self E-reference, and
> the behavior was unexpected and the debugger was unable to run perfectly.
What behavior? What does that have to do with running the debugger?
> Any idea of what to do to set the E-reference in the opposite side im2
> instance while setting the E-reference for this im1 instance ??
It sounds like you want something like two EReferences, i.e.,
Machine.includes and Machine.includers both can be multi-valued of type
Machine and they can be each other's eOpposites. Then if you have two
instance m1 and m2 and do m1.getIncludes().add(m2) you'll find
afterwards m2.getIcluders().contains(m1) is true.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Generated Model Code- ******.impl get, set properties [message #1489197 is a reply to message #1488961] |
Thu, 27 November 2014 07:00 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Basheer,
Comments below.
On 27/11/2014 3:24 AM, Basheer Jasser wrote:
> Yes Actually I need bidirectional E-References, but the issue is not
> about including machine m1 and included one m2. it about two machine
> which share some property
And what's a property?
> and they are exactly equal in roles,
What are roles? What do equal roles mean?
> there is no difference between m1 and m2 and they both should have the
> same role for each other (which is shares property).
It sounds like you're suggesting it's similar to previous posts of the
idea, Person.friends, where presumably friendship is mutual. This can't
be directly modeled with Ecore (nor EMOF nor UML) because bidirectional
references must be a pair of references (or with UML, and association
must have two different ends). You get into the odd situation of things
like can a Person be their own friend; in the bidirectional hand shaking
this would require special handling.
>
> the issue is that I observed before, while exploring previous
> topics,that bidirectional E-References are not allowed in the E-core
> model (E-Opposite property).
The eOpposite must be a different reference, yes.
> So I'm trying to handle this using java model code for both single
> values and multiple values E-references.
You'd need a special list implementation. It's hard to imagine the
single valued case being useful for anything in the real world. And
even in general, there always seems to be some directionality involved,
i.e., Person.friends doesn't deal with the fact that while I might
consider someone my friend, they might not consider me their friend.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: Generated Model Code- ******.impl get, set properties [message #1489602 is a reply to message #1489538] |
Thu, 27 November 2014 14:13 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Basheer,
Comments below.
On 27/11/2014 2:02 PM, Basheer Jasser wrote:
> Ed, Thanks a lot for your replies.
>
> in the E-core model Machine E-class is sharing itself. During the run
> time I have M1 and M2 as instances of Machine E-class. When setting
> (M1.shares = M2) then (M2.shares=null).
Are these like toy examples? I've already explained that an EReference
can't be its own opposite. Sorry about that, but it's the way it is.
> What I want is when setting shares property for M1 (M1.shares=M2), M2
> shares property is also set to M1 automatically (M2.shares=M1).
Like a bidirectional reference but I've explained that just doesn't work.
> Because the relationship between M1 and M2 is reflexive.
Yes, presumably like friendship.
> For the time being, I should set the shares property for both M1 and
> M2 using two processes while I'm trying to save it in one process to
> make more usable and applicable.
I have to wonder what it's used for and what it's applicable too.
> I'm trying to do it using jave model code eSet (){} method (multiple
> values) setShares(){} (single value). Any advice in this context ???
Don't try. Implementing directional references is extremely
complicated and you won't get it right, ever. And even if you did get
it right, the framework won't expect the behavior you've implemented, so
and command framework won't work, notifications will be confusing to the
adapter/listeners, you'll have a hard time deserializing the results,
copying the objects, and so on. It's a rat hole that you ought to avoid.
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Generated Model Code- ******.impl get, set properties [message #1490266 is a reply to message #1489602] |
Fri, 28 November 2014 03:02 |
Basheer Jasser Messages: 23 Registered: September 2014 Location: University Putra Malaysia... |
Junior Member |
|
|
Ed., below are my comments
> in the E-core model Machine E-class is sharing itself. During the run
> time I have M1 and M2 as instances of Machine E-class. When setting
> (M1.shares = M2) then (M2.shares=null).
Are these like toy examples? I've already explained that an EReference
can't be its own opposite. Sorry about that, but it's the way it is.
* Actually these are part of research project UML-B and Event-B in which EMF is used for UML-B meta-model.
> What I want is when setting shares property for M1 (M1.shares=M2), M2
> shares property is also set to M1 automatically (M2.shares=M1).
Like a bidirectional reference but I've explained that just doesn't work.
* In this project I really need the situation to be like that M1 is sharing a property with M2 and same applies to M2.
> Because the relationship between M1 and M2 is reflexive.
Yes, presumably like friendship.
* relationship between M1 and M2 is reflexive and it should be like that for my theoretical aim.
> For the time being, I should set the shares property for both M1 and
> M2 using two processes while I'm trying to save it in one process to
> make more usable and applicable.
I have to wonder what it's used for and what it's applicable too.
* if I only allow M1 to share with M2, it means that only M1 has access to M2 attributes and events which is not the intended case. That's why I need also to make M2 shares its attributes and events with M1. May be this way is E-reference is not the best way to do it, but theoretically this is how want it to be for my aim.
> I'm trying to do it using jave model code eSet (){} method (multiple
> values) setShares(){} (single value). Any advice in this context ???
Don't try. Implementing directional references is extremely
complicated and you won't get it right, ever. And even if you did get
it right, the framework won't expect the behavior you've implemented, so
and command framework won't work, notifications will be confusing to the
adapter/listeners, you'll have a hard time deserializing the results,
copying the objects, and so on. It's a rat hole that you ought to avoid.
* maybe I should change the recent meta-model trying to achieve my theoretical aim, or I just stick with adding both shares properties through two steps for both M1 and M2. And really thank you for alerting me trying this way so that I save my time and don't try something unavailable to be implemented.
|
|
|
Re: Generated Model Code- ******.impl get, set properties [message #1490478 is a reply to message #1490266] |
Fri, 28 November 2014 07:13 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Basheer,
Notice that EReference.eOpposite itself is of this nature and there too
it cannot be made its own opposite and so both sides must be set
explicitly and there is a constraint define that checks that the
r.getEOpposite() == null || r.getEOpposite().getEOpposite() == r. In
this case the generated item provider is modified so that the user in
the editor does not need to set both sides
On 28/11/2014 4:02 AM, Basheer Jasser wrote:
> Ed., below are my comments
>
>> in the E-core model Machine E-class is sharing itself. During the run
>> time I have M1 and M2 as instances of Machine E-class. When setting
>> (M1.shares = M2) then (M2.shares=null).
> Are these like toy examples? I've already explained that an EReference
> can't be its own opposite. Sorry about that, but it's the way it is.
>
> * Actually these are part of research project UML-B and Event-B in
> which EMF is used for UML-B meta-model.
>> What I want is when setting shares property for M1 (M1.shares=M2), M2
>> shares property is also set to M1 automatically (M2.shares=M1).
> Like a bidirectional reference but I've explained that just doesn't work.
>
> * In this project I really need the situation to be like that M1 is
> sharing a property with M2 and same applies to M2.
>> Because the relationship between M1 and M2 is reflexive.
> Yes, presumably like friendship.
>
> * relationship between M1 and M2 is reflexive and it should be like
> that for my theoretical aim.
>> For the time being, I should set the shares property for both M1 and
>> M2 using two processes while I'm trying to save it in one process to
>> make more usable and applicable.
> I have to wonder what it's used for and what it's applicable too.
>
> * if I only allow M1 to share with M2, it means that only M1 has
> access to M2 attributes and events which is not the intended case.
> That's why I need also to make M2 shares its attributes and events
> with M1. May be this way is E-reference is not the best way to do it,
> but theoretically this is how want it to be for my aim.
>> I'm trying to do it using jave model code eSet (){} method (multiple
>> values) setShares(){} (single value). Any advice in this context ???
> Don't try. Implementing directional references is extremely
> complicated and you won't get it right, ever. And even if you did get
> it right, the framework won't expect the behavior you've implemented, so
> and command framework won't work, notifications will be confusing to the
> adapter/listeners, you'll have a hard time deserializing the results,
> copying the objects, and so on. It's a rat hole that you ought to avoid.
>
> * maybe I should change the recent meta-model trying to achieve my
> theoretical aim, or I just stick with adding both shares properties
> through two steps for both M1 and M2. And really thank you for
> alerting me trying this way so that I save my time and don't try
> something unavailable to be implemented.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Generated Model Code- ******.impl get, set properties [message #1494186 is a reply to message #1493885] |
Mon, 01 December 2014 08:47 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Basheer,
No, that's not what I'm suggesting. I'm suggesting you do something
like what's done in
org.eclipse.emf.ecore.provider.EReferenceItemProvider.addEOppositePropertyDescriptor(Object).
I.e., ensure that in the editor you get this automatic behavior to make
life easier for the user, but just live with the behavior in the
programmatic API itself.
On 01/12/2014 4:00 AM, Basheer Jasser wrote:
> Ed,
> are you suggesting adding OCL constraint in order to fulfill the
> requirement of automatically adding the E-Opposite without the user
> intervention ?
> if so., I started doing that with opening Ecore model using
> OCLineEcore Editor, and adding the necessary operation and invariant.
> This eventually must be reflected in the generated java item provider.
> Am I on the right way of doing it ??
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Goto Forum:
Current Time: Wed Sep 25 15:18:20 GMT 2024
Powered by FUDForum. Page generated in 0.09529 seconds
|