Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] EEnum to EClass
[ATL] EEnum to EClass [message #546793] Wed, 14 July 2010 09:00 Go to next message
Izaak van Niekerk is currently offline Izaak van NiekerkFriend
Messages: 35
Registered: June 2010
Member
I need to transform a class X with an EEnum attribute called Y of value "B" into the next model where class X will have a reference to EClass Y that has a String description attribute with the value "B".
And all other class X transformations that point to the same EEnum will also have to reference that same new EClass Y when transformed.

In otherwords EEnum Y needs to be transformed into EClass Y and all the objects that were referencing this enumeration value will now have a reference to this newly created EClass Y.

Can somebody please help me with how I would go about constructing these rules? I don't want to create a new instance of EClass with a value "B" everytime I find the value, so I probably need some way of pre-transforming all the enumeration values into instances of EClass Y before hand and then somehow find a reference to them during transformation of class X?
Re: [ATL] EEnum to EClass [message #547393 is a reply to message #546793] Fri, 16 July 2010 15:07 Go to previous messageGo to next message
Freddy Allilaire is currently offline Freddy AllilaireFriend
Messages: 130
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010902090805020901030107
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Dear Izaak,

I don't really understand well your problem. Could you please give us
more details (e.g. about your metamodels)?

Thanks,
Freddy.

Le 14/07/2010 11:00, Izaak a écrit :
> I need to transform a class X with an EEnum attribute called Y of value
> "B" into the next model where class X will have a reference to EClass Y
> that has a String description attribute with the value "B".
> And all other class X transformations that point to the same EEnum will
> also have to reference that same new EClass Y when transformed.
>
> In otherwords EEnum Y needs to be transformed into EClass Y and all the
> objects that were referencing this enumeration value will now have a
> reference to this newly created EClass Y.
>
> Can somebody please help me with how I would go about constructing these
> rules? I don't want to create a new instance of EClass with a value "B"
> everytime I find the value, so I probably need some way of
> pre-transforming all the enumeration values into instances of EClass Y
> before hand and then somehow find a reference to them during
> transformation of class X?


--------------010902090805020901030107
Content-Type: text/x-vcard; charset=utf-8;
name="freddy_allilaire.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="freddy_allilaire.vcf"

YmVnaW46dmNhcmQNCmZuOkZyZWRkeSBBbGxpbGFpcmUNCm46QWxsaWxhaXJl O0ZyZWRkeQ0K
b3JnOk9CRU8NCmFkcjtxdW90ZWQtcHJpbnRhYmxlOjs7NyBCb3VsZXZhcmQg QW1wPUMzPUE4
cmU7Q0FSUVVFRk9VOzs0NCA0ODE7RnJhbmNlDQplbWFpbDtpbnRlcm5ldDpm cmVkZHkuYWxs
aWxhaXJlQG9iZW8uZnINCnVybDp3d3cub2Jlby5mcg0KdmVyc2lvbjoyLjEN CmVuZDp2Y2Fy
ZA0KDQo=
--------------010902090805020901030107--
Re: [ATL] EEnum to EClass [message #547402 is a reply to message #546793] Fri, 16 July 2010 15:50 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHEFriend
Messages: 129
Registered: July 2009
Senior Member
Le 14/07/2010 11:00, Izaak a écrit :
> I need to transform a class X with an EEnum attribute called Y of value
> "B" into the next model where class X will have a reference to EClass Y
> that has a String description attribute with the value "B".
> And all other class X transformations that point to the same EEnum will
> also have to reference that same new EClass Y when transformed.
>
> In otherwords EEnum Y needs to be transformed into EClass Y and all the
> objects that were referencing this enumeration value will now have a
> reference to this newly created EClass Y.
>
> Can somebody please help me with how I would go about constructing these
> rules? I don't want to create a new instance of EClass with a value "B"
> everytime I find the value, so I probably need some way of
> pre-transforming all the enumeration values into instances of EClass Y
> before hand and then somehow find a reference to them during
> transformation of class X?

You have to generate the B instance for the enum in a "unique called
rule" which parameter is the enum value. Doing so, each you encounter a
given value of this enum, ATL will return the same B corresponding instance.
--
Cordialement

Vincent MAHÉ

Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
Re: [ATL] EEnum to EClass [message #547406 is a reply to message #547402] Fri, 16 July 2010 16:14 Go to previous messageGo to next message
Izaak van Niekerk is currently offline Izaak van NiekerkFriend
Messages: 35
Registered: June 2010
Member
Hi Vincent,

Would this rule also create one instance of "B" then so that it can be referenced every time "B" is encountered?

@Freddy

> Could you please give us more details (e.g. about your
> metamodels)?

Version 1:
--------------
Class "RoleSpec" has a feature "conformanceType" that is of type "RoleSpecTypeExplorer".

"RoleSpecTypeExplorer" is an Enumrator with values:
Party = 0, Account = 1, Place=2, Agreement=3

Version 2:
--------------
Class "RoleSpec" has a feature "conformanceType" that is of type "Type".

"Type" is a class with a feature "name" of type String.

So when Version1 is transformed to Version2, RoleSpec's feature comformanceType must be transformed from an enumeration to a class, and an instance of Type must be created with name set to "Party" or "Account" or "Place" etc.

One instance of each enumeration must be created and every RoleSpec that for instance have a conformanceType with enumeration value of "Party" must reference that same instance of Type with name "Party".

Hope this is more clear?

[Updated on: Fri, 16 July 2010 19:28]

Report message to a moderator

Re: [ATL] EEnum to EClass [message #547633 is a reply to message #547406] Mon, 19 July 2010 08:30 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHEFriend
Messages: 129
Registered: July 2009
Senior Member
Le 16/07/2010 18:14, Izaak a écrit :
> Hi Vincent,
>
> Would this rule also create one instance of "B" then so that it can be
> referenced every time "B" is encountered?

You can call another unique rule to create B and use this rule every
time you need to get a B instance
--
Cordialement

Vincent MAHÉ

Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
Re: [ATL] EEnum to EClass [message #547847 is a reply to message #547633] Mon, 19 July 2010 19:08 Go to previous messageGo to next message
Izaak van Niekerk is currently offline Izaak van NiekerkFriend
Messages: 35
Registered: June 2010
Member
Thank you Freddy and William for all the help!

The following code did the trick:

helper def: enumMap : Map(PMWV1!Location, String) =
Map {(#IL, 'IL'), (#AZ, 'AZ'), (#AK, 'AK')};

helper def: enumByName : Map(PMWV1!Location, PMWV2!CriteriaAllowedValue) = Map {};

helper def: getEnum(s : PMWV1!Location) : OclAny =
if (thisModule.enumByName.containsKey(s)) then
(thisModule.enumByName.get(s))
else
(thisModule.enum(s))
endif;

rule enum(s : PMWV1!Location) {
to
t : PMWV2!CriteriaAllowedValue(
description <- thisModule.enumMap.get(s)
)
do {
thisModule.enumByName <- thisModule.enumByName.including(s, t);
t;
}
}


Basically build up a map of the instances created and first check the map for an instance before creating one again...
Re: [ATL] EEnum to EClass [message #547912 is a reply to message #546793] Tue, 20 July 2010 07:41 Go to previous message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Using the keyword unique you can simplify that to :

helper def: enumMap : Map(PMWV1!Location, String) =
Map {(#IL, 'IL'), (#AZ, 'AZ'), (#AK, 'AK')};

unique lazy rule enum{
from s : PMWV1!Location
to
t : PMWV2!CriteriaAllowedValue(
description <- thisModule.enumMap.get(s)
)
}

Though it's a lazy rule, the call to it is the same as with the called rule.

[Updated on: Tue, 20 July 2010 07:42]

Report message to a moderator

Previous Topic:programmatically invoke ATL
Next Topic:[QVTO] ClassNotFound in blackbox
Goto Forum:
  


Current Time: Fri Apr 26 02:24:38 GMT 2024

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

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

Back to the top