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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Frédéric Jouault 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
|
|
| |
Goto Forum:
Current Time: Tue Sep 24 08:28:36 GMT 2024
Powered by FUDForum. Page generated in 0.04715 seconds
|