[QVTO] How to work with inheritance [message #507995] |
Fri, 15 January 2010 13:32 |
PBarendrecht Messages: 36 Registered: November 2009 Location: Eindhoven, Netherlands |
Member |
|
|
Hi all,
I would like to know how to transform inherited classes. Example:
There are families which consist of members. A member can be child or adult.
In the village where the families live, there is a committee. Every owner of a house is a member of that committee:
My question is, how can I transform the Family model to the Committee model? The class "Adult" has a boolean property owner.
I realise this is in fact not a real transformation, more like a query. Nevertheless, a problem like this could occur when doing a real transformation.
I expected it to be something like this (not sure how to check for the owner property):
mapping Family::toCommittee() : Committee {
consistsOf += self.members.allSubobjectsOfType(Adult)->map toOwner();
}
mapping Adult::toOwner() : Owner {
name := self.name;
}
NB: The example above is not my actual case, just a representative example. My actual case is a bit too complicated to post.
------------------------------------------------------------ ----------------------------------------------
[Edit]
Hmm I just found out about disjuncts, I can make a transformation like this:
mapping Family::toCommittee() : Committee {
consistsOf += self.members->map toOwner();
}
mapping Person::toOwner() : Owner
disjuncts Adult::toOwner2
{}
mapping Adult::toOwner2() : Owner {
name := self.name;
}
It works fine. Just out of curiosity, is there a way to solve the problem without using disjuncts? If I would transform both Child and Adult there wouldn't be another way, but I only want to transform Adult.
Now I know about this disjuncts, I have a question that has to do with my actual project. This is the situation:
I would like to transform Class_A, the model. The problem is that in this metamodel, Class_E are the variables (with name, type). However, in my other metamodel, the variables are directly contained in Class_A, the model.
I started with something like variables += self.relation_a. ??
The question is: How can I acces the variables in Class_E from Class_A?
[Updated on: Sat, 16 January 2010 23:01] Report message to a moderator
|
|
|
|
Re: [QVTO] How to work with inheritance [message #508307 is a reply to message #507995] |
Mon, 18 January 2010 11:22 |
Eclipse User |
|
|
|
Originally posted by: dvorak.radek.gmail.com
Hi,
The errors are reported because:
1) the assignment with the additive semantics must be
applied on a collection type left side.
2) allSubobjectsOfType returns Set(Element), so you would have to
explicitly cast to a type
which you define a mapping for.
Just try with self.members.allSubobjects()[Adult] // ensures
collection of Adult
Regards,
/Radek
On Fri, 15 Jan 2010 14:32:27 +0100, PBarendrecht <pieter@redpanda.nl>
wrote:
> Hi all,
>
> I would like to know how to transform inherited classes. Example:
>
>
>
> There are families which consist of members. A member can be child or
> adult.
> In the village where the families live, there is a committee. Every
> owner of a house is a member of that committee:
>
>
>
> My question is, how can I transform the Family model to the Committee
> model? The class "Adult" has a boolean property owner.
>
> I expected it to be something like this (not sure how to check for the
> owner property):
>
>
> mapping Family::toCommittee() : Committee {
> consistsOf += self.members.allSubobjectsOfType(Adult)->map toOwner();
> }
>
> mapping Adult::toOwner() : Owner {
> name := self.name;
> }
>
>
> However, errors like "Mapping Operation Expected" (on the right handside
> of consistsOf or in a similar case on the left handside, "Property
> 'consistsOf' must have a collection type".
>
> Any ideas for a transformation that actually works?
|
|
|
Powered by
FUDForum. Page generated in 0.03979 seconds