0

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>
Roman R.
  • 68,205
  • 6
  • 94
  • 158
DeLac
  • 1,068
  • 13
  • 43
  • So you're looking for somebody to help you writing the OCL constraint? Suggesting different approaches to achieve the same? or what? – Jordi Cabot Mar 22 '14 at 20:53
  • I am asking for the best way to achieve that. I am not sure that OCL could be the best solution.If it's possible do it without OCL is even better. My goal is avoid manually control if an element already exists in the relation "in", I want that all should be implicit in the metamodel – DeLac Mar 23 '14 at 07:23

2 Answers2

0

The OCL constraint will indeed prevent this (or, better said, you´ll be able to check whether the ATL transformation has produced an inconsistent model by evaluating this OCL constraint at the end of the execution)

Jordi Cabot
  • 8,058
  • 2
  • 33
  • 39
  • So I should manually remove duplicates in anyway..mm.. is there a way to avoid manual modification? For instance, instead defining the IN relation as an array, it could be defined as a "set", so equivalent elements will be ignored. Is that possible? – DeLac Mar 23 '14 at 21:14
0

The ID=true shall make the validation produce an error, with the following message: The ID '...' of '...' collides with that of '...'

To validate your model, use for example : Diagnostician.INSTANCE.validate(eObjectToValidate)

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
franck
  • 26
  • 1
  • 2