Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » eSet in multiple (parent/child) models
eSet in multiple (parent/child) models [message #425826] Tue, 09 December 2008 13:33 Go to next message
Morten MacFly is currently offline Morten MacFlyFriend
Messages: 69
Registered: July 2009
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:
- 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)
- 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.
Re: eSet in multiple (parent/child) models [SOLVED] [message #425831 is a reply to message #425826] Tue, 09 December 2008 14:27 Go to previous message
Morten MacFly is currently offline Morten MacFlyFriend
Messages: 69
Registered: July 2009
Morten MacFly wrote:
> I receive a "IllegalCastException"

Nah! Forget about my question. After I read a bit more I realised what I
did wrong. This also made me ralised I asked a stupid question. Sorry
for the noise. :-(

With regards, Morten.
Previous Topic:EOperation return type
Next Topic:[CDO] Multiple resource creation bug ?
Goto Forum:

Current Time: Thu Feb 27 08:57:08 GMT 2020

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

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

Back to the top