I have an Ecore metamodel. The node Peer has a containment relation 0..* called "in" with the node Message. I want that all the messages contained by the Peer, have different names. So a Peer can not have two messages with the same name.
+--------+ +-----------+
| PEER |◄►-- in 0..* --> | MESSAGE |
+--------+ +-----------+
|name:String|
+-----------+
- I put the option id=true of the attribute Message.name
- I put the option EKeys=name of the relation Peer.in
- tried to override methods hashCode() and equals() of the Message, to calculate them basing on the attribute name
But in a model, the Peer can still have equal messages in its relation in. I thought maybe OCL can help me to achieve that I want.
Actually I am using ATL for a M2M, and the result is that the Peer has many equal messages. I would like that the constraint is implicite in the metamodel, without manually controlling in the ATL rule if the Peer has already or not that message before add it.
Thank you
Node Peer
<eClassifiers xsi:type="ecore:EClass" name="Peer">
<eStructuralFeatures xsi:type="ecore:EReference" name="in" upperBound="-1"
eType="#//Message"
containment="true" eKeys="#//Message/name"
/>
</eClassifiers>
Node Message
<eClassifiers xsi:type="ecore:EClass" name="Message" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
iD="true"
/>
</eClassifiers>