Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsCreating EMap Entries
https://www.eclipse.org/forums/index.php/mv/msg/135551/425972/#msg_425972
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?
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 Merks2008-12-15T01:00:26-00:00Re: Creating EMap Entries
https://www.eclipse.org/forums/index.php/mv/msg/135551/425975/#msg_425975
> 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.
> It uses reflection, i.e, the equivalent of EcoreUtil.create(<EClass>).
I'm sure I'll open the source of this method later.
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 Merks2008-12-15T12:35:20-00:00