Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Proper nesting
[ATL] Proper nesting [message #43388] Thu, 31 May 2007 13:16 Go to next message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

Hi everybody,

I want to create a UML to UML transformation.

When I look at my input XMI file, everything is contained in the UML:Model
element.

<UML:Model xmi.id='eee_1045467100313_135436_1' name='Data'>
<UML:ModelElement.comment>
<UML:Comment xmi.id='_9_5_1_3e4f06c0_1180422049437_213635_233'
name='This is comment'/>
</UML:ModelElement.comment>
...
</UML:Model>

As a test I wanted to apply the following transformation rule:

module UML2UML; -- Module Template
create OUT : UML refining IN : UML;

rule m2m {
from
m_in : UML!Model
to
m_out : UML!Model (
name <- m_in.name,
comment <- m_in.comment
)
}

This rule, however, creates a reference in Model to a Comment outside of
Model:

<UML:Model xmi.id = 'a1' name = 'Data' isSpecification = 'false' isRoot =
'false' isLeaf = 'false' isAbstract = 'false'>
<UML:ModelElement.comment>
<UML:Comment xmi.idref = 'a2'/>
</UML:ModelElement.comment>
</UML:Model>
<UML:Comment xmi.id = 'a2' name = 'This is comment' isSpecification =
'false'>
<UML:Comment.annotatedElement>
<UML:Model xmi.idref = 'a1'/>
</UML:Comment.annotatedElement>
</UML:Comment>

How can I adjust my transformation rule in such a way, that not a reference
to comment but the actual comment is placed within Model and nothing is
places outside of Model?
Is it possible to specify a target element's parent so it will be contained
by that parent?

I need to know how to do this, because eventually I want to create a layout
of packages. After creating this layout I need to create Classes which
should be contained in the right package.

Can anyone help me out on this one?

Thanks in advance
Re: [ATL] Proper nesting [message #43417 is a reply to message #43388] Thu, 31 May 2007 14: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,

Containment is specified in the metamodel.

Your cases looks like you have two different UML metamodels, with
ModelElement.comment being a composition in the source metamodel, but
not in the target metamodel.

Could you please check whether ModelElement.comment is a containment in
your target UML metamodel? If it is not, simply changing it will solve
your problem. If it is, then we will have to look for the problem
somewhere else.


Note that I do not mean you are not using the exact same metamodel for
the transformation, but that the source model was created using a
different version of the metamodel (e.g., using a UML tool with a
slightly different metamodel).



Regards,

Frédéric Jouault


ATL_Apprentice wrote:
> Hi everybody,
>
> I want to create a UML to UML transformation.
>
> When I look at my input XMI file, everything is contained in the UML:Model
> element.
>
> <UML:Model xmi.id='eee_1045467100313_135436_1' name='Data'>
> <UML:ModelElement.comment>
> <UML:Comment xmi.id='_9_5_1_3e4f06c0_1180422049437_213635_233'
> name='This is comment'/>
> </UML:ModelElement.comment>
> ...
> </UML:Model>
>
> As a test I wanted to apply the following transformation rule:
>
> module UML2UML; -- Module Template
> create OUT : UML refining IN : UML;
>
> rule m2m {
> from
> m_in : UML!Model
> to
> m_out : UML!Model (
> name <- m_in.name,
> comment <- m_in.comment
> )
> }
>
> This rule, however, creates a reference in Model to a Comment outside of
> Model:
>
> <UML:Model xmi.id = 'a1' name = 'Data' isSpecification = 'false' isRoot =
> 'false' isLeaf = 'false' isAbstract = 'false'>
> <UML:ModelElement.comment>
> <UML:Comment xmi.idref = 'a2'/>
> </UML:ModelElement.comment>
> </UML:Model>
> <UML:Comment xmi.id = 'a2' name = 'This is comment' isSpecification =
> 'false'>
> <UML:Comment.annotatedElement>
> <UML:Model xmi.idref = 'a1'/>
> </UML:Comment.annotatedElement>
> </UML:Comment>
>
> How can I adjust my transformation rule in such a way, that not a reference
> to comment but the actual comment is placed within Model and nothing is
> places outside of Model?
> Is it possible to specify a target element's parent so it will be contained
> by that parent?
>
> I need to know how to do this, because eventually I want to create a layout
> of packages. After creating this layout I need to create Classes which
> should be contained in the right package.
>
> Can anyone help me out on this one?
>
> Thanks in advance
>
>
Re: [ATL] Proper nesting [message #43898 is a reply to message #43417] Sat, 02 June 2007 08:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

I'm using the UML 1.4 metamodel from the OMG website
(http://www.omg.org/docs/ad/01-02-15.xml)

You were right.

In this metamodel the Association with xmi.id a295 and name
"A_comment_annotatedElement" was not a composition.

I changed it to a composition and it indeed solved the problem.
The comment is now contained by the model.
Doesn't this change in the metamodel have any undesirable side effects?




"Fr
Re: [ATL] Proper nesting [message #43927 is a reply to message #43898] Sat, 02 June 2007 13:00 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,

> I'm using the UML 1.4 metamodel from the OMG website
> (http://www.omg.org/docs/ad/01-02-15.xml)
>
> You were right.
>
> In this metamodel the Association with xmi.id a295 and name
> "A_comment_annotatedElement" was not a composition.
>
> I changed it to a composition and it indeed solved the problem.
> The comment is now contained by the model.

;-).


> Doesn't this change in the metamodel have any undesirable side effects?

Well, if it was meant to be a composition not really.
If it was not, it will prevent you from associating a given comment to
more than one ModelElement.


Regards,

Frédéric Jouault
Re: [ATL] Proper nesting [message #43957 is a reply to message #43927] Sun, 03 June 2007 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

Hi!

First of all I want to thank you for helping me.

I thought maybe a very simple example would set me on the right track, but I
think I didn't come up with a good example, because I still don't know how
to do what I actually wanted to do.
The purpose of my example was to learn how to position an element in the
target model.

What I actually want to do is the following:
* The whole input model should be copied into the output model (both UML).
That's why I thought refining mode would be a good idea.

* In the input model a package with a specific name has to be matched. If
this match is found, then an additional package with a specific name has to
be created, without deleting the source package (both have to be present in
the target model).

* If classes are found in the source package, then these classes have to be
copied into the newly created package, without deleting the source package.
The names of these classes will be prefixed.

* All get-operations have to be matched in the classes in the matched source
package. These operations have to be copied into the target model into the
classes in the newly created package, but instead of get-operations, they
have to be turned into set-operations.

This transformation seems very simple to me, but I'm having a hard time
getting everything nested in the correct package.

Say I have the following INPUT:

<UML:Model xmi.id="a1" name="Data">
<UML:Namespace.ownedElement>
<UML:Package xmi.id="a2" name="PackA">
<UML:Namespace.ownedElement>
<UML:Class xmi.id="a3" name="Class1">
<UML:Classifier.feature>
<UML:Operation xmi.id="a4" name="getProperty"
visibility="public">
<UML:BehavioralFeature.parameter>
<UML:Parameter xmi.id="a5" kind="return" />
</UML:BehavioralFeature.parameter>
</UML:Operation>
</UML:Classifier.feature>
</UML:Class>
</UML:Namespace.ownedElement>
</UML:Package>
</UML:Namespace.ownedElement>
</UML:Model>

Then I would want the following OUTPUT:

<UML:Model xmi.id="a1" name="Data">
<UML:Namespace.ownedElement>
<UML:Package xmi.id="a2" name="PackA">
<UML:Namespace.ownedElement>
<UML:Class xmi.id="a3" name="Class1">
<UML:Classifier.feature>
<UML:Operation xmi.id="a4" name="getProperty"
visibility="public">
<UML:BehavioralFeature.parameter>
<UML:Parameter xmi.id="a5" kind="return" />
</UML:BehavioralFeature.parameter>
</UML:Operation>
</UML:Classifier.feature>
</UML:Class>
</UML:Namespace.ownedElement>
</UML:Package>
<UML:Package xmi.id="a6" name="PackB">
<UML:Namespace.ownedElement>
<UML:Class xmi.id="a7" name="XClass1">
<UML:Classifier.feature>
<UML:Operation xmi.id="a8" name="setProperty"
visibility="public">
<UML:BehavioralFeature.parameter>
<UML:Parameter xmi.id="a9" kind="return" />
</UML:BehavioralFeature.parameter>
</UML:Operation>
</UML:Classifier.feature>
</UML:Class>
</UML:Namespace.ownedElement>
</UML:Package>
</UML:Namespace.ownedElement>
</UML:Model>

I have made some transformation rules:
- One to copy Model;
- One to copy Package and create an additional Package;
- One to copy Classes and create additional Classes;
- One to copy Operations and create additional Operations.

As I said, the transformation is running in refining mode
(good or bad choice?)

Here are the rules:

rule model {
from
m_in : UML!Model
to
m_out : UML!Model (
name <- m_in.name,
ownedElement <- m_in.ownedElement
)
}

rule pack {
from
p_in : UML!Package(
p_in.name='PackA'
)
to
p_out : UML!Package(
name<-p_in.name,
ownedElement<-p_in.ownedElement
),
p_add : UML!Package(
name<-'PackB'
--how do I tell that PackB must be in Model?
)
}

rule class {
from
c_in : UML!Class
-- Still need to make sure to select only Classes from PackA
to
c_out : UML!Class(
name<-c_in.name,
feature<-c_in.feature
),
c_add : UML!Class(
name<-'X'+c_in.name
--how do I tell that this class should come in PackB?
)
}

rule op {
from
o_in : UML!Operation
-- Still need to make sure only to select get-ops from classes of
PackA
to
o_out : UML!Operation(
name<-o_in.name,
parameter<-o_in.parameter
),
o_add : UML!Operation(
name<-'set' + o_in.name --not yet correct
--Also, here I need to make sure the operation goes to the proper
target class.
)
}

The source package seems properly copied,
but the additional elements are created outside of the Model element.

I don't know how to get those nested in the proper position.

I can't solve this by changing stuff in the metamodel, because the metamodel
is correct.

How do I assign the new elements to the correct "parent" element?




"Fr
Re: [ATL] Proper nesting [message #43989 is a reply to message #43957] Sun, 03 June 2007 12:59 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,

Firstly, I believe the choice of refining mode is good, because you
really do not want to write copying rules for everything that you do not
modify.

An alternative would be to generate a copying transformation (e.g.,
using KM32ATLCopier:
http://www.eclipse.org/m2m/atl/atlTransformations/#KM32ATLCo pier)
that you could then modify, or, even better, superimpose with your own
rules (for an example, see
http://wiki.eclipse.org/index.php/ATL_Superimposition).



Secondly, regarding nesting:

You need to initialize the containment associations beween Model and
Package, Package and Class, and Class and Operation.

Depending on the UML metamodel you use:
- this can be easy if the association can be initialized in both
directions: then you simply initialize the "parent" (see your UML
metamodel to know its actual name) reference when you create the
additional Packages, Classes, and Operations.
- this can be a bit more painful if the association is unidirectional
(i.e., if the metamodel was *not* designed with transformation in mind):
you then need to add the newly created elements to the collection you
use to initialize the "children" (e.g., "ownedElement", or "feature" in
your case) reference. For instance, in rule model:

ownedElement <- m_in.ownedElement->union(
m_in.ownedElement->select(e |
e.oclIsKindOf(UML!Package)
)->select(e |
-- you may want to define the guard
-- in an attribute helper, so as to
-- reuse it instead of cloning it
e.name = 'PackA'
)->collect(e |
thisModule.resolveTemp(e, 'p_add')
)
)



Note that you will probably also need a rule to copy parameters.


Best regards,

Frédéric Jouault

P.S.: Thanks for thanking me for helping you ;-). It is always
gratifying to know that 1) the solution one suggests work, 2) the person
it was suggested to is grateful :-D.


ATL_Apprentice wrote:
> Hi!
>
> First of all I want to thank you for helping me.
>
> I thought maybe a very simple example would set me on the right track, but I
> think I didn't come up with a good example, because I still don't know how
> to do what I actually wanted to do.
> The purpose of my example was to learn how to position an element in the
> target model.
>
> What I actually want to do is the following:
> * The whole input model should be copied into the output model (both UML).
> That's why I thought refining mode would be a good idea.
>
> * In the input model a package with a specific name has to be matched. If
> this match is found, then an additional package with a specific name has to
> be created, without deleting the source package (both have to be present in
> the target model).
>
> * If classes are found in the source package, then these classes have to be
> copied into the newly created package, without deleting the source package.
> The names of these classes will be prefixed.
>
> * All get-operations have to be matched in the classes in the matched source
> package. These operations have to be copied into the target model into the
> classes in the newly created package, but instead of get-operations, they
> have to be turned into set-operations.
>
> This transformation seems very simple to me, but I'm having a hard time
> getting everything nested in the correct package.
>
> Say I have the following INPUT:
>
> <UML:Model xmi.id="a1" name="Data">
> <UML:Namespace.ownedElement>
> <UML:Package xmi.id="a2" name="PackA">
> <UML:Namespace.ownedElement>
> <UML:Class xmi.id="a3" name="Class1">
> <UML:Classifier.feature>
> <UML:Operation xmi.id="a4" name="getProperty"
> visibility="public">
> <UML:BehavioralFeature.parameter>
> <UML:Parameter xmi.id="a5" kind="return" />
> </UML:BehavioralFeature.parameter>
> </UML:Operation>
> </UML:Classifier.feature>
> </UML:Class>
> </UML:Namespace.ownedElement>
> </UML:Package>
> </UML:Namespace.ownedElement>
> </UML:Model>
>
> Then I would want the following OUTPUT:
>
> <UML:Model xmi.id="a1" name="Data">
> <UML:Namespace.ownedElement>
> <UML:Package xmi.id="a2" name="PackA">
> <UML:Namespace.ownedElement>
> <UML:Class xmi.id="a3" name="Class1">
> <UML:Classifier.feature>
> <UML:Operation xmi.id="a4" name="getProperty"
> visibility="public">
> <UML:BehavioralFeature.parameter>
> <UML:Parameter xmi.id="a5" kind="return" />
> </UML:BehavioralFeature.parameter>
> </UML:Operation>
> </UML:Classifier.feature>
> </UML:Class>
> </UML:Namespace.ownedElement>
> </UML:Package>
> <UML:Package xmi.id="a6" name="PackB">
> <UML:Namespace.ownedElement>
> <UML:Class xmi.id="a7" name="XClass1">
> <UML:Classifier.feature>
> <UML:Operation xmi.id="a8" name="setProperty"
> visibility="public">
> <UML:BehavioralFeature.parameter>
> <UML:Parameter xmi.id="a9" kind="return" />
> </UML:BehavioralFeature.parameter>
> </UML:Operation>
> </UML:Classifier.feature>
> </UML:Class>
> </UML:Namespace.ownedElement>
> </UML:Package>
> </UML:Namespace.ownedElement>
> </UML:Model>
>
> I have made some transformation rules:
> - One to copy Model;
> - One to copy Package and create an additional Package;
> - One to copy Classes and create additional Classes;
> - One to copy Operations and create additional Operations.
>
> As I said, the transformation is running in refining mode
> (good or bad choice?)
>
> Here are the rules:
>
> rule model {
> from
> m_in : UML!Model
> to
> m_out : UML!Model (
> name <- m_in.name,
> ownedElement <- m_in.ownedElement
> )
> }
>
> rule pack {
> from
> p_in : UML!Package(
> p_in.name='PackA'
> )
> to
> p_out : UML!Package(
> name<-p_in.name,
> ownedElement<-p_in.ownedElement
> ),
> p_add : UML!Package(
> name<-'PackB'
> --how do I tell that PackB must be in Model?
> )
> }
>
> rule class {
> from
> c_in : UML!Class
> -- Still need to make sure to select only Classes from PackA
> to
> c_out : UML!Class(
> name<-c_in.name,
> feature<-c_in.feature
> ),
> c_add : UML!Class(
> name<-'X'+c_in.name
> --how do I tell that this class should come in PackB?
> )
> }
>
> rule op {
> from
> o_in : UML!Operation
> -- Still need to make sure only to select get-ops from classes of
> PackA
> to
> o_out : UML!Operation(
> name<-o_in.name,
> parameter<-o_in.parameter
> ),
> o_add : UML!Operation(
> name<-'set' + o_in.name --not yet correct
> --Also, here I need to make sure the operation goes to the proper
> target class.
> )
> }
>
> The source package seems properly copied,
> but the additional elements are created outside of the Model element.
>
> I don't know how to get those nested in the proper position.
>
> I can't solve this by changing stuff in the metamodel, because the metamodel
> is correct.
>
> How do I assign the new elements to the correct "parent" element?
>
>
>
>
> "Frédéric Jouault" <frederic.jouault@univ-nantes.fr> schreef in bericht
> news:f3rplv$9hv$2@build.eclipse.org...
>> Hi,
>>
>>> I'm using the UML 1.4 metamodel from the OMG website
>>> (http://www.omg.org/docs/ad/01-02-15.xml)
>>>
>>> You were right.
>>>
>>> In this metamodel the Association with xmi.id a295 and name
>>> "A_comment_annotatedElement" was not a composition.
>>>
>>> I changed it to a composition and it indeed solved the problem.
>>> The comment is now contained by the model.
>> ;-).
>>
>>
>>> Doesn't this change in the metamodel have any undesirable side effects?
>> Well, if it was meant to be a composition not really.
>> If it was not, it will prevent you from associating a given comment to
>> more than one ModelElement.
>>
>>
>> Regards,
>>
>> Frédéric Jouault
>
>
>
Re: [ATL] Proper nesting [message #44020 is a reply to message #43989] Sun, 03 June 2007 16:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atl_apprentice.yahoo.com

You're good..

The association is bidirectional indeed.

>> rule pack {
>> from
>> p_in : UML!Package(
>> p_in.name='PackA'
>> )
>> to
>> p_out : UML!Package(
>> name<-p_in.name,
>> ownedElement<-p_in.ownedElement
>> ),
>> p_add : UML!Package(
>> name<-'PackB'
>> --how do I tell that PackB must be in Model?
>> )
>> }

In the part that creates PackB, I just added the following line:

namespace<-p_in.namespace

that was all.. and now PackB is properly nested..

Thanks!!

P.S. I'm using the metamodel provided by the OMG
(http://www.omg.org/docs/ad/01-02-15.xml)
Re: [ATL] Proper nesting [message #44049 is a reply to message #44020] Sun, 03 June 2007 17:11 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

> You're good..

;-)

> The association is bidirectional indeed.
>
>>> rule pack {
>>> from
>>> p_in : UML!Package(
>>> p_in.name='PackA'
>>> )
>>> to
>>> p_out : UML!Package(
>>> name<-p_in.name,
>>> ownedElement<-p_in.ownedElement
>>> ),
>>> p_add : UML!Package(
>>> name<-'PackB'
>>> --how do I tell that PackB must be in Model?
>>> )
>>> }
>
> In the part that creates PackB, I just added the following line:
>
> namespace<-p_in.namespace
>
> that was all.. and now PackB is properly nested..
>
> Thanks!!
>
> P.S. I'm using the metamodel provided by the OMG
> (http://www.omg.org/docs/ad/01-02-15.xml)

Ok. I am glad it now works for you.


Best regards,

Frédéric Jouault
Previous Topic:[ATL] : problem with EOposite and lazy rule
Next Topic:ATL - How to assign a new value to an attribute of type map
Goto Forum:
  


Current Time: Thu Jan 21 06:22:01 GMT 2021

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

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

Back to the top