Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Dynamic Enumeration-based Attributes(Setting values of dynamically created enumeration-based eattributes when creating xmi instances)
Dynamic Enumeration-based Attributes [message #1790721] Fri, 15 June 2018 02:08 Go to next message
Ioannis Nearchou is currently offline Ioannis NearchouFriend
Messages: 13
Registered: February 2018
Junior Member
Hello Everyone,

I am trying to finish a program for dynamically creating xmi files of class instances from an ecore file in the file system of a project and then validating them following creation. I am currently having one of the last issues with trying to set EEnum type attributes in EObject instances of classes that belong to a loaded ecore file.

The first strategy I used was to generically set the EType of a newly dynamically created eattribute to the EType of the corresponding attribute of a given EClass in the model. But, trying to set the value of the attribute leaves me with a Class Casting Exception thrown about the particular type of EEnumImpl read at runtime. Second, I have also tried making an EDataType instance, so that the attribute could hold a null value. My issue there is trying to add it to the corresponding EClass I dynamically create, due to the type hierarchy. Last, I entertained the idea of setting the default value of the eattribute to a literal from its corresponding EEnum, but I find that there is a Null Pointer Exception thrown when a getPackage() call for an intermediary factory variable in the middle of the setDefaultValue() call of the attribute returns null. I have been having trouble finding an exact related explanation due to most programmatic examples being generated and not dynamic. I have read that EMF treats EEnum literal values as primitives, but haven't been able to successfully use that on an eSet() call on an enumeration-based attribute. I am wondering what am I missing that would allow me to successfully set a value to an enumeration-based attribute of a class from an ecore file?

Thank you,
Ioannis Nearchou
Re: Dynamic Enumeration-based Attributes [message #1790725 is a reply to message #1790721] Fri, 15 June 2018 06:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29545
Registered: July 2009
Senior Member
All the problems are described rather vaguely and of course any concrete problem will depend on much more specific details than you've provided. One thing I suspect you're not doing is ensuring that every EEnum, EClass, and EDataType you create is actually contained by an EPackage. In any case, if some eObject x has an EClass c with an EAttribute f of EEnum type e and f is single valued, then you should be able to call x.eSet(f, e.getELiterals().get(<index>).getInstance()).
Re: Dynamic Enumeration-based Attributes [message #1790730 is a reply to message #1790725] Fri, 15 June 2018 07:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Enum literals can be quite tricky, but as so often the Sample Ecore Editor is invaluable. Create a Dynamic Instance of your model and populate it with one of your enumeration literals. Then copy what the Editor does in your application.

Regards

Ed Willink
Re: Dynamic Enumeration-based Attributes [message #1790757 is a reply to message #1790725] Fri, 15 June 2018 16:46 Go to previous message
Ioannis Nearchou is currently offline Ioannis NearchouFriend
Messages: 13
Registered: February 2018
Junior Member
Ed Merks wrote on Fri, 15 June 2018 06:21
One thing I suspect you're not doing is ensuring that every EEnum, EClass, and EDataType you create is actually contained by an EPackage. In any case, if some eObject x has an EClass c with an EAttribute f of EEnum type e and f is single valued, then you should be able to call x.eSet(f, e.getELiterals().get(<index>).getInstance()).


Hello Ed and Ed,

How are you both? Thank you for the quick replies. Those two quick steps from the above quote did the trick. I previously wasn't calling getInstance() when using the explained x.eSet(...) example in the quote and missed adding the EClasses, etc. to the EPackage as I was going. Those two things solved that problem and now I just have to take care of some Semantic Exceptions thrown during the OCL validation step of my model instances. Thanks for passing on the insight about how to use EMF!

Thank you,
Ioannis Nearchou
Previous Topic:[CDO] View update timing/concurrency
Next Topic:Mapping dateTime
Goto Forum:
  


Current Time: Sun Sep 23 06:10:04 GMT 2018

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

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

Back to the top