Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] How to call different mappings based on some predicate?
[QVTO] How to call different mappings based on some predicate? [message #490594] Fri, 09 October 2009 10:15 Go to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Hi,

in my target metamodel there's an abstract class Person, and two
concrete subclasses Male and Female. The class Genealogy references a
set of Persons. So I have:

--8<---------------cut here---------------start------------->8---
main() {
src.objectsOfType(FamilyTree) -> map familyTree2Genealogy();
}

mapping FamilyTree::familyTree2Genealogy() : Genealogy {
persons := self.members -> map member2Person();
}
--8<---------------cut here---------------end--------------->8---

Additionally, for the concrete Male/Female I have those mappings:

--8<---------------cut here---------------start------------->8---
mapping Member::member2Female() : Female
when {self.isFemale()}
{
fullName := self.firstName + ' ' + self.familyName();
}

mapping Member::member2Male() : Male
when {not self.isFemale()}
{
fullName := self.firstName + ' ' + self.familyName();
}
--8<---------------cut here---------------end--------------->8---

But I cannot figure out how to define the member2Person() mapping so
that it dispatches to the right mapping. Reading the QVT spec, it looks
to me that the disjuncts keyword is the thing I'm looking for. But

--8<---------------cut here---------------start------------->8---
mapping Member::member2Person() : Person
disjuncts member2Female, member2Male() {}
--8<---------------cut here---------------end--------------->8---

shows errors becauso of "Unresolved mapping operation references" for
member2Female and member2Male.

What am I doing wrong?

And another minor question: In the QVT spec there seem to be a lot of
syntactical constructs that won't work. For example, there often things
like

if (<predicate>) return 'Foo';

are used, but it seems that in reality I need to write

if (<predicate>) then return 'Foo' else return null elseif;

so I cannot omit the then and else. Why is that difference?

Bye,
Tassilo
Re: [QVTO] How to call different mappings based on some predicate? [message #490844 is a reply to message #490594] Sun, 11 October 2009 19:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dvorak.radek.gmail.com

Hi Tassilo,

See inlined comments.

Regards,
/Radek

>
> But I cannot figure out how to define the member2Person() mapping so
> that it dispatches to the right mapping. Reading the QVT spec, it looks
> to me that the disjuncts keyword is the thing I'm looking for. But
>
> --8<---------------cut here---------------start------------->8---
> mapping Member::member2Person() : Person
> disjuncts member2Female, member2Male() {}
> --8<---------------cut here---------------end--------------->8---
>
> shows errors becauso of "Unresolved mapping operation references" for
> member2Female and member2Male.
>
> What am I doing wrong?

Use qualified reference to mapping operations, like
disjuncts Member::member2Male, Member::member2Female {}

>
> And another minor question: In the QVT spec there seem to be a lot of
> syntactical constructs that won't work. For example, there often things
> like
>
> if (<predicate>) return 'Foo';
>
> are used, but it seems that in reality I need to write
>
> if (<predicate>) then return 'Foo' else return null elseif;
>
> so I cannot omit the then and else. Why is that difference?

You can do the following:

if (<predicate>) then
return 'Foo'
endif;


>
> Bye,
> Tassilo
Re: [QVTO] How to call different mappings based on some predicate? [message #490907 is a reply to message #490844] Mon, 12 October 2009 10:55 Go to previous message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
"radek dvorak" <dvorak.radek@gmail.com> writes:

Hi Radek,

>> But I cannot figure out how to define the member2Person() mapping so
>> that it dispatches to the right mapping. Reading the QVT spec, it looks
>> to me that the disjuncts keyword is the thing I'm looking for. But
>>
>> --8<---------------cut here---------------start------------->8---
>> mapping Member::member2Person() : Person
>> disjuncts member2Female, member2Male() {}
>> --8<---------------cut here---------------end--------------->8---
>>
>> shows errors becauso of "Unresolved mapping operation references" for
>> member2Female and member2Male.
>>
>> What am I doing wrong?
>
> Use qualified reference to mapping operations, like
> disjuncts Member::member2Male, Member::member2Female {}

Ah, this does the trick. Thanks a lot!

> You can do the following:
>
> if (<predicate>) then
> return 'Foo'
> endif;

Great, that also works. The problem was that I always omitted the
semicolon.

Bye,
Tassilo
Previous Topic:[QVTO] Reflectively accessing a transformation
Next Topic:mwe Workflow xmi Writer error
Goto Forum:
  


Current Time: Mon Jan 13 04:55:40 GMT 2025

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

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

Back to the top