Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
PBarendrecht is currently offline PBarendrechtFriend
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

http://www.redpanda.nl/Family1.png

To this one, named Second

http://www.redpanda.nl/Family2.png

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 Go to previous messageGo to next message
Eclipse UserFriend
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!
Re: [QVTO] Questions about specialisation (inheritance) [message #508443 is a reply to message #508165] Mon, 18 January 2010 20:47 Go to previous message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Radek, thank you very much for your reply, this explains a lot! Smile
Previous Topic:[QVTO] How to work with inheritance
Next Topic:ATL
Goto Forum:
  


Current Time: Thu Aug 22 08:49:09 GMT 2019

Powered by FUDForum. Page generated in 0.01992 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top