Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] : problem with EOposite and lazy rule
[ATL] : problem with EOposite and lazy rule [message #43478] Thu, 31 May 2007 14:47 Go to next message
Eclipse UserFriend
Originally posted by: tristan.faure.c-s.fr

Hi !
I have designed in my metamodel (ecore) a meta class
state with an attribute transition : transition => containment
and a meta class
transition with an attribute owner : state

for each attribut i've put the EOposite attribute

and for some of my rule there is no problem i can access to my owner when
i've inserted a new Element but ...

I have this rule =>

states <- defaultState,
states <- c.ownedMember->select(e |
e.isStereotyped(thisModule.ster_state_machine))
),
defaultState : _IF!State (
id <- thisModule.state_default_top,
options <- #start,
transition <- c.ownedOperation
->select(o | not o.isStereotyped(thisModule.ster_trigger_operation) and
not o.isStereotyped(thisModule.ster_create))
->collect(o | thisModule.Operation2Transition(o))

)

in my lazy rule thisModule.Operation2Transition(o) the field owner doesn't
exist (I tried to print it and i have oclUndefined) Is there something
special with lazy rule ???

Thank you !
Re: [ATL] : problem with EOposite and lazy rule [message #43602 is a reply to message #43478] Thu, 31 May 2007 23:49 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 Tristan,

I understand that your metamodel is not in KM3, but it would be so much
simpler if you wrote a bit of KM3 code instead of describing your
metamodel in natural language ;-).

For instance, I am really confused about eOpposite attributes!

Could you please try to describe your problem with some KM3 code?


Moreover, are all the bindings and expressions that you gave necessary
to understand the problem? If not, could you please get rid of the
unnecessary ones?

Thanks.

Regards,

Frédéric Jouault


