Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Dynamic EMF] StackOverflow when using eSet
[Dynamic EMF] StackOverflow when using eSet [message #419630] Thu, 29 May 2008 16:04 Go to next message
Matthias Schoettle is currently offline Matthias SchoettleFriend
Messages: 44
Registered: July 2009
Member
I have a EMF Model with a class that has some attributes (only one in my
example). Now I want to add an attribute dynamically which works. When I
create an instance of this class and try to set this dynamic attribute
using eSet() I get a StackOverflowException.

I debugged a bit and found out that this is due to eStaticFeatureCount()
returning 2, but only 1 static feature exists, i.e. it's not looking for
CLASSNAME_FEATURE_COUNT in the generated Package interface.

This is how I added the EAttribute:

EAttribute testId = EcoreFactory.eINSTANCE.createEAttribute();
testId.setName("testId");
testId.setEType(EcorePackage.eINSTANCE.getEInt());


BugtestPackage.eINSTANCE.getTestClass().getEStructuralFeatur es().add(testId);

TestClass testClass = (TestClass) resource.getContents().get(0);
testClass.eSet(testId, 1);

Is this not possible or did I do anything wrong?

Thanks in advance
Matthias
Re: [Dynamic EMF] StackOverflow when using eSet [message #419631 is a reply to message #419630] Thu, 29 May 2008 16:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Matthias,

Comments below.

Matthias Schoettle wrote:
> I have a EMF Model with a class that has some attributes (only one in
> my example). Now I want to add an attribute dynamically which works.
Oh? Is this a generated model? It's not valid to modify a generated model.
> When I create an instance of this class and try to set this dynamic
> attribute using eSet() I get a StackOverflowException.
So it's not working so well. :-P
>
> I debugged a bit and found out that this is due to
> eStaticFeatureCount() returning 2, but only 1 static feature exists,
> i.e. it's not looking for CLASSNAME_FEATURE_COUNT in the generated
> Package interface.
Yes, this is not supported.
>
> This is how I added the EAttribute:
>
> EAttribute testId = EcoreFactory.eINSTANCE.createEAttribute();
> testId.setName("testId");
> testId.setEType(EcorePackage.eINSTANCE.getEInt());
>
>
> BugtestPackage.eINSTANCE.getTestClass().getEStructuralFeatur es().add(testId);
>
>
> TestClass testClass = (TestClass) resource.getContents().get(0);
> testClass.eSet(testId, 1);
>
> Is this not possible or did I do anything wrong?
It's not valid. You can create a new EPackage, with a new EClass that
extends the generated EClass and add a new attribute to that EClass, but
you can't modify a generated model. It should be treated as immutable.
>
>
> Thanks in advance
> Matthias


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Dynamic EMF] StackOverflow when using eSet [message #419638 is a reply to message #419631] Fri, 30 May 2008 08:30 Go to previous message
Matthias Schoettle is currently offline Matthias SchoettleFriend
Messages: 44
Registered: July 2009
Member
Thanks Ed, now it does make sense :-)
Previous Topic:Model persistence related query.
Next Topic:[Transactions] No Rollback when a Trigger command fails
Goto Forum:
  


Current Time: Fri Apr 19 19:05:24 GMT 2024

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

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

Back to the top