Home » Modeling » EMF » issue with EMF proxy, EOpposite, and Adapters(An EMF object with EOpposite relations is not updated when a Proxy is Replaced by a real EObject)
issue with EMF proxy, EOpposite, and Adapters [message #1802952] |
Tue, 19 February 2019 14:50 |
Patrik Suzzi Messages: 2 Registered: February 2018 |
Junior Member |
|
|
Hi All,
I have an issue with EMF proxy, EOpposite, and Adapters and I would like to get advice from the community.
In my model, I have a Mapping object referencing two classes: ClassA and ClassB. These mappings are EOpposites. (please, see the image below representing the model)
When running, we could have Proxies, and because of this we hit a bug:
- When we set a proxy in our Mapping Object, the framework sets the proxy as EOpposite.
- When the framework replaces the proxy with a real EObject, the Opposite relation is gone. (BUG)
I took a look at the generated code, and I observed that:
Mapping.setFirst(.) correctly removes and adds again the inverses calling eInverseRemove() and eInverseAdd() (see snippet below)
public void setFirst(ElementA newFirst) {
if (newFirst != first) {
NotificationChain msgs = null;
if (first != null)
msgs = ((InternalEObject)first).
eInverseRemove(this, ApplicationPackage.ELEMENT_A__MAPPINGS_A, ElementA.class, msgs);
if (newFirst != null)
msgs = ((InternalEObject)newFirst).
eInverseAdd(this, ApplicationPackage.ELEMENT_A__MAPPINGS_A, ElementA.class, msgs);
msgs = basicSetFirst(newFirst, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ApplicationPackage.MAPPING__FIRST, newFirst, newFirst));
}
but in the Mapping.getFirst(), the proxy object is replaced by the actual EObject without unsetting/setting again the inverse.
(see first = (ElementA)eResolveProxy(oldFirst); in the snippet below)
public ElementA getFirst() {
if (first != null && first.eIsProxy()) {
InternalEObject oldFirst = (InternalEObject)first;
first = (ElementA)eResolveProxy(oldFirst);
if (first != oldFirst) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, ApplicationPackage.MAPPING__FIRST, oldFirst, first));
}
}
return first;
}
I found a way to solve our bug, by editing the generated code above:
- replacing first = (ElementA)eResolveProxy(oldFirst);
- with setFirst((ElementA)eResolveProxy(oldFirst));
This solution is not acceptable as we should not edit the EMF generated code, so I found two possible alternatives
(1) There must be a special flag in EMF genmodel, to tell EMF to eInverseRemove/eInverseAdd when a proxy is replaced by an EObject
(2) I should add an Adapter to reacto to Notification.RESOLVE, and call eInverseRemove/eInverseAdd when a proxy is replaced.
However, I am missing details to implement any of the two above solutions, hence I have two questions:
(1)
I don't know if there is a flag to tell EMF to call eInverseRemove() and eInverseAdd() when replacing a Proxy Object with an Actual EObject.
-> Does someone knows if such flag exists?
(2)
To add an Adapter to an EObject instance, I should modify a Generated Factory class. Again, I prefer not to modify generated code.
-> Is there a best practice way to attach an Adapter to all the instances of Generated classes, in order to avoid polluting generated code?
Thanks in advance for your time and consideration,
Best Regards,
Patrik
|
|
| | | |
Re: issue with EMF proxy, EOpposite, and Adapters [message #1803036 is a reply to message #1803001] |
Thu, 21 February 2019 10:01 |
Patrik Suzzi Messages: 2 Registered: February 2018 |
Junior Member |
|
|
Yes, correct: on one side I have a proxy and on the other side a value that I populated by reading the current XML file with my XMIHandler.
IIUC, for each bidirectional, proxy-resolving, cross reference, only two cases are valid:
- both ends are proxies
- both ends are concrete objects
Hence, I should solve the issue by changing how I build the Object tree in my XMIHandler:
- for each "bidirectional, proxy-resolving, cross reference", If I cannot resolve both ends of the relation, I should put proxies on both ends.
Thanks and Best Regards,
Patrik
[Updated on: Thu, 21 February 2019 10:01] by Moderator Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Apr 25 06:35:33 GMT 2024
Powered by FUDForum. Page generated in 0.03057 seconds
|