Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] How to put model elements in a package that is created in another rule?
[ATL] How to put model elements in a package that is created in another rule? [message #80080] Mon, 28 April 2008 10:19 Go to next message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

Hey all,

I'm stuck with the following situation:

I want to map some model onto a UML model.

The first model is of a box which can contain squares and circles.

Therefore I created a rule:

rule struct {
from
b : BoxMM!Box
to
m : UML!Model (
name<- b.name
),
ps : UML!Package (
name<-'squares',
namespace<-m
),
pc : UML!Package (
name <-'circles',
namespace <-m
)
}


Now I want to put all the squares into the package squares and all the
circles into the package circle.
So I thought it would be easy to create another rule:

rule squares {
from
s : BoxMM!Square
to
c : UML!Class (
name<-s.name,
namespace <-ps <<<< THIS WON'T WORK!!
Because ps was created in another
rule.
)
}

and a similar rule for circles. How to reference the package 'squares' that
was created in another rule?

Kind regards
Re: [ATL] How to put model elements in a package that is created in another rule? [message #80097 is a reply to message #80080] Mon, 28 April 2008 11:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

Hi all,

I already found out how to do this using lazy rules.

Now I have one matched rule and two lazy rules.
Comments on how to do this in a better way are welcome of course.
This is my solution:

rule struct {
from
b : BoxMM!Box
to
m : UML!Model (
name<- b.name
),
ps : UML!Package (
name<-'squares',
namespace<-m,
ownedElement<-BoxMM!Square.allInstances()->collect(e|squares(e))
),
pc : UML!Package (
name <-'circles',
namespace <-m,
ownedElement<-BoxMM!Circle.allInstances()->collect(e|circles(e))
)
}

lazy rule squares {
from
s : BoxMM!Square
to
c : UML!Class (
name<-s.name
)
}

lazy rule circles {
from
s : BoxMM!Circle
to
c : UML!Class (
name<-s.name
)
}


"ATL_Apprentice" <atl_apprentice@yahoo.com> schreef in bericht
news:fv48b2$eg7$1@build.eclipse.org...
> Hey all,
>
> I'm stuck with the following situation:
>
> I want to map some model onto a UML model.
>
> The first model is of a box which can contain squares and circles.
>
> Therefore I created a rule:
>
> rule struct {
> from
> b : BoxMM!Box
> to
> m : UML!Model (
> name<- b.name
> ),
> ps : UML!Package (
> name<-'squares',
> namespace<-m
> ),
> pc : UML!Package (
> name <-'circles',
> namespace <-m
> )
> }
>
>
> Now I want to put all the squares into the package squares and all the
> circles into the package circle.
> So I thought it would be easy to create another rule:
>
> rule squares {
> from
> s : BoxMM!Square
> to
> c : UML!Class (
> name<-s.name,
> namespace <-ps <<<< THIS WON'T WORK!!
> Because ps was created in another
> rule.
> )
> }
>
> and a similar rule for circles. How to reference the package 'squares'
> that was created in another rule?
>
> Kind regards
>
Re: [ATL] How to put model elements in a package that is created in another rule? [message #80205 is a reply to message #80097] Tue, 29 April 2008 07:04 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

> I already found out how to do this using lazy rules.
>
> Now I have one matched rule and two lazy rules.
> Comments on how to do this in a better way are welcome of course.

Your solution with lazy rules should not actually need the rules to be
lazy to work. Therefore, you could also use:

rule struct {
from
b : BoxMM!Box
to
m : UML!Model (
name<- b.name
),
ps : UML!Package (
name<-'squares',
namespace<-m,
ownedElement<-BoxMM!Square.allInstances()
),
pc : UML!Package (
name <-'circles',
namespace <-m,
ownedElement<-BoxMM!Circle.allInstances()
)
}

rule squares {
from
s : BoxMM!Square
to
c : UML!Class (
name<-s.name
)
}

rule circles {
from
s : BoxMM!Circle
to
c : UML!Class (
name<-s.name
)
}


This works because source elements are automatically resolved into their
corresponding target elements.

Both your lazy rules solution, and the one above initialize the
ownedElement reference. You can also initialize the namespace reference
as you attempted to do in your previous code excerpt:

rule struct {
from
b : BoxMM!Box
to
m : UML!Model (
name<- b.name
),
ps : UML!Package (
name<-'squares',
namespace<-m
),
pc : UML!Package (
name <-'circles',
namespace <-m
)
}


rule squares {
from
s : BoxMM!Square
to
c : UML!Class (
name<-s.name,
namespace <-thisModule.resolveTemp(<an expression to get
the box>, 'ps')
)
}


Where <an expression to get the box> may be any expression that can
retrieve the Box. For instance, if a square has a reference myBox to its
box, then you can use:

namespace <-thisModule.resolveTemp(s.myBox, 'ps')

If the square is directly contained in the box, then you can also use:

namespace
<-thisModule.resolveTemp(s.refImmediateComposite(), 'ps')

Otherwise, you may need to write a recursive helper to get the box.



There is another alternative that does not make use of resolveTemp:
using unique lazy rules.



rule struct {
from
b : BoxMM!Box
to
m : UML!Model (
name<- b.name
)
}

unique lazy rule squaresPackage {
from
b : BoxMM!Box
to
ps : UML!Package (
name<-'squares',
namespace<-b -- will be resolved into the Model
)
)

unique lazy rule circlesPackage {
from
b : BoxMM!Box
to
pc : UML!Package (
name <-'circles',
namespace <-b -- will be resolved into the Model
)
}


rule squares {
from
s : BoxMM!Square
to
c : UML!Class (
name<-s.name,
namespace <-thisModule.squaresPackage(<an expression to get
the box>, 'ps')
)
}

Note that you also need to get the box from the squares in this solution.


Regards,

Frédéric Jouault
Re: [ATL] How to put model elements in a package that is created in another rule? [message #80312 is a reply to message #80205] Tue, 29 April 2008 09:06 Go to previous message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

Thank you for your clear explanation with examples.


"Fr
Previous Topic:ATL polymorphism
Next Topic:[ATL] Multiple source patterns
Goto Forum:
  


Current Time: Mon Jul 22 14:39:50 GMT 2019

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

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

Back to the top