Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Creating EMap Entries
Creating EMap Entries [message #425972] Sun, 14 December 2008 22:22 Go to next message
Felix Dorner is currently offline Felix DornerFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 #425975 is a reply to message #425974] Mon, 15 December 2008 06:47 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
> 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.

> 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
Re: Creating EMap Entries [message #426050 is a reply to message #425975] Mon, 15 December 2008 12:35 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:[CDO] CDOObject containment problems
Next Topic:Faster Loading EMF Models from XML
Goto Forum:
  


Current Time: Thu Sep 19 23:28:16 GMT 2024

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

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

Back to the top