Home » Archived » M2M (model-to-model transformation) » [QVTO] Questions about specialisation (inheritance)
[QVTO] Questions about specialisation (inheritance) [message #508165] |
Sat, 16 January 2010 22:57 |
PBarendrecht Messages: 36 Registered: November 2009 Location: Eindhoven, Netherlands |
Member |
|
|
Hi All,
I'm sorry to bother you again this soon, but I'm stuck again with my project. I hope you can provide me with an answer, in return I will write a QVTO tutorial when my project is finished.
I would like to transform this metamodel, named First
To this one, named Second
I have to transform the "Child" to a "Baby" or "Toddler", depending on the age of the Child.
The basic transformation would be something like this:
mapping First::Family::toFamily() : Second::Family {
consistsOf += self.consistsOf->map toPerson();
}
mapping First::Person::toPerson() : Second::Person
disjuncts First::toChild, First::toAdolescent, First::toAdult
{}
mapping First::Child::toChild() : Second::Baby or Toddler {
if (self.age > 3) then { Toddler } else { Baby } endif;
}
...
If I understand the disjuncts-operator correctly, it works like this: when the input-object is an "abstract" type, like Person, the disjuncts-operator compares the input-object (Person) with the input-objects for the given mappings (whether it is a Child, Adolescent or Adult).
But, as far as I know, I cannot use conditions when using disjuncts. Therefore I have to decide whether I have to transform the "Child" to a "Baby" or "Toddler" in the toChild() mapping. How can I do that?
--------------------------------------------------
My other question is rather short. When the cardinality limits (e.g. the 1..* at consistsOf) would be just 1 in a similar case, the mapping toPerson() still returns a Bag (or sometimes a Sequence) of type Person!
I cannot assign this to a Person-type, the way I solve this now is save the result of the mapping in a variable of Bag(Person):
--Cardinality limits of consistOf is now 1
...
var Test: Bag(Person);
Test := self.consistOf->map toPerson();
consistOf := Test->asOrderedSet()->at(1)
But I don't think this is the official way to solve this. Any ideas?
Thanks!
[Updated on: Sun, 17 January 2010 09:39] Report message to a moderator
|
|
|
Re: [QVTO] Questions about specialisation (inheritance) [message #508299 is a reply to message #508165] |
Mon, 18 January 2010 10:47 |
Eclipse User |
|
|
|
Originally posted by: dvorak.radek.gmail.com
Hi Pieter,
Comments inlined below.
Regards,
/Radek
On Sat, 16 Jan 2010 23:57:36 +0100, PBarendrecht <pieter@redpanda.nl>
wrote:
> Hi All,
>
> I'm sorry to bother you again this soon, but I'm stuck again with my
> project. I hope you can provide me with an answer, in return I will make
> a QVTO tutorial when my project is finished.
>
> I would like to transform this metamodel, named First
>
>
>
> To this one, named Second
>
>
>
> I have to transform the "Child" to a "Baby" or "Toddler", depending on
> the age of the Child.
>
> The basic transformation would be something like this:
>
>
> mapping First::Family::toFamily() : Second::Family {
> consistsOf += self.consistsOf->map toPerson();
> }
>
> mapping First::Person::toPerson() : Second::Person disjuncts
> First::toChild, First::toAdolescent, First::toAdult
> {}
>
> mapping First::Child::toChild() : Second::Baby or Toddler {
> if (self.age > 3) then { Toddler } else { Baby } endif;
> }
>
> ..
>
>
> If I understand the disjuncts-operator correctly, it works like this:
> when the input-object is an "abstract" type, like Person, the
> disjuncts-operator compares the input-object with the input-objects for
> the given mappings (whether it is a Child, Adolescent or Adult).
> But, as far as I know, I cannot use conditions when using disjuncts.
> Therefore I have to decide whether I have to transform the "Child" to a
> "Baby" or "Toddler" in the toChild() mapping. How can I do that?
You can use when clause with disjuncts, OMG spec states:
A mapping operation may be defined as a disjunction of an ordered list of
mappings. This means that an invocation of the
operation results on the selection of the first mapping whose guard (type
and when clause) succeeds. The null value is returned if no guard succeeds.
If you wish to decide about the return type inside the mapping, you have
to do it
within the init section, IOW before an implicit instantiation occurs. You
have
to assign the output to predefined 'result' variable.
>
> --------------------------------------------------
>
> My other question is rather short. When the cardinality limits (e.g. the
> 1..* at consistsOf) would be just 1 in a similar case, the mapping
> toPerson() still returns a Bag (or sometimes a Sequence) of type Person!
> I cannot assign this to a Person-type, the way I solve this now is save
> the result of the mapping in a variable of Bag(Person):
>
>
> --Cardinality limits of consistOf is now 1
> ..
> var Test: Bag(Person);
> Test := self.consistOf->map toPerson();
> consistOf := Test->asOrderedSet()->at(1)
>
When a mapping is called with '->', it means that iterator is involved.
The result type is
Sequence or Bag depending on whether the source of the call is an ordered
collection or not.
Even if the source is scalar, applying '->' in a mapping call will always
results in a collection.
>
> But I cannot image that this is the official way to solve this. Any
> ideas?
> Thanks!
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 20:02:58 GMT 2024
Powered by FUDForum. Page generated in 0.04247 seconds
|