A case scenario regarding the selection of mappings based on composed model elements [message #1061280] |
Thu, 30 May 2013 23:06 |
Emre T Messages: 119 Registered: April 2013 |
Senior Member |
|
|
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
[Updated on: Thu, 30 May 2013 23:07] Report message to a moderator
|
|
|
|
|
Re: A case scenario regarding the selection of mappings based composed model elements [message #1061434 is a reply to message #1061326] |
Fri, 31 May 2013 15:31 |
Adolfo Sanchez-Barbudo Herrera Messages: 260 Registered: July 2009 |
Senior Member |
|
|
By some reasons, replying via newsgroup didn't update the forum.... I should have done something wrong
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.
|
|
|
|
Re: A case scenario regarding the selection of mappings based composed model elements [message #1061490 is a reply to message #1061280] |
Sat, 01 June 2013 00:14 |
Alan McMorran Messages: 55 Registered: July 2009 |
Member |
|
|
Emre,
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:
mapping SRC::M::toX() : TARGET::X
when{not self.A.B.oclIsUndefined()}{
// Then within here you can create Y, Z and T objects
}
mapping SRC::M::toK() : TARGET::K
when{self.A.B.oclIsUndefined()}{
// Then do your mapping and create L as well
}
In your main, assuming an input parameter src you can do:
main(){
src.objectsOfType(SRC::M).map toX();
src.objectsOfType(SRC::M).map toK();
}
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
|
|
|
Powered by
FUDForum. Page generated in 0.04325 seconds