Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EReference and EKeys
EReference and EKeys [message #1665441] Wed, 11 March 2015 08:21 Go to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 191
Registered: July 2009
Senior Member
Dear all,

I can not figure out how the ERefernce works with EKeys. I imagine the EReference should reject to
add an Object if already an Object with the same EKey exists in this particular list. But the
generated default editor is able to set two objects with the same key into a reference.

I am using Ecore Tools with Eclipse 4.4.1.

The object ConductorTypes references ConductorType (without"s" at the end)

The eCore snippet is as below:
<eClassifiers xsi:type="ecore:EClass" name="ConductorType">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType
http://www.eclipse.org/emf/2003/XMLType#//String"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="material" lowerBound="1"
eType="#//Material" eKeys="#//Material/name">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="materialID"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="crossSection_mm2" eType="ecore:EDataType
http://www.eclipse.org/emf/2003/XMLType#//Double"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="degreeOfWear_percent"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Double"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="equivalentRadius_mm"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Double"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="temperature_DegreeCentigrade"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Double"
defaultValueLiteral="20"/>
</eClassifiers>


<eClassifiers xsi:type="ecore:EClass" name="ConductorTypes">
<eStructuralFeatures xsi:type="ecore:EReference" name="conductorType" lowerBound="1"
upperBound="-1" eType="#//ConductorType" containment="true" eKeys="#//ConductorType/name">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="ConductorType"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>


any help is appreciated, Martin
Re: EReference and EKeys [message #1666053 is a reply to message #1665441] Wed, 11 March 2015 14:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Martin,

Comments below.

On 11/03/2015 9:21 AM, Martin Jacob wrote:
> Dear all,
>
> I can not figure out how the ERefernce works with EKeys. I imagine the
> EReference should reject to add an Object if already an Object with
> the same EKey exists in this particular list.
No, it's a constraint that's validated. If you've enabled live
validation for the generated editor you'll see that it's checked after
the fact...
> But the generated default editor is able to set two objects with the
> same key into a reference.
Imagine changing the value of the key after the fact such that a
duplicate arises as a result of that, rather than as a result of adding
an object to the reference's list.
>
> I am using Ecore Tools with Eclipse 4.4.1.
>
> The object ConductorTypes references ConductorType (without"s" at the
> end)
>
> The eCore snippet is as below:
> <eClassifiers xsi:type="ecore:EClass" name="ConductorType">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//String"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="material"
> lowerBound="1"
> eType="#//Material" eKeys="#//Material/name">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="materialID"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="crossSection_mm2" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Double"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="degreeOfWear_percent" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Double"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="equivalentRadius_mm" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Double"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="temperature_DegreeCentigrade"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Double"
> defaultValueLiteral="20"/>
> </eClassifiers>
>
>
> <eClassifiers xsi:type="ecore:EClass" name="ConductorTypes">
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="conductorType" lowerBound="1"
> upperBound="-1" eType="#//ConductorType" containment="true"
> eKeys="#//ConductorType/name">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="ConductorType"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
>
> any help is appreciated, Martin


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EReference and EKeys [message #1667734 is a reply to message #1666053] Thu, 12 March 2015 06:57 Go to previous messageGo to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 191
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<font face="Helvetica, Arial, sans-serif">Hi Ed,<br>
<br>
thanks for your comments. Live validation is enabled in preference
setting "Model Validation/Constraints". Do I have to sent an
option / annotation to enable validation? See my settings in the
picture below.<br>
<br>
But still its possible to have twice the same key. In my case the
key is a java.lang.String. May be it has some thing to do with the
use of == instead of equals to compare the keys?<br>
<br>
</font><br>
<img src="https://www.eclipse.org/forums/index.php?t=getfile&amp;id=21144" alt=""><br>
<div class="moz-cite-prefix">Ed Merks schrieb am 11.03.2015 um
15:19:<br>
</div>
<blockquote cite="mid:mdpith$cov$1@xxxxxxxxe.org" type="cite">Martin,
<br>
<br>
Comments below.
<br>
<br>
On 11/03/2015 9:21 AM, Martin Jacob wrote:
<br>
<blockquote type="cite">Dear all,
<br>
<br>
I can not figure out how the ERefernce works with EKeys. I
imagine the EReference should reject to add an Object if already
an Object with the same EKey exists in this particular list.
<br>
</blockquote>
No, it's a constraint that's validated.  If you've enabled live
validation for the generated editor you'll see that it's checked
after the fact...
<br>
<blockquote type="cite">But the generated default editor is able
to set two objects with the same key into a reference.
<br>
</blockquote>
Imagine changing the value of the key after the fact such that a
duplicate arises as a result of that, rather than as a result of
adding an object to the reference's list.
<br>
<blockquote type="cite">
<br>
I am using Ecore Tools with Eclipse 4.4.1.
<br>
<br>
The object ConductorTypes references ConductorType (without"s"
at the end)
<br>
<br>
The eCore snippet is as below:
<br>
  &lt;eClassifiers xsi:type="ecore:EClass"
name="ConductorType"&gt;
<br>
    &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
      &lt;details key="kind" value="elementOnly"/&gt;
<br>
    &lt;/eAnnotations&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="name" eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//String">http://www.eclipse.org/emf/2003/XMLType#//String</a>"/&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EReference"
name="material" lowerBound="1"
<br>
        eType="#//Material" eKeys="#//Material/name"&gt;
<br>
      &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
        &lt;details key="kind" value="attribute"/&gt;
<br>
        &lt;details key="name" value="materialID"/&gt;
<br>
      &lt;/eAnnotations&gt;
<br>
    &lt;/eStructuralFeatures&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="crossSection_mm2" eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//Double">http://www.eclipse.org/emf/2003/XMLType#//Double</a>"/&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="degreeOfWear_percent" eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//Double">http://www.eclipse.org/emf/2003/XMLType#//Double</a>"/&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="equivalentRadius_mm" eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//Double">http://www.eclipse.org/emf/2003/XMLType#//Double</a>"/&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="temperature_DegreeCentigrade"
<br>
        eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//Double">http://www.eclipse.org/emf/2003/XMLType#//Double</a>"
defaultValueLiteral="20"/&gt;
<br>
  &lt;/eClassifiers&gt;
<br>
<br>
<br>
  &lt;eClassifiers xsi:type="ecore:EClass"
name="ConductorTypes"&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EReference"
name="conductorType" lowerBound="1"
<br>
        upperBound="-1" eType="#//ConductorType"
containment="true" eKeys="#//ConductorType/name"&gt;
<br>
      &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
        &lt;details key="kind" value="element"/&gt;
<br>
        &lt;details key="name" value="ConductorType"/&gt;
<br>
      &lt;/eAnnotations&gt;
<br>
    &lt;/eStructuralFeatures&gt;
<br>
  &lt;/eClassifiers&gt;
<br>
<br>
<br>
any help is appreciated,    Martin
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>
  • Attachment: jibhhegc.png
    (Size: 125.04KB, Downloaded 131 times)
Re: EReference and EKeys [message #1668744 is a reply to message #1667734] Thu, 12 March 2015 16:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Martin,

Yes, it's a GenModel property (Decorator) in the Editor section which
you can set when you open the *.genmodel.

Yes, in general the model can be in an invalid state with respect to
this constraint. The runtime should be using .equals to compare keys.

On 12/03/2015 7:57 AM, Martin Jacob wrote:
> Hi Ed,
>
> thanks for your comments. Live validation is enabled in preference
> setting "Model Validation/Constraints". Do I have to sent an option /
> annotation to enable validation? See my settings in the picture below.
>
> But still its possible to have twice the same key. In my case the key
> is a java.lang.String. May be it has some thing to do with the use of
> == instead of equals to compare the keys?
>
>
>
> Ed Merks schrieb am 11.03.2015 um 15:19:
>> Martin,
>>
>> Comments below.
>>
>> On 11/03/2015 9:21 AM, Martin Jacob wrote:
>>> Dear all,
>>>
>>> I can not figure out how the ERefernce works with EKeys. I imagine
>>> the EReference should reject to add an Object if already an Object
>>> with the same EKey exists in this particular list.
>> No, it's a constraint that's validated. If you've enabled live
>> validation for the generated editor you'll see that it's checked
>> after the fact...
>>> But the generated default editor is able to set two objects with the
>>> same key into a reference.
>> Imagine changing the value of the key after the fact such that a
>> duplicate arises as a result of that, rather than as a result of
>> adding an object to the reference's list.
>>>
>>> I am using Ecore Tools with Eclipse 4.4.1.
>>>
>>> The object ConductorTypes references ConductorType (without"s" at
>>> the end)
>>>
>>> The eCore snippet is as below:
>>> <eClassifiers xsi:type="ecore:EClass" name="ConductorType">
>>> <eAnnotations
>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>> <details key="kind" value="elementOnly"/>
>>> </eAnnotations>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>>> eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2003/XMLType#//String"/>
>>> <eStructuralFeatures xsi:type="ecore:EReference" name="material"
>>> lowerBound="1"
>>> eType="#//Material" eKeys="#//Material/name">
>>> <eAnnotations
>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>> <details key="kind" value="attribute"/>
>>> <details key="name" value="materialID"/>
>>> </eAnnotations>
>>> </eStructuralFeatures>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>> name="crossSection_mm2" eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2003/XMLType#//Double"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>> name="degreeOfWear_percent" eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2003/XMLType#//Double"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>> name="equivalentRadius_mm" eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2003/XMLType#//Double"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>> name="temperature_DegreeCentigrade"
>>> eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2003/XMLType#//Double"
>>> defaultValueLiteral="20"/>
>>> </eClassifiers>
>>>
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="ConductorTypes">
>>> <eStructuralFeatures xsi:type="ecore:EReference"
>>> name="conductorType" lowerBound="1"
>>> upperBound="-1" eType="#//ConductorType" containment="true"
>>> eKeys="#//ConductorType/name">
>>> <eAnnotations
>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>> <details key="kind" value="element"/>
>>> <details key="name" value="ConductorType"/>
>>> </eAnnotations>
>>> </eStructuralFeatures>
>>> </eClassifiers>
>>>
>>>
>>> any help is appreciated, Martin
>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Texo Example is Missing Files
Next Topic:CDO vs NEO4EMF vd TENEO
Goto Forum:
  


Current Time: Thu Apr 25 03:40:47 GMT 2024

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

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

Back to the top