Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Map keys shall be only attributes of an EClass
Map keys shall be only attributes of an EClass [message #1052965] Wed, 01 May 2013 15:31 Go to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Hello,

I have a class X, which contains different attributes for describing base values.
Now I want to describe effects on these attributes.

My idea was to use an EMap, but I don't want to use a string as key to prevent a check if the method is really existing before calling a get/set.
I was thinking about the attribute reference, but I don't know how to model it with Ecore that it allows only available attributes as keys.

Another idea would be the implementation over an own EClass, which contains a key and the value, but I don't know how to reference on the EAttribute either.

Another option would be the implementation of a constraint, but I hoped there is perhaps a better way to do that.
Re: Map keys shall be only attributes of an EClass [message #1052985 is a reply to message #1052965] Wed, 01 May 2013 17:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
John,

Comments below.

On 01/05/2013 5:31 PM, John M. wrote:
> Hello,
>
> I have a class X, which contains different attributes for describing
> base values.
> Now I want to describe effects on these attributes.
>
> My idea was to use an EMap, but I don't want to use a string as key to
> prevent a check if the method is really existing before calling a
> get/set.
I'm not sure what you mean by this sentence.
> I was thinking about the attribute reference, but I don't know how to
> model it with Ecore that it allows only available attributes as keys.
EReference.eKeys has nothing to do with EMaps...
>
> Another idea would be the implementation over an own EClass, which
> contains a key and the value, but I don't know how to reference on the
> EAttribute either.
That's what EMaps do, e.g., look at EStringToStringMapEntry in Ecore.
>
> Another option would be the implementation of a constraint, but I
> hoped there is perhaps a better way to do that.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Map keys shall be only attributes of an EClass [message #1052992 is a reply to message #1052965] Wed, 01 May 2013 18:38 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Hello Ed,

Thanks for your fast answer.
I am searching for a method to have a map which keys are the Eattributes of a given EClass.
Re: Map keys shall be only attributes of an EClass [message #1053037 is a reply to message #1052992] Thu, 02 May 2013 07:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
John,

A little like what we do for EPackage.getEClassifier(String) but that's
hand coded. Nothing will generate that for you directly. You could
imagine that if we declared EReference.eKeys, we could generate such a
helper method. The tricky part is maintaining the state of the map when
the values of the keys change...

On 01/05/2013 8:38 PM, John M. wrote:
> Hello Ed,
>
> Thanks for your fast answer.
> I am searching for a method to have a map which keys are the
> Eattributes of a given EClass.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Map keys shall be only attributes of an EClass [message #1053127 is a reply to message #1053037] Thu, 02 May 2013 15:19 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Hum ... I had a look into the EPackage.getEClassifier(String), but I didn't get when/how the List is created.
In the meantime I had the idea to disable the setter of the map and declare my own EOperation, which takes the EAttribute over the Literals and the value itself.
Re: Map keys shall be only attributes of an EClass [message #1053133 is a reply to message #1052992] Thu, 02 May 2013 15:27 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, John,

Are you looking for a map entry in which the key references an
EAttribute from your Ecore model? I think you would just create an
EClass named, say, EAttributeToStringMapEntry with

- an EReference named "key" having EType = EAttribute
- an EAttribute named "value" having EType = EString
- implementationClassName = "java.util.Map$Entry"

the value could be an EReference of any type, if that's what you need.
Then, a containment EReference of this EAttributeToStringMapEntry type
will generate an EMap of the kind you need (I think).

I think the Ecore editor should give you EAttribute in the list of
possible eTypes for the key reference, but if it doesn't, then you can
load the Ecore model using the "Load Resource..." action in the
editor's context menu.

To constrain the keys to be EAttributes only some some particular
EClass, you can customize the getChoiceOfValues() method in the
item-provider generated for your map-entry EClass such that it only
provides the EAttributes that you want the user to be able to choose
from.

HTH,

Christian



On 2013-05-01 18:38:40 +0000, John M. said:

> Hello Ed,
>
> Thanks for your fast answer.
> I am searching for a method to have a map which keys are the
> Eattributes of a given EClass.
Previous Topic:Resolving proxy URIs with a customized URI schema
Next Topic:Transient eOpposite of a persistent eRef?
Goto Forum:
  


Current Time: Fri Mar 29 10:18:10 GMT 2024

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

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

Back to the top