Tristan FAURE wrote:
> Hi !
> I have designed in my metamodel (ecore) a meta class state with an
> attribute transition : transition => containment
> and a meta class
> transition with an attribute owner : state
> for each attribut i've put the EOposite attribute
>
> and for some of my rule there is no problem i can access to my owner
> when i've inserted a new Element but ...
>
> I have this rule =>
>
> states <- defaultState,
> states <- c.ownedMember->select(e |
> e.isStereotyped(thisModule.ster_state_machine))
> ),
> defaultState : _IF!State (
> id <- thisModule.state_default_top,
> options <- #start,
> transition <- c.ownedOperation
> ->select(o | not
> o.isStereotyped(thisModule.ster_trigger_operation) and not
> o.isStereotyped(thisModule.ster_create))
> ->collect(o |
> thisModule.Operation2Transition(o))
>
> )
>
> in my lazy rule thisModule.Operation2Transition(o) the field owner
> doesn't exist (I tried to print it and i have oclUndefined) Is there
> something special with lazy rule ???
>
> Thank you !
>
Re: [ATL] : problem with EOposite and lazy rule [message #43629 is a reply to message #43602] Fri, 01 June 2007 08:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tristan.faure.c-s.fr

ok i will write KM3 code :p

class Transition extends Element {
reference trigger[0-1] ordered container : Trigger oppositeOf owner;
reference nextState[0-1] ordered : State;
attribute statement[0-1] ordered : ;
attribute deadline[0-1] ordered : deadlineType;
reference timedGuard[0-1] ordered container : Guard oppositeOf ownerT;
reference discreteGuard[0-1] ordered container : Guard oppositeOf ownerD;
reference owner[0-1] ordered : State oppositeOf transition;
}

class State extends Element {
attribute options[*] ordered unique : StateOptionType;
reference transition[1-*] ordered container : Transition oppositeOf owner;
reference save[0-1] ordered : Signal;
attribute tpc[0-1] ordered : ;
reference subState[*] ordered container : State oppositeOf ownerState;
reference owner[0-1] ordered : Process oppositeOf states;
reference ownerState[0-1] ordered : State oppositeOf subState;
}

EOposite corresponds to oppositeOf and if i understand with this kind of
relation when i add an element in my attribute transition the attribute
owner of transition is automaically filled. this works everywhere except
in my lazy rule described in the precedent post.

So maybe there is a problem with this kind of relation in lazy rule ?
Or maybe it 's an other problem I tried to access to owner element in a do
section when this part of code is executed ???

i recopy my rule :


caller :

rule Class2Process {
from
c : UML!Class (c.oclIsTypeOf(UML!Class) and
c.isStereotyped(thisModule.ster_class)) --and c.isActive
to
s : _IF!Process (
id <- c.name,
nbInstancesToStart <- '0',
variables <-
c.ownedMember->select(a|a.oclIsTypeOf(UML!Property))->collect(p |
thisModule.Property2Variables(p)),
-- default variables for a process
variables <- Sequence {
thisModule.newVariable (thisModule.var_leader,'pid',true),
thisModule.newVariable (thisModule.var_callerObj,'pid',false),
thisModule.newVariable (thisModule.var_caller,'pid',false),
thisModule.newVariable (thisModule.var_waiting,'pid',false)
},
------------------------------------------------------------ ---
--states <- thisModule.newFinalState,
states <- defaultState,
states <- c.ownedMember->select(e |
e.isStereotyped(thisModule.ster_state_machine))
),
defaultState : _IF!State (
id <- thisModule.state_default_top,
options <- #start,
transition <- c.ownedOperation
->select(o | not o.isStereotyped(thisModule.ster_trigger_operation) and
not o.isStereotyped(thisModule.ster_create))
->collect(o | thisModule.Operation2Transition(o))

)
}

callee :
lazy rule Operation2Transition {
from
o : UML!Operation
using {
signalName : String = thisModule.pre_call + o.owner.name + '_' + o.name ;
processOwner : _IF!Process = _IF!Process ;
nbVarOid : Integer = 0 ;
}
to
t : _IF!Transition (
deadline <- #lazyO,
statement <- 'informal "--dynamic linking to ' + o.owner.name + '::' +
o.name +' --"; \n' +
'\t\tfork u2i__handler_' + o.owner.name + '__' + o.owner.name + '__'
+ o.name +'(u2i__parvar_waiting, u2i__parvar_caller,
u2i__parvar_callerObj, self',
trigger <- aTrigger
),
aTrigger : _IF!Trigger (
input <- sc
),
sc : _IF!SignalCall (
signalReferenced <- thisModule.mapSignals.get(signalName),
effectiveParameters <- Sequence {
thisModule.newVariable(thisModule.var_waiting,'null',false),
thisModule.newVariable(thisModule.var_caller,'null',false),
thisModule.newVariable(thisModule.var_callerObj,'null',false ),
thisModule.newVariable('void','null',false)
}
)
do {
-- getting the process of this transition
---sc.owner.owner.owner.toString().println() ;
t.owner.toString().println() ;
processOwner <- thisModule.gettingProcessOwner(sc) ;
-- counting the actual number of temp var
nbVarOid <- processOwner.variables
->select(v | v.name.startsWith('u2i__parvar_u2i__oid')).size() + 1 ;
-- for each parameter adding the host temp var
for (p in o.ownedParameter->select(p | p.name <> 'return')){
t.statement <- t.statement + ', ' + thisModule.var_tmp +
nbVarOid.toString() ;
sc.effectiveParameters <- thisModule.newVariable(thisModule.var_tmp +
nbVarOid.toString(),p.type.name.getType(),false) ;
processOwner.variables <- thisModule.newVariable(thisModule.var_tmp +
nbVarOid.toString(),p.type.name.getType(),false) ;
nbVarOid <- nbVarOid + 1 ;
}
t.statement <- t.statement + ') ;' ;
}
}

the problem is : t.owner.toString().println() ; which display oclUndefined
Re: [ATL] : problem with EOposite and lazy rule [message #43659 is a reply to message #43629] Fri, 01 June 2007 08:31 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,

> ok i will write KM3 code :p

Thanks ;-)


> class Transition extends Element {
> reference trigger[0-1] ordered container : Trigger oppositeOf owner;
> reference nextState[0-1] ordered : State;
> attribute statement[0-1] ordered : ;
> attribute deadline[0-1] ordered : deadlineType;
> reference timedGuard[0-1] ordered container : Guard oppositeOf
ownerT;
> reference discreteGuard[0-1] ordered container : Guard oppositeOf
> ownerD;
> reference owner[0-1] ordered : State oppositeOf transition;
> }
>
> class State extends Element {
> attribute options[*] ordered unique : StateOptionType;
> reference transition[1-*] ordered container : Transition oppositeOf
> owner;
> reference save[0-1] ordered : Signal;
> attribute tpc[0-1] ordered : ;
> reference subState[*] ordered container : State oppositeOf
ownerState;
> reference owner[0-1] ordered : Process oppositeOf states;
> reference ownerState[0-1] ordered : State oppositeOf subState;
> }

Do I really need to understand all these references and attributes to
understand your problem? If not, could you please keep only what is
necessary?


> EOposite corresponds to oppositeOf and if i understand with this kind of
> relation when i add an element in my attribute transition the attribute
> owner of transition is automaically filled. this works everywhere except
> in my lazy rule described in the precedent post.

Do you mean the eOpposite reference between EReferences in the Ecore
metametamodel?


> So maybe there is a problem with this kind of relation in lazy rule ?
> Or maybe it 's an other problem I tried to access to owner element in a
> do section when this part of code is executed ???

I really do not see what kind of problems there could be with lazy rules
and opposite references. However, I still have to look into your problem
in more details. I am just waiting to see if I can get a simpler
definition (i.e., only the necessary KM3 and ATL code) of it before
trying to understand it ;-).


