Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » Enumeration data type
Enumeration data type [message #41057] Wed, 23 May 2007 16:01 Go to next message
Kelly  arcés is currently offline Kelly arcésFriend
Messages: 22
Registered: July 2009
Junior Member
Hello,

I have a transformation where source and target model are the same
(Business metamodel). I wrote this rule:

1 rule element2element{
2 from
3 e : business!Element
4 to
5 ef : business!Element(
6 operation <- Sequence{ots}),
7 ots: business!Operation(
8 name<-'toString',
9 parameter<-Sequence{p}),
10 p : business!Parameter(
11 direction<-#return,
12 type<-#string
13 )
14 }

I get a model where (meta)attribute 'direction' of (meta)class
'Parameter' is missing (see lines 10-13), but (meta)attribute 'type' is ok.

'type' and 'direction' are Enumeration data types. Why does not it work?

Thanks in advance.
Re: [ATL] Enumeration data type [message #41148 is a reply to message #41057] Wed, 23 May 2007 19:24 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,

Can you please remember to prefix the subject of your ATL-related posts
with [ATL] as I just did in this reply? Thanks.


> I have a transformation where source and target model are the same
> (Business metamodel). I wrote this rule:
>
> 1 rule element2element{
> 2 from
> 3 e : business!Element
> 4 to
> 5 ef : business!Element(
> 6 operation <- Sequence{ots}),
> 7 ots: business!Operation(
> 8 name<-'toString',
> 9 parameter<-Sequence{p}),
> 10 p : business!Parameter(
> 11 direction<-#return,
> 12 type<-#string
> 13 )
> 14 }
>
> I get a model where (meta)attribute 'direction' of (meta)class
> 'Parameter' is missing (see lines 10-13), but (meta)attribute 'type'
is ok.
>
> 'type' and 'direction' are Enumeration data types. Why does not it work?


I will assume that by "missing" you mean it is not serialized in the
resulting XMI file. If you mean that it is *really* not assigned to the
property, then please disregard my comments below and ask your question
again :-).


I suppose that #return is the first value of its enumeration (i.e., the
default one), or that it is the default value of the direction
attribute. When this is the case, EMF does not serialize the attribute
to XMI, because it is not necessary.

We already had many questions about this kind of stuff (especially on
the old ATL mailing list). My advice was, and still is: do not infer
that your transformation does not work just because you do not
understand XMI, which I must admit is sometimes confusing ;-).

One way to check if your model is correct is to open it with the EMF
reflective editor. Note that you may need to register your metamodel
first for the editor to find it and work properly.


Best regards,

