Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] How to work with inheritance
[QVTO] How to work with inheritance [message #507995] Fri, 15 January 2010 13:32 Go to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Hi all,

I would like to know how to transform inherited classes. Example:

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

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:

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

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:

http://www.redpanda.nl/ActualProb.png
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 #508141 is a reply to message #507995] Sat, 16 January 2010 14:14 Go to previous messageGo to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Hmm I came up with something, if somebody has a better idea please share!

From Class_A:

if ( self.transition_a.oclIsTypeOf(Class_C) ) then {
  if ( self.transition_a.oclAsType(Class_C).relation_c.oclIsTypeOf(Class_E) ) then {
    --Do something with self.transition_a.oclAsType(Class_C).relation_c.oclAsType(Class_E).
    --If relation_c would be 0..*, I could use the first check with disjuncts to map the objects. 
    --If I only need values, and therefore just one object I would use this code.
  } endif;
} endif;
Re: [QVTO] How to work with inheritance [message #508307 is a reply to message #507995] Mon, 18 January 2010 11:22 Go to previous message
Eclipse UserFriend
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?
Previous Topic:[QVTo] How to export QVTo transformation as Eclipse-plugin
Next Topic:[QVTO] Questions about specialisation (inheritance)
Goto Forum:
  


Current Time: Fri Aug 23 09:39:22 GMT 2019

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

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

Back to the top