Best regards,

Frédéric Jouault
Re: [ATL] : problem with EOposite and lazy rule [message #43687 is a reply to message #43659] Fri, 01 June 2007 08:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tristan.faure.c-s.fr

:$ sorry

this is the strict necessary to understand the problem

class Process extends Element {
reference states[*] ordered container : State oppositeOf owner;
}

class State extends Element {
reference transition[1-*] ordered container : Transition oppositeOf owner;
}

class Transition extends Element {
reference owner[0-1] ordered : State oppositeOf transition;
}

in a rule i to generate process i do
states <- defaultState
)
defaultState : _IF!State (
transition <- c.ownedOperation
->select(o | not o.isStereotyped(thisModule.ster_trigger_operation) and not
o.isStereotyped(thisModule.ster_create))
->collect(o | thisModule.Operation2Transition(o)) -- I apply a lazy rule
)

this is the lazy rule

lazy rule Operation2Transition {
from
o : UML!Operation
using {
...
processOwner : _IF!Process = _IF!Process ;
nbVarOid : Integer = 0 ;
}
to
t : _IF!Transition (
...
trigger <- aTrigger
),
aTrigger : _IF!Trigger (
input <- sc
),
sc : _IF!SignalCall (
....
do {
t.owner.toString().println() ;
processOwner <- thisModule.gettingProcessOwner(sc) ;
....
}
}

the problem is in the do section the owner attribute value of transition
is OclUndefined and should be the value of the default State(first Rule)
Re: [ATL] : problem with EOposite and lazy rule [message #43752 is a reply to message #43687] Fri, 01 June 2007 10: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
Hello,

> :$ sorry

No problem.

> this is the strict necessary to understand the problem

I just insist on this because having a minimal example that exhibits a
given problematic behavior can save a lot of time to diagnose it.

Moreover, I hope that next time you will go for the minimal example
directly ;-).


> class Process extends Element {
> reference states[*] ordered container : State oppositeOf owner;
> }
>
> class State extends Element {
> reference transition[1-*] ordered container : Transition oppositeOf
> owner;
> }
>
> class Transition extends Element {
> reference owner[0-1] ordered : State oppositeOf transition;
> }

Don't you miss a "owner" reference (oppositeOf "states") in class State?

You also declared reference "owner" as ordered, whereas:
- its opposite is already ordered (only one end can be ordered),
- the upper bound of multiplicity is 1.


> in a rule i to generate process i do
> states <- defaultState
> )
> defaultState : _IF!State (
> transition <- c.ownedOperation
> ->select(o | not o.isStereotyped(thisModule.ster_trigger_operation)
> and not o.isStereotyped(thisModule.ster_create))
> ->collect(o | thisModule.Operation2Transition(o)) -- I apply a lazy
> rule
> )
>
> this is the lazy rule
>
> lazy rule Operation2Transition {
> from o : UML!Operation using {
> ...
> processOwner : _IF!Process = _IF!Process ;
> nbVarOid : Integer = 0 ;
> }
> to
> t : _IF!Transition (
> ...
> trigger <- aTrigger
> ),
> aTrigger : _IF!Trigger (
> input <- sc
> ),
> sc : _IF!SignalCall (
> ....
> do {
> t.owner.toString().println() ;
> processOwner <- thisModule.gettingProcessOwner(sc) ;
> ....
> }
> }
>
> the problem is in the do section the owner attribute value of transition
> is OclUndefined and should be the value of the default State(first Rule)

You are not allowed to navigate target models in declarative code.
Here, you are trying to do it from an imperative block.
Although this is allowed, it is your responsibility to make sure you do
only things that can work.

Typically, what works is navigating properties you have initialized in
the very same rule.
Alternatively, you can do any kind of navigation from the endpoint
called rule, because then the declarative part of the transformation has
been completely executed.

In your case, you are trying to navigate "owner", expecting it to be
initialized in the "calling" rule when its opposite ("transition") is
initialized. However, "transition" will only be initialized when rule
Operation2Transition returns (i.e., after the imperative block has been
executed).



Here is my advice: try to understand why you need to navigate the source
model. In many cases this is really not necessary, and the same result
can be achieved by navigating the source model. This is often not more
complex, and sometimes even simpler.

If you really need to navigate the target model, then try to do it by
navigating properties initialized in the same rule, or by doing it in
the endpoint called rule.

Once you have identified why you want to navigate the target model, do
not hesitate to ask if, for instance, you do not see how to transform
target model navigation into source model navigation.


Best regards,

Frédéric Jouault
Re: [ATL] : problem with EOposite and lazy rule [message #43785 is a reply to message #43752] Fri, 01 June 2007 10:22 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
> Here is my advice: try to understand why you need to navigate the source
> model. In many cases this is really not necessary, and the same result
> can be achieved by navigating the source model. This is often not more
> complex, and sometimes even simpler.

Obviously, what you need to understand is why you need to navigate the
*target* model, and not the source model as I mistakenly typed!


Many thanks to Freddy for pointing this out ;-).



Regards,

Frédéric Jouault
Re: [ATL] : problem with EOposite and lazy rule [message #43807 is a reply to message #43785] Fri, 01 June 2007 13:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tristan.faure.c-s.fr

okay I understand why it doesn't work !!!
(for the order in fact i generated the km3 code and i disn't checked
correctly :oups:)

i have a question if i can browse the source model.
how can i access to a reference already generated for exemple

I have a class transformed by a rule Class2Process

I have a process

If i found an UML operation is it possible to found the process generated
by the owner of the operation (the class)

something like that
from o : _UML!Operation
using {
process : _IF!Process = o.owner ;
}
I know this doesn't work but i need the reference of the process generated
from this reference

Sorry it's a little difficult to explain by mail :s
Re: [ATL] : problem with EOposite and lazy rule [message #43837 is a reply to message #43807] Fri, 01 June 2007 13:40 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,

> okay I understand why it doesn't work !!!

Ok :-).


> (for the order in fact i generated the km3 code and i disn't checked
> correctly :oups:)

Well, if you tried to reinject the KM3 code, it should tell you there is
a problem. However, if Ecore2KM3 set the reference as ordered, it is
because it is ordered in your Ecore metamodel, which you should probably
correct.

This is also a good reason to use KM3 to design your metamodels: it will
check for many potential errors.


> i have a question if i can browse the source model.
> how can i access to a reference already generated for exemple
>
> I have a class transformed by a rule Class2Process
>
> I have a process
>
> If i found an UML operation is it possible to found the process
> generated by the owner of the operation (the class)
>
> something like that
> from o : _UML!Operation
> using {
> process : _IF!Process = o.owner ;
> } I know this doesn't work but i need the reference of the process
> generated from this reference
> Sorry it's a little difficult to explain by mail :s

Well, using ATL automatic traceability, it is... automatic. However, you
cannot use the traceability in the variable definition seciont
(introduced by the "using" keyword), but you can use it in the target
pattern.

For instance:

from
o : UML!Operation
to
t : IF!Something (
process <- o.owner
)

The <- operator will automatically resolve the owner (i.e., a Class)
into the target element that was generated from it (i.e., a Process, in
rule Class2Process). As you can see, this is quite simple and concise ;-).


Best regards,

Frédéric Jouault
Re: [ATL] : problem with EOposite and lazy rule [message #43867 is a reply to message #43837] Fri, 01 June 2007 13:50 Go to previous message
Eclipse UserFriend
Originally posted by: tristan.faure.c-s.fr

thank you very much i will continue my (huge (for me)) transformation
Previous Topic:[ATL] problem with programmatically transformation output model
Next Topic:[ATL] Proper nesting
Goto Forum:
  


Current Time: Thu Jan 21 15:17:12 GMT 2021

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

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

Back to the top