Creating EMap Entries [message #425972] |
Sun, 14 December 2008 22:22 |
Felix Dorner Messages: 676 Registered: July 2009 |
Senior Member |
|
|
Hey,
when I create a map, as described in the FAQ (eg create a FlagToCountry
EClass, and a multiplicity-many reference of that type in the map's
container), the generated Editor lets me create map entries, so that the
usual map invariants are violated, (e.g. map one Flag to several Countries)
I am trying to accomplish the same thing programatically, but I somehow
cannot create proper FlagToCountry instances: There's a
FlagToCountryImpl class, but its constructor is protected. The factory
doesn't declare a createFlagToCountry() method. Of course I can hack
around... But somehow the generated Editor must also be able to create
such FlagToCountry objects in order to add them to the map's list. How
does it do?
Thanks,
Felix
|
|
|
Re: Creating EMap Entries [message #425974 is a reply to message #425972] |
Mon, 15 December 2008 01:00 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Felix,
Comments below.
Felix Dorner wrote:
> Hey,
>
> when I create a map, as described in the FAQ (eg create a
> FlagToCountry EClass, and a multiplicity-many reference of that type
> in the map's container), the generated Editor lets me create map
> entries, so that the usual map invariants are violated, (e.g. map one
> Flag to several Countries)
If you invoke validate though, it will complain that you have duplicate
keys, right?
>
> I am trying to accomplish the same thing programatically, but I
> somehow cannot create proper FlagToCountry instances: There's a
> FlagToCountryImpl class, but its constructor is protected.
You'd generally not create map entries and add them to the list, you'd
generally use EMap.put...
> The factory doesn't declare a createFlagToCountry() method.
That's intentional yes.
> Of course I can hack around... But somehow the generated Editor must
> also be able to create such FlagToCountry objects in order to add them
> to the map's list. How does it do?
It uses reflection, i.e, the equivalent of EcoreUtil.create(<EClass>).
>
> Thanks,
> Felix
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Creating EMap Entries [message #426050 is a reply to message #425975] |
Mon, 15 December 2008 12:35 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Felix,
Comments below.
Felix Dorner wrote:
>> If you invoke validate though, it will complain that you have
>> duplicate keys, right?
> Yes.
>> You'd generally not create map entries and add them to the list,
>> you'd generally use EMap.put...
> Which requires me to write more code, as I don't want users to
> accidentally overwrite things. (Which I'll sure do later). For now I
> just wanted to mimic the behavior of the generated Editor.
I'm confused. Surely map.containsKey and map.put are the least amount
of code you could write?
>
>> It uses reflection, i.e, the equivalent of EcoreUtil.create(<EClass>).
> I'm sure I'll open the source of this method later.
>
> Thank you.
> Felix
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03933 seconds