Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsA case scenario regarding the selection of mappings based on composed model elements
https://www.eclipse.org/forums/index.php/mv/msg/488243/1061280/#msg_1061280
Following is the situation:
Model Element A has an other model element B in it. Is is defined as a composition. And both of them are again composed by a main model element M. The B generally is optional in this situation, but might appear. So it is either M -> A -> B or only M -> A. (Please note, this isn't inheritance.)
So based on both options, in this case whether the last model element B is created in the source model instance or not, a certain corresponding mapping should be chosen. One of them eventually transforms A and B into something, and the other mapping transforms only A into something else. (Transformation of M is no matter.)
M-A-B -> Mapping 1 -> X-Y-Z-T....
M-A -> Mapping 2 -> K-L
So which mapping should be chosen depends on the existence check of source model element B. And I am guessing I can do this in the mapping definition of the first source model element M. But the question is: How?
OCL comes into my mind, but I only know some ways of checking the inheritance relation between model elements, not the composition.
I will be very thankful, if you could help me!
Best regards,
Emre]]>Emre T2013-05-30T23:06:46-00:00Re: A case scenario regarding the selection of mappings based composed model elements
https://www.eclipse.org/forums/index.php/mv/msg/488243/1061300/#msg_1061300
> OCL comes into my mind, but I only know some ways of checking the
> inheritance relation between model elements, not the composition.
Indeed, use an OCL expression in a guard comparing the ptoperty value to
null.
Regards
Ed Willink]]>Ed Willink2013-05-31T05:51:18-00:00Re: A case scenario regarding the selection of mappings based composed model elements
https://www.eclipse.org/forums/index.php/mv/msg/488243/1061326/#msg_1061326
You mean any property value of B, right? Could you please give a little code snippet?
Thanks!
]]>Emre T2013-05-31T08:45:19-00:00Re: A case scenario regarding the selection of mappings based composed model elements
https://www.eclipse.org/forums/index.php/mv/msg/488243/1061434/#msg_1061434
Replying via Web browser:
Cheers,
Adolfo.
----
Hi Emre,
Something like the following
mapping M::mappingMA () : Something
when {self.refToA.refToB.oclIsUndefined()} ...
mapping M::mappingMAB () : Something
when {not self.refToA.refToB.oclIsUndefined()} ...
Note that if M doesn't contain any A self.refToA may be invalid, then making the guard evaluate to true ( OclInvalid.oclIsUndefined() = true), so you should probably require a more elaborated guard.
Take into account that you need a joint-point mapping which diverges against those two mappings (Again, review disjunct mapping semantics in the specification). For this example, something like:
mapping M::mappingM () : Something
disjunct mappingMA, mappingMAB
when {not self.refToA.oclIsUndefined()} // A way to partially solve the note I mentioned above
Cheers,
Adolfo. ]]>Adolfo Sanchez-Barbudo Herrera2013-05-31T15:31:33-00:00Re: A case scenario regarding the selection of mappings based composed model elements
https://www.eclipse.org/forums/index.php/mv/msg/488243/1061474/#msg_1061474
your tips were very helpful. It wasn't clear me enough, which OCL constructs I needed use for the purpose. And the disjuncts was of course no success without the correct when-logic.
Again thanks a lot!
Emre]]>Emre T2013-05-31T20:05:41-00:00Re: A case scenario regarding the selection of mappings based composed model elements
https://www.eclipse.org/forums/index.php/mv/msg/488243/1061490/#msg_1061490
If I understand you correctly, with QVTO you can put conditions on the
mapping so in your example, assuming the source model is SOURCE and
we're mapping to a raget model TARGET, you could have something like:
And the when statements will mean only those instances of M that mee
the where conditions for each mapping are mapped.
Alan
On 2013-05-30 23:06:47 +0000, Emre Taspolatoglu said:
> Hello!
>
> Following is the situation:
>
> Model Element A has an other model element B in it. Is is defined as a
> composition. And both of them are again composed by a main model
> element M. The B generally is optional in this situation, but might
> appear. So it is either M -> A -> B or only M -> A. (Please note, this
> isn't inheritance.)
>
> So based on both options, in this case whether the last model element B
> is created in the source model instance or not, a certain corresponding
> mapping should be chosen. One of them eventually transforms A and B
> into something, and the other mapping transforms only A into something
> else. (Transformation of M is no matter.)
>
> M-A-B -> Mapping 1 -> X-Y-Z-T....
>
> M-A -> Mapping 2 -> K-L
>
> So which mapping should be chosen depends on the existence check of
> source model element B. And I am guessing I can do this in the mapping
> definition of the first source model element M. But the question is:
> How?
> OCL comes into my mind, but I only know some ways of checking the
> inheritance relation between model elements, not the composition.
>
> I will be very thankful, if you could help me!
>
> Best regards,
> Emre]]>Alan McMorran2013-06-01T00:14:07-00:00