Frédéric Jouault
Re: [ATL] Enumeration data type [message #41452 is a reply to message #41148] Thu, 24 May 2007 14:42 Go to previous messageGo to next message
Kelly  arcés is currently offline Kelly arcésFriend
Messages: 22
Registered: July 2009
Junior Member
Dear Fréderic,

Thanks for your help, model is ok. I have other question.
Transformation has in (A) and out (B) metamodel. Both are different, but
they have similar enumerations:

*** A metamodel ***

Enumeration DataType
int = 0
string = 1
...

*** B metamodel ***

Enumeration JavaType
JInteger = 0
JString = 1
...

I wrote this rule

rule parameter2parameter
{
from
pb : business!Parameter
to
pj : java!Parameter(
type <- thisModule.getJavaType(pb.type)
)
}

getJavaType is a helper wich put correct JavaType according DataType:

helper def : getJavaType(dt : business!DataType) : java!JavaType =
if dt = #string
then #JString
...
else #JInteger
endif;

I don't like it because there are too IF. Is it possible iterate
enumerations by finding correct literal? or Could you give me any advice
for improving this.

Thanks in advance.




Frédéric Jouault a écrit :
> Hello,
>
> Can you please remember to prefix the subject of your ATL-related posts
> with [ATL] as I just did in this reply? Thanks.
>
>
> > I have a transformation where source and target model are the same
> > (Business metamodel). I wrote this rule:
> >
> > 1 rule element2element{
> > 2 from
> > 3 e : business!Element
> > 4 to
> > 5 ef : business!Element(
> > 6 operation <- Sequence{ots}),
> > 7 ots: business!Operation(
> > 8 name<-'toString',
> > 9 parameter<-Sequence{p}),
> > 10 p : business!Parameter(
> > 11 direction<-#return,
> > 12 type<-#string
> > 13 )
> > 14 }
> >
> > I get a model where (meta)attribute 'direction' of (meta)class
> > 'Parameter' is missing (see lines 10-13), but (meta)attribute 'type'
> is ok.
> >
> > 'type' and 'direction' are Enumeration data types. Why does not it work?
>
>
> I will assume that by "missing" you mean it is not serialized in the
> resulting XMI file. If you mean that it is *really* not assigned to the
> property, then please disregard my comments below and ask your question
> again :-).
>
>
> I suppose that #return is the first value of its enumeration (i.e., the
> default one), or that it is the default value of the direction
> attribute. When this is the case, EMF does not serialize the attribute
> to XMI, because it is not necessary.
>
> We already had many questions about this kind of stuff (especially on
> the old ATL mailing list). My advice was, and still is: do not infer
> that your transformation does not work just because you do not
> understand XMI, which I must admit is sometimes confusing ;-).
>
> One way to check if your model is correct is to open it with the EMF
> reflective editor. Note that you may need to register your metamodel
> first for the editor to find it and work properly.
>
>
> Best regards,
>
> Frédéric Jouault
Re: [ATL] Enumeration data type [message #41513 is a reply to message #41452] Thu, 24 May 2007 15:09 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hi,

> Thanks for your help, model is ok. I have other question.

You are welcome.

> Transformation has in (A) and out (B) metamodel. Both are different, but
> they have similar enumerations:
>
> *** A metamodel ***
>
> Enumeration DataType
> int = 0
> string = 1
> ...
>
> *** B metamodel ***
>
> Enumeration JavaType
> JInteger = 0
> JString = 1
> ...
>
> I wrote this rule
>
> rule parameter2parameter
> {
> from
> pb : business!Parameter
> to
> pj : java!Parameter(
> type <- thisModule.getJavaType(pb.type)
> )
> }
>
> getJavaType is a helper wich put correct JavaType according DataType:
>
> helper def : getJavaType(dt : business!DataType) : java!JavaType =
> if dt = #string
> then #JString
> ...
> else #JInteger
> endif;
>
> I don't like it because there are too IF. Is it possible iterate
> enumerations by finding correct literal? or Could you give me any advice
> for improving this.

What about this?

helper def: javaTypes : Sequence(java!JavaType) =
Sequence {#JString, #JInteger, ...};

helper def: businessTypes : Sequence(business!DataType) =
Sequence {#string, #int, ...};

helper def : getJavaType(dt : business!DataType) : java!JavaType =
thisModule.javaTypes->at(thisModule.businessTypes->indexOf(dt));

You may put the javaTypes and businessTypes helper as let expressions in
the getJavaType helper, but I believe the version I suggest will be faster.




Or even better:

helper def: typesMap : Map(business!DataType, java!JavaType) =
Map {(#string, #JString), (#int, #JInteger), ...);

helper def : getJavaType(dt : business!DataType) : java!JavaType =
thisModule.typesMap.get(dt);

This second solution does not rely on two sequences having the same
order, plus it uses a Map, which is even faster ;-).



I only thought about the second solution after having written the first
one, and I did not feel like deleting all that stuff. Therefore, you get
two answers for the price of one (which is free anyway!) ;-).


Best regards,

Frédéric Jouault
Previous Topic:[ATL] using generated ecore files for GMF
Next Topic:ATL :
Goto Forum:
  


Current Time: Thu Jan 21 05:20:09 GMT 2021

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

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

Back to the top