Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] how to find an already generated element in non-declarative rules ?
[ATL] how to find an already generated element in non-declarative rules ? [message #37805] Tue, 15 May 2007 08:46 Go to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

Hi All,

I'm stuck with a simple (?) problem: I want to transform a model (MA)
that conforms to a home-made metamodel (MMA) into another model that
conforms to eCore.
In my MMA, I have an element that can be combined with itself (i.e.
Element has a collection of <Element> called 'elements').
I want to transform these elements into EClass, so I have a declarative
rule that takes a Element in its 'from' clause and produce a EClass in
its 'to' clause.
But now I want the collection 'elements' to become a EReference in the
target model.
Because there is no corresponding entity in my source model, I can not
create a declarative rule for this transformation.
So I have added a called rule that create the new EReference, but I
can't see how to find the target of my EReference, which must be an
already generated EClass...
I understand that ATL can find target elements from the input elements,
but I think this can work only for declarative rules ??

Please Help !

Thanks in advance,
Sylvain

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #37935 is a reply to message #37805] Tue, 15 May 2007 13:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

Ok forget it,

In my called rule that create EReference, I'have added a parameter that
is the eType of eReference. As the rule is called from a declarative
rule, ATL is able to find the correct target element.

> Hi All,
>
> I'm stuck with a simple (?) problem: I want to transform a model (MA) that
> conforms to a home-made metamodel (MMA) into another model that conforms to
> eCore.
> In my MMA, I have an element that can be combined with itself (i.e. Element
> has a collection of <Element> called 'elements').
> I want to transform these elements into EClass, so I have a declarative rule
> that takes a Element in its 'from' clause and produce a EClass in its 'to'
> clause.
> But now I want the collection 'elements' to become a EReference in the target
> model.
> Because there is no corresponding entity in my source model, I can not create
> a declarative rule for this transformation.
> So I have added a called rule that create the new EReference, but I can't see
> how to find the target of my EReference, which must be an already generated
> EClass...
> I understand that ATL can find target elements from the input elements, but I
> think this can work only for declarative rules ??
>
> Please Help !
>
> Thanks in advance,
> Sylvain

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #37969 is a reply to message #37805] Tue, 15 May 2007 14:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rchevrel.sodius.com

This is a multi-part message in MIME format.
--------------030309010002050208030700
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Hi Sylvain,

I cannot completely understand your problem but I think this code could
help you.

-------------------------------------------------
rule root {
from
in_elm1 : MMa!Element
to
out_elm1 : ECore!EClass ()
}
-------------------------------------------------
rule elements {
from
-- you match a relation
e1 : MMa!Element,
e2 : MMA!Element (
e1.elements->includes(e2)
)
to
out_elm1 : ECore!EReference (
-- you attach this element with its parent
eContainer <- e1
),
out_elm2 : ECore!EReference (
-- you attach this element with its parent
eContainer <- e2,
-- you set the opposite
eOpposite <- out_elm1
)
}
-------------------------------------------------

You could also use a lazy rule.

Please send a concrete example if you have some problems.

*R
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #37999 is a reply to message #37969] Tue, 15 May 2007 14:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

Hi Regis,

With your code I think I can remove the called rule ! I did not see
this tips to match the relation.

thanks
Sylvain


> Hi Sylvain,
>
> I cannot completely understand your problem but I think this code could help
> you.
>
> -------------------------------------------------
> rule root {
> from
> in_elm1 : MMa!Element
> to
> out_elm1 : ECore!EClass ()
> }
> -------------------------------------------------
> rule elements {
> from
> -- you match a relation
> e1 : MMa!Element,
> e2 : MMA!Element (
> e1.elements->includes(e2)
> )
> to
> out_elm1 : ECore!EReference (
> -- you attach this element with its parent
> eContainer <- e1
> ),
> out_elm2 : ECore!EReference (
> -- you attach this element with its parent
> eContainer <- e2,
> -- you set the opposite
> eOpposite <- out_elm1
> )
> }
> -------------------------------------------------
>
> You could also use a lazy rule.
>
> Please send a concrete example if you have some problems.
>
> *Régis CHEVREL* <mailto:rchevrel@sodius.com>
>
>
> SODIUS*
> *6, rue Cornouaille
> 44319 Nantes - France
>
> Phone: +33 (0)2 28 23 54 34
>
> ***www.mdworkbench.com* <http://www.mdworkbench.com/>* *
> Draw more value from your model

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38059 is a reply to message #37969] Tue, 15 May 2007 15:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

Hi Régis

> Hi Sylvain,
>
> I cannot completely understand your problem but I think this code could help
> you.
>
> -------------------------------------------------
> rule root {
> from
> in_elm1 : MMa!Element
> to
> out_elm1 : ECore!EClass ()
> }
> -------------------------------------------------
> rule elements {
> from
> -- you match a relation
> e1 : MMa!Element,
> e2 : MMA!Element (
> e1.elements->includes(e2)
> )
> to
> out_elm1 : ECore!EReference (
> -- you attach this element with its parent
> eContainer <- e1

Unfortunately this doesn't work as eContainingClass from MOF is not
modifiable. It seems that a newly created EReference cannot be attached
to another EClassifier like that. I must explicitly add it to
eStructuralFeatures features of the EClass :-(

> ),
> out_elm2 : ECore!EReference (
> -- you attach this element with its parent
> eContainer <- e2,
> -- you set the opposite
> eOpposite <- out_elm1
> )
> }
> -------------------------------------------------
>
> You could also use a lazy rule.
>
> Please send a concrete example if you have some problems.
>
> *Régis CHEVREL* <mailto:rchevrel@sodius.com>
>
>
> SODIUS*
> *6, rue Cornouaille
> 44319 Nantes - France
>
> Phone: +33 (0)2 28 23 54 34
>
> ***www.mdworkbench.com* <http://www.mdworkbench.com/>* *
> Draw more value from your model

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38125 is a reply to message #38059] Tue, 15 May 2007 16: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
Hello Sylvain,

>> rule elements {
>> from
>> -- you match a relation
>> e1 : MMa!Element,
>> e2 : MMA!Element (
>> e1.elements->includes(e2)
>> )
>> to
>> out_elm1 : ECore!EReference (
>> -- you attach this element with its parent
>> eContainer <- e1
>
> Unfortunately this doesn't work as eContainingClass from MOF is not
> modifiable. It seems that a newly created EReference cannot be attached
> to another EClassifier like that. I must explicitly add it to
> eStructuralFeatures features of the EClass :-(

Being able to navigate and set references in both directions is *very*
useful in model transformation, especially when using a declarative style.

Here is an excerpt of a slide on metamodeling hints that I give to students:

* Define bidirectional associations (i.e., pairs of references)
=> Makes the model easier to navigate and populate


It seems that Ecore was not designed by model transformation developers :-).


A quick and dirty (i.e., imperative) way to solve your problem would be
to add an action block to rule "elements" to perform the setting in the
opposite direction:

do {
e1.eStructuralFeatures <- out_elm1;
}


Best regards,

Frédéric Jouault
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38157 is a reply to message #38125] Tue, 15 May 2007 16:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

Hi again,

> Hello Sylvain,
>
> >> rule elements {
> >> from
> >> -- you match a relation
> >> e1 : MMa!Element,
> >> e2 : MMA!Element (
> >> e1.elements->includes(e2)
> >> )
> >> to
> >> out_elm1 : ECore!EReference (
> >> -- you attach this element with its parent
> >> eContainer <- e1
> >
> > Unfortunately this doesn't work as eContainingClass from MOF is not
> > modifiable. It seems that a newly created EReference cannot be attached
> > to another EClassifier like that. I must explicitly add it to
> > eStructuralFeatures features of the EClass :-(
>
> Being able to navigate and set references in both directions is *very* useful
> in model transformation, especially when using a declarative style.
>
> Here is an excerpt of a slide on metamodeling hints that I give to students:
>
> * Define bidirectional associations (i.e., pairs of references)
> => Makes the model easier to navigate and populate
>
>
> It seems that Ecore was not designed by model transformation developers :-).
>
I agree with you on that point ;-)
>
> A quick and dirty (i.e., imperative) way to solve your problem would be to
> add an action block to rule "elements" to perform the setting in the opposite
> direction:
>
> do {
> e1.eStructuralFeatures <- out_elm1;
> }

well, I dont understand that: e1 refers to my input model, so it
doesn't have the eStructuralFeatures ! In order to do this I must get
the generated target eClass and I think it's bad ;-)

do
{
giveMeTheGeneratedEClassFor(e1).eStructuralFeatures <- out_elm1;
}

should solve my problem ;-)

>
>
> Best regards,
>
> Frédéric Jouault

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38258 is a reply to message #38157] Tue, 15 May 2007 16:46 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 again,

>> A quick and dirty (i.e., imperative) way to solve your problem would
>> be to add an action block to rule "elements" to perform the setting in
>> the opposite direction:
>>
>> do {
>> e1.eStructuralFeatures <- out_elm1;
>> }
>
> well, I dont understand that: e1 refers to my input model, so it doesn't
> have the eStructuralFeatures ! In order to do this I must get the
> generated target eClass and I think it's bad ;-)
>
> do
> {
> giveMeTheGeneratedEClassFor(e1).eStructuralFeatures <- out_elm1;
> }
>
> should solve my problem ;-)

Of course, you are right. I so much focused on the reverse setting part
of the issue that I missed this ;-).

giveMeTheGenerated<something>For is called resolveTemp in ATL.

This case is one of the rare cases when we are going to actually use
resolveTemp to resolve to the default target element (because we are
doing it in an imperative block):

do {
thisModule.resolveTemp(e1, 'out_elm1').eStructuralFeatures <- out_elm1;
}



Best regards,

Frédéric Jouault
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38324 is a reply to message #38258] Tue, 15 May 2007 17:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

> Hello again,
>
> >> A quick and dirty (i.e., imperative) way to solve your problem would
> >> be to add an action block to rule "elements" to perform the setting in
> >> the opposite direction:
> >>
> >> do {
> >> e1.eStructuralFeatures <- out_elm1;
> >> }
> >
> > well, I dont understand that: e1 refers to my input model, so it doesn't
> > have the eStructuralFeatures ! In order to do this I must get the
> > generated target eClass and I think it's bad ;-)
> >
> > do
> > {
> > giveMeTheGeneratedEClassFor(e1).eStructuralFeatures <- out_elm1;
> > }
> >
> > should solve my problem ;-)
>
> Of course, you are right. I so much focused on the reverse setting part of
> the issue that I missed this ;-).
>
> giveMeTheGenerated<something>For is called resolveTemp in ATL.
>
> This case is one of the rare cases when we are going to actually use
> resolveTemp to resolve to the default target element (because we are doing it
> in an imperative block):
>
> do {
> thisModule.resolveTemp(e1, 'out_elm1').eStructuralFeatures <- out_elm1;
> }

