Home » Archived » M2M (model-to-model transformation) » Enumeration data type
Enumeration data type [message #41057] |
Wed, 23 May 2007 12:01  |
Eclipse User |
|
|
|
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 15:24   |
Eclipse User |
|
|
|
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 10:42   |
Eclipse User |
|
|
|
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 11:09  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Fri Apr 25 05:21:13 EDT 2025
Powered by FUDForum. Page generated in 0.03620 seconds
|