eSet in multiple (parent/child) models [message #425826] |
Tue, 09 December 2008 13:33 |
Morten MacFly Messages: 69 Registered: July 2009 |
Member |
|
|
Dear NG,
I have a model structure that exist of several ecroe models (one root,
several children). Now I am writing an import filter for an external
format that would create a model accordingly. I want to "eSet" all
sub-elements but I receive a "IllegalCastException" when I try to create
the cildren.
Assume this structure:
Resource
- Root (first EObject)
- A (child of Root, but own ecore model)
- B (child of Root, but own ecore model)
- B1 (child of B, inside "B" ecore model)
- B2 (child of B, inside "B" ecore model)
What I am doing is this:
- Creating the ResourceSet / Resource "Resource"
- Obtaining the root structural feature (RootSF)
- Obtaining the root ECLass (RootEC)
....then:
- Root = RootFactory.create(RootEC)
- Root.eSet(RootSF, EcoreUtil.create((EClass)RootSF.getEType()));
- Resource.getContents().add(Root);
Up to here it's just "copied" from the default (generated) wizard. Now
comes my part accordingly:
- EReference B = RootPackage.eINSTANCE.getB();
- EObject B_O = EcoreUtil.create(B.getEReferenceType());
- Root.eSet(B, B_O);
- This works, I see the child "B" in the model instance if I stop here.
Now I want to add the B1/B2, too the same way:
- EReference B1 = BPackage.eINSTANCE.getB1();
- EObject B1_O = EcoreUtil.create(B1.getEReferenceType());
- B.eSet(B1, B1_O);
But this fails with the "IllegalCastException". :-( Any idea what I am
doing wrong?
Probably I should mention that B is of type "many". But it also fails if
it is not.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02416 seconds