Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Set boolean flag if object is referenced
[ATL] Set boolean flag if object is referenced [message #521429] Wed, 17 March 2010 11:07 Go to next message
Eclipse UserFriend
Hello,

I have been playing around with ATL a little bit and am trying to solve the following:

My input model contains a collection (0...*) of classes and a reference to one of these classes.

My output model contains the same collection, but instead of the reference to one of the classes, every class contains a boolean flag.

What I want is that the transformation sets the boolean flag to "true" in the class that is referenced in the input model.

Any ideas how to accomplish this?


I tried something like the following:
module In2Out;
create OUT : OutModel from IN : InModel;

helper def : isFinishStation(station : InModel!Station) : Boolean =
   if (station = self.finishStation) then
      true
   else
      false
   endif;

rule Level2Level {
   from
      s : InModel!Level
   to
      t : OutModel!Level (
         stations <- s.stations
      )
}

rule Station2Station {
   from
      s : InModel!Station
   to
      t : OutModel!Station (
         name <- s.name,
         isFinishStation <- thisModule.isFinishStation(s)
   )
}


If I run the transformation then it produces an output model without any errors on the console.
But the boolean flag is never set to true.

Thanks for the help,
Bernhard
Re: [ATL] Set boolean flag if object is referenced [message #521450 is a reply to message #521429] Wed, 17 March 2010 11:50 Go to previous messageGo to next message
Eclipse UserFriend
Bernhard L. a écrit :
> Hello,
>
> I have been playing around with ATL a little bit and am trying to solve
> the following:
>
> My input model contains a collection (0...*) of classes and a reference
> to one of these classes.
>
> My output model contains the same collection, but instead of the
> reference to one of the classes, every class contains a boolean flag.
>
> What I want is that the transformation sets the boolean flag to "true"
> in the class that is referenced in the input model.
>
> Any ideas how to accomplish this?
>
>
> I tried something like the following:
>
> module In2Out;
> create OUT : OutModel from IN : InModel;
>
> helper def : isFinishStation(station : InModel!Station) : Boolean =
> if (station = self.finishStation) then

Here "self" refers to the current station.... (if I'm correct).
You need to refer to the input "model" (or anything else) which have the
reference.
You may try to get "station" container [container] and see its
"finishStation" property ...

> true
> else
> false
> endif;
>
> rule Level2Level {
> from
> s : InModel!Level
> to
> t : OutModel!Level (
> stations <- s.stations
> )
> }
>
> rule Station2Station {
> from
> s : InModel!Station
> to
> t : OutModel!Station (
> name <- s.name,
> isFinishStation <- thisModule.isFinishStation(s)
> )
> }
>
>
> If I run the transformation then it produces an output model without any
> errors on the console.
> But the boolean flag is never set to true.
>
> Thanks for the help,
> Bernhard


--
Cordialement

Vincent MAHÉ

Ingénieur plate-forme - Cesar/Artemisia - Équipe Espresso
IRISA-INRIA, Campus de Beaulieu, 35042 Rennes cedex, France
Tél: +33 (0) 2 99 84 71 00, Fax: +33 (0) 2 99 84 71 71
Re: [ATL] Set boolean flag if object is referenced [message #521578 is a reply to message #521450] Thu, 18 March 2010 03:26 Go to previous messageGo to next message
Eclipse UserFriend
Vincent MAHE wrote on Wed, 17 March 2010 11:50

> helper def : isFinishStation(station : InModel!Station) : Boolean =
> if (station = self.finishStation) then

Here "self" refers to the current station.... (if I'm correct).
You need to refer to the input "model" (or anything else) which have the
reference.
You may try to get "station" container [container] and see its
"finishStation" property ...



Thanks Vincent. If I change "self.finishStation" to "station.eContainer().finishStation" then it works as expected.

Greetings,
Bernhard
Re: [ATL] Set boolean flag if object is referenced [message #521590 is a reply to message #521429] Thu, 18 March 2010 04:55 Go to previous messageGo to next message
Eclipse UserFriend
That's a bad way to define a helper; use the context :

helper context InModel!Station def : isFinishStation : Boolean =
if (station = self.eContainer().finishStation) then

and then just use it like that : s.isFinishStation
Re: [ATL] Set boolean flag if object is referenced [message #521598 is a reply to message #521590] Thu, 18 March 2010 05:24 Go to previous messageGo to next message
Eclipse UserFriend
Sylvain EVEILLARD wrote on Thu, 18 March 2010 04:55

if (station = self.eContainer().finishStation) then



Thanks for the tip. It seems you ment the following:
self = self.eContainer().finishStation


Greetings,
Bernhard
Re: [ATL] Set boolean flag if object is referenced [message #521600 is a reply to message #521429] Thu, 18 March 2010 05:39 Go to previous message
Eclipse UserFriend
yep, copy/paste gone wrong Wink
Previous Topic:[ATL] Running ATL programmatically example?
Next Topic:how to use xtext before M2M transformation
Goto Forum:
  


Current Time: Mon Jul 14 10:58:46 EDT 2025

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

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

Back to the top