Adding feature to dynamic instance model [message #1818447] |
Mon, 16 December 2019 12:49 |
Stefan John Messages: 17 Registered: March 2018 |
Junior Member |
|
|
Hi all,
I am currently trying to encapsulate a model element TypeA of a dynamic instance model within a wrapper extending EObjectImpl. I am trying to do that without extending the underlying metamodel.
So far, I managed to add the wrapper object to the model by substituting TypeA with EcoreUtil.replace(), effectively, injecting it into the containment hierarchy.
Now I would like TypeA to be contained in the wrapper.
// given an instance aInstance of TypeA and a wrapperInstance
EObject container = aInstance.eContainer();
if (container != null) {
EStructuralFeature containment = aInstance.eContainmentFeature();
EcoreUtil.replace(container, containment, aInstance, wrapperInstance);
EcoreFactory eFactory = EcoreFactory.eINSTANCE;
EReference referenceToWrapped = eFactory.createEReference();
referenceToWrapped.setEType(aInstance.eClass());
referenceToWrapped.setContainment(true);
referenceToWrapped.setName("wrappedObject");
wrapperInstance.eClass().getEStructuralFeatures().add(referenceToWrapped);
wrapperInstance.eSet(referenceToWrapped, aInstance);
}
Unfortunately, trying to eSet() or eGet() the new reference results in an infinite loop in the implementation which is trying to deal with resolving the featureID.
Exception in thread "main" java.lang.StackOverflowError
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDerivedStructuralFeatureID(BasicEObjectImpl.java:1497)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1068)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1095)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071)
...
Switching to eDynamicSet() seems to get closer to what I try to achieve. However, I was not able to find documentation of eDynamicSet() and eOpenSet() so I know nothing about the semantics or preconditions.
Exception in thread "main" java.lang.IllegalArgumentException: The feature 'wrappedObject' is not a valid changeable feature
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenSet(BasicEObjectImpl.java:1141)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(BasicEObjectImpl.java:1119)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(BasicEObjectImpl.java:1107)
at vectoroptimization.dynamicemf.DynamicRunner.wrapSolutionObjects(DynamicRunner.java:176)
at vectoroptimization.dynamicemf.DynamicRunner.loadModels(DynamicRunner.java:78)
at vectoroptimization.dynamicemf.DynamicRunner.main(DynamicRunner.java:42)
I found a similar thread which is, however, about generated models.
https://www.eclipse.org/forums/index.php/t/152894/
I would really appreciate someone helping me to understand how or if extending a dynamic instance model is supported (without extending the underlying metamodel).
I got the EMF book at hand if that helps. Maybe I just didn't find the relevant parts in it.
Best wishes,
Stefan
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03969 seconds