Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL]Problem generating Model
[ATL]Problem generating Model [message #58767] Mon, 20 August 2007 12:52 Go to next message
Eclipse UserFriend
Originally posted by: maximilian.weinhart.sdm.de

Hi,

I am new to ATL.

I have a problem generating a target metamodel.
Explanation to the source- and targetmetamodel :
Every Class in the sourcemodel should be a Shape in the targetmodel.
Every Shape in the targetmodel should be connected through Edges.
Every Edge has got two EdgeEnds, which are directly connected to the
Node(s).

What I have written until now works fine except that I don
Re: [ATL]Problem generating Model [message #59026 is a reply to message #58767] Tue, 21 August 2007 21:17 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
Hi,

When writing declarative ATL code, the implicit traceability mechanism
enables simple resolution of elements.

If you write imperative code, then you have to deal with traceability
manually.

My advice would be to first try to find a declarative solution to your
problem before working on manual traceability.


For the moment, I see two possibilities:
- You could try to use lazy rules to be able to find the edge
corresponding to a given source element.
- You may be able to generate all the target elements that correspond to
attributes and relations in the rule that creates the Shape. Then,
thisModule.resolveTemp could be used to find the edges.


Note that the second solution is likely to be more verbose than what you
currently have. However, I have the feeling that most of your code could
be automatically generated from your source metamodel using a Higher
Order Transformation (HOT, i.e., a transformation that generates a
transformation).

Moreover, you could then reuse the same code for any source metamodel.
You could even deal with metamodel-specific customizations by having
your HOT take an additional model as input specifying them.



Regards,

Frédéric Jouault


exquisitus wrote:
> Hi,
>
> I am new to ATL.
>
> I have a problem generating a target metamodel.
> Explanation to the source- and targetmetamodel :
> Every Class in the sourcemodel should be a Shape in the targetmodel.
> Every Shape in the targetmodel should be connected through Edges.
> Every Edge has got two EdgeEnds, which are directly connected to the
> Node(s).
>
> What I have written until now works fine except that I don´t know how to
> connect the generated EdgeEnds to Edges.
> It is possible to connect the generated EdgeEnd with the parallel generated
> Edge, but
> I don´t know how to add "the other EdgeEnd" of another Node to the generated
> Edge.
> I thought it could be done with (rel in
> a.refGetValue(relName).asSequence()) located in the Customer2Shape rule,but
> that doesn´t work.
>
> I have also marked my Problem in the code and attached two graphics with the
> models.
>
> Regards
>
> Max
>
> Code:
>
> helper def : textLineIDCounter : Integer = 0;
> rule Customer2Shape {
> from
> a : GenMetamodel!customer
> using{
> attribs : Sequence(String) =
> Sequence{'forename','surname','street','housenumber'};
> relations : Sequence(String) =
> Sequence{'uses','lives_near'};
> }
> to
> sh : NodesEdgesMModel!Shape
> (
> shapeType <- 'CustomerRectangle'
> )
> do{
> for(attr in attribs){
> thisModule.NewTextLine ( a , attr);
> }
> for(relName in relations){
> for(rel in a.refGetValue(relName).asSequence()){
> thisModule.NewEdgeEndAndTextLine( sh, relName );
> }
> }
> }
>
> ### for every type like product, maufacturer etc. the same code as for
> customer2shape is used ###
>
> rule NewTextLine ( a : GenMetamodel!customer, attributeName: String){
> to
> tl : NodesEdgesMModel!TextLine
> (
> textLineID <- thisModule.textLineIDCounter,
> text <- a.refGetValue(attributeName).toString(),
> TextLine_to_Node <- a
> )
> do{
> thisModule.textLineIDCounter <- thisModule.textLineIDCounter + 1;
> }
> }
>
> rule NewEdgeEndAndTextLine ( sh : NodesEdgesMModel!Shape, relationName:
> String ){
> to
> eEnd : NodesEdgesMModel!EdgeEnd
> (
> EdgeEnd_to_TextLine <- tl,
> EdgeEnd_to_Node <- sh
> ),
> tl : NodesEdgesMModel!TextLine
> (
> textLineID <- thisModule.textLineIDCounter,
> text <- relationName.toString()
> ),
> edge : NodesEdgesMModel!Edge
> (
> -- ####
> -- Here the problem is that Edge_to_EdgeEnd should point to two
> elements (customer, product etc.) to connect two Nodes.
> -- But i don´t know how to set the second relation
> -- I thought it could be done with rel in
> a.refGetValue(relName).asSequence() located in the Customer2Shape rule,
> -- but that doesn´t work.
> -- ####
>
> Edge_to_EdgeEnd <- eEnd
>
> )
> do{
> thisModule.textLineIDCounter <- thisModule.textLineIDCounter + 1;
> }
> }
>
>
>
Re: [ATL]Problem generating Model [message #59076 is a reply to message #59026] Wed, 22 August 2007 11:15 Go to previous message
Eclipse UserFriend
Originally posted by: maximilian.weinhart.sdm.de

Hi,
Now I tried to generate most targetelements in the rule Customer2Shape.
In the code below I have tried just making the customer to product relation
work.
In the Customer2Shape rule I wanted to generate the edge and in
Product2Shape I wanted to connect to the generated edge(s).
I get an error from ATL.
I think the problem is that 'edgeUses' contains more than one element/ edge.
Or is there another reason for that error ?
How to solve it ?

Regards,

Max

SCHWERWIEGEND: ****** BEGIN Stack Trace
SCHWERWIEGEND: message: ERROR: could not find operation
getNamedTargetFromSource on Void having supertypes: [OclAny]
SCHWERWIEGEND: A.main() : ??#26 null
SCHWERWIEGEND: local variables = {self=Storage2Nodes : ASMModule}
SCHWERWIEGEND: local stack = []
SCHWERWIEGEND: A.__exec__() : ??#18 null
SCHWERWIEGEND: local variables = {self=Storage2Nodes : ASMModule,
e=TransientLink {rule = 'Product2Shape', sourceElements = {a = IN!Bycicle
Racingbike}, targetElements = {sh = OUT!<unnamed>, eEndIsUsedBy = Sequence
{OUT!<unnamed>}, tl = Sequence {OUT!<unnamed>, OUT!<unnamed>,
OUT!<unnamed>}}, variables = {attribs = Sequence {'price', 'name', 'id'},
relations = Sequence {'is_used_by', 'is_produced_by', 'is_stored_in'}}}}
SCHWERWIEGEND: local stack = []
SCHWERWIEGEND: A.__applyProduct2Shape(1 : NTransientLink;) : ??#152
86:23-86:70
SCHWERWIEGEND: local variables = {relation=IN!<unnamed>, attribs=Sequence
{'price', 'name', 'id'}, sh=OUT!<unnamed>, eEndIsUsedBy=Sequence
{OUT!<unnamed>}, a=IN!Bycicle Racingbike, self=Storage2Nodes : ASMModule,
collection=Sequence {IN!<unnamed>}, relations=Sequence {'is_used_by',
'is_produced_by', 'is_stored_in'}, counter=1, tl=Sequence {OUT!<unnamed>,
OUT!<unnamed>, OUT!<unnamed>}, link=TransientLink {rule = 'Product2Shape',
sourceElements = {a = IN!Bycicle Racingbike}, targetElements = {sh =
OUT!<unnamed>, eEndIsUsedBy = Sequence {OUT!<unnamed>}, tl = Sequence
{OUT!<unnamed>, OUT!<unnamed>, OUT!<unnamed>}}, variables = {attribs =
Sequence {'price', 'name', 'id'}, relations = Sequence {'is_used_by',
'is_produced_by', 'is_stored_in'}}}}
SCHWERWIEGEND: local stack = [OUT!<unnamed>, OUT!<unnamed>, Storage2Nodes :
ASMModule]
SCHWERWIEGEND: A.resolveTemp(1 : J, 2 : S) : ??#6 null
SCHWERWIEGEND: local variables = {name='edgeUses', self=Storage2Nodes :
ASMModule, value=Sequence {IN!<unnamed>}}
SCHWERWIEGEND: local stack = []
SCHWERWIEGEND: ****** END Stack Trace

module Storage2Nodes; -- Module Template
create OUT : NodesEdgesMModel from IN : GenMetamodel;

helper def : textLineIDCounter : Integer = 0;

rule Customer2Shape {
from
a : GenMetamodel!customer
using{
attribs : Sequence(String) =
Sequence{'forename','surname','street','housenumber'};
relations : Sequence(String) =
Sequence{'uses','lives_near'};
}
to
sh : NodesEdgesMModel!Shape
(
nodeID <- 'customer.' + a.id.toString(),
shapeType <- 'CustomerSquare'
) ,
tl : distinct NodesEdgesMModel!NodeTextLine foreach (attr in
attribs)
(
textLineID <- attr.toString() ,
text <- a.refGetValue(attr).toString(),
TextLine_to_Node <- a
),
eEndUses : distinct NodesEdgesMModel!EdgeEnd foreach ( relation in
a.refGetValue('uses').asSequence() )
(
edgeEndID <- 'customer.' + a.id.toString() + '.uses',
EdgeEnd_to_Node <- sh
),
eEndLivesNear : distinct NodesEdgesMModel!EdgeEnd foreach ( relation
in a.refGetValue('lives_near').asSequence() )
(
edgeEndID <- 'customer.' + a.id.toString() + '.lives_near',
EdgeEnd_to_Node <- sh
),
edgeUses : distinct NodesEdgesMModel!Edge foreach ( relation in
a.refGetValue('uses').asSequence() )
(
Edge_to_EdgeEnd <- eEndUses
) ,
edgeLivesNear : distinct NodesEdgesMModel!Edge foreach ( relation in
a.refGetValue('lives_near').asSequence() )
(
Edge_to_EdgeEnd <- eEndLivesNear
)
do{
eEndUses.output();
for( eUses in eEndUses ){
thisModule.NewTextLineUses(a,eUses);
}
for( eLives in eEndLivesNear ){
thisModule.NewTextLineLivesNear(a,eLives);
}
}
}

rule Product2Shape {
from
a : GenMetamodel!product
using{
attribs : Sequence(String) = Sequence{'price','name','id'};
relations : Sequence(String) =
Sequence{'is_used_by','is_produced_by','is_stored_in'};
}
to
sh : NodesEdgesMModel!Shape
(
nodeID <- 'product.' + a.id.toString(),
shapeType <- 'ProductSquare'
) ,
tl : distinct NodesEdgesMModel!NodeTextLine foreach (attr in
attribs)
(
textLineID <- attr.toString() , -- '#' +
a.refGetValue(attr).toString(),
text <- a.refGetValue(attr).toString(),
TextLine_to_Node <- a
),
eEndIsUsedBy : distinct NodesEdgesMModel!EdgeEnd foreach ( relation
in a.refGetValue('is_used_by').asSequence() )
(
edgeEndID <- 'product.' + a.id.toString() + '.is_used_by',
EdgeEnd_to_Node <- sh,
-- ###### ERROR
EdgeEnd_to_Edge <-
thisModule.resolveTemp(a.is_used_by,'edgeUses')
-- ###### ERROR
)
do{
for( eUses in eEndIsUsedBy ){
thisModule.NewTextLineIsUsedBy(a,eUses);
}
}
}

rule NewTextLineUses ( a : GenMetamodel!customer, eUses: OclAny ){
to
tl : NodesEdgesMModel!EdgeEndTextLine
(
textLineID <- eUses.edgeEndID,
text <- 'uses',
TextLine_to_EdgeEnd <- eUses
)
}

rule NewTextLineLivesNear ( a : GenMetamodel!customer, eLives: OclAny ){
to
tl : NodesEdgesMModel!EdgeEndTextLine
(
textLineID <- eLives.edgeEndID,
text <- 'lives_near',
TextLine_to_EdgeEnd <- eLives
)
}

rule NewTextLineIsUsedBy ( a : GenMetamodel!product, eUses: OclAny ){
to
tl : NodesEdgesMModel!EdgeEndTextLine
(
textLineID <- eUses.edgeEndID,
text <- 'is_used_by',
TextLine_to_EdgeEnd <- eUses
)
}


"Fr
Previous Topic:[ATL] : Using a Set in the "from" action
Next Topic:[ATL] : Exception when using two variable in the "from" action
Goto Forum:
  


Current Time: Mon Jan 18 08:58:07 GMT 2021

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

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

Back to the top