Well I tried this and I get an EmptyStackException... I dont understand
why: every elements should have been created at this time ?

>
>
>
> Best regards,
>
> Frédéric Jouault

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38422 is a reply to message #38324] Tue, 15 May 2007 17:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylvain.maillard.univ-nantes.fr

>> Hello again,
>>
>> >> A quick and dirty (i.e., imperative) way to solve your problem would
>> >> be to add an action block to rule "elements" to perform the setting in
>> >> the opposite direction:
>> >>
>> >> do {
>> >> e1.eStructuralFeatures <- out_elm1;
>> >> }
>> >
>> > well, I dont understand that: e1 refers to my input model, so it doesn't
>> > have the eStructuralFeatures ! In order to do this I must get the
>> > generated target eClass and I think it's bad ;-)
>> >
>> > do
>> > {
>> > giveMeTheGeneratedEClassFor(e1).eStructuralFeatures <- out_elm1;
>> > }
>> >
>> > should solve my problem ;-)
>>
>> Of course, you are right. I so much focused on the reverse setting part of
>> the issue that I missed this ;-).
>>
>> giveMeTheGenerated<something>For is called resolveTemp in ATL.
>>
>> This case is one of the rare cases when we are going to actually use
>> resolveTemp to resolve to the default target element (because we are doing
>> it in an imperative block):
>>
>> do {
>> thisModule.resolveTemp(e1, 'out_elm1').eStructuralFeatures <- out_elm1;
>> }
>
> Well I tried this and I get an EmptyStackException... I dont understand why:
> every elements should have been created at this time ?

OK my mistake: the second parameter of resolveTemp should be set to the
same name as the one specified in the rule used to create the parent
element ! in my case it was 'class' rather than 'out_elm1'.

Thanks for your help Frédéric ;-)


>
>>
>>
>>
>> Best regards,
>>
>> Frédéric Jouault

--
Sylvain
Re: [ATL] how to find an already generated element in non-declarative rules ? [message #38488 is a reply to message #38422] Tue, 15 May 2007 20:35 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

> OK my mistake: the second parameter of resolveTemp should be set to the
> same name as the one specified in the rule used to create the parent
> element ! in my case it was 'class' rather than 'out_elm1'.

Well, the example was confusing because both rules used the same target
element name in Régis' original example (note that I do not blame him: I
would have done exactly the same thing ;-)).

> Thanks for your help Frédéric ;-)

You are welcome.


Best regards,

Frédéric Jouault
Previous Topic:[ATL] how to keep reference to source Model in target model
Next Topic:Composite Class
Goto Forum:
  


Current Time: Mon Jan 25 15:15:08 GMT 2021

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

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

Back to the top