Dynamic Enumeration-based Attributes [message #1790721] |
Fri, 15 June 2018 02:08 |
Ioannis Nearchou Messages: 18 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 #1790757 is a reply to message #1790725] |
Fri, 15 June 2018 16:46 |
Ioannis Nearchou Messages: 18 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
|
|
|
Powered by
FUDForum. Page generated in 0.02501 seconds