[ATL] How to get the elements and put them in a target element [message #536471] |
Fri, 28 May 2010 12:15 |
ayoub Messages: 25 Registered: March 2010 |
Junior Member |
|
|
Hi all,
I have the following problem:
My source metamodel named MMS has 2 classes named ObjPere and ObjFils respectively without relationship like this:
MMS: <objPere name="1"> </objPere>
<objFils name="21" type="a"> </objFils>
<objFils name="22" type="b"> </objFils>
My target metamodel named MMT has 2 classes (father and child) with composition relationship like this:
MMT: <father name="..">
<children>
<child name="..." type="a"> </child>
<child name="..." type="b"> </child>
.....
.....
</children>
</father>
children is the name of relationship (composition) between father and child, note that father contain 0 or * child.
I want make the following transformation:
1- MMT!father.name = MMS!objPere.name
2- MMT!children = List of MMT!child where child.name = MMS!objFils.name and child.type = MMS!objFils.type
Note I want also regroup the child elements into element children in a result transformation conforming to MMT metamodel.
Thanks for your help,
forgive my poor english
[Updated on: Fri, 28 May 2010 19:22] Report message to a moderator
|
|
|
|
Re: [ATL] How to get the elements and put them in a target element [message #536977 is a reply to message #536966] |
Mon, 31 May 2010 18:38 |
ayoub Messages: 25 Registered: March 2010 |
Junior Member |
|
|
hi wafaa,
thank's for your interest!
I don't know how can I share the metamodel's file, but I try to copy the code.
1-the mms metamode is:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mms">
<eClassifiers xsi:type="ecore:EClass" name="objPere">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="objFils">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>
2- the mmt metamode is:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mmt">
<eClassifiers xsi:type="ecore:EClass" name="father">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//child" containment="true" eOpposite="#//child/father"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="child">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="father" eType="#//father"
eOpposite="#//father/children"/>
</eClassifiers>
</ecore:EPackage>
---- children is the name of relationship (composition) between father and child, note that father contain 0 or * child.
3-the input file that is conforming to the mms metamodel is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mms">
<objPere name="root"> </objPere>
<objFils name="001" type="a"> </objFils>
<objFils name="001" type="a"> </objFils>
<objFils name="010" type="b"> </objFils>
<objFils name="011" type="a"> </objFils>
<objFils name="100" type="c"> </objFils>
<objFils name="101" type="a"> </objFils>
<objFils name="110" type="d"> </objFils>
</xmi:XMI>
I want make the following transformation:
a- MMT!father.name = MMS!objPere.name
b- MMT!children = List of MMT!child where child.name = MMS!objFils.name and child.type = MMS!objFils.type and MMS!objFils.type ='a'
And regroup the child elements into element children in a result transformation conforming to MMT metamodel.
For this I wrote the following transformation:
4- the ATL transformation:
module mms2mmt;
create OUT: mmt from IN: mms;
rule mms2mmt {
from s : mms!objPere
to t : mmt!father (
name <- s.name,
children <- mms!objFils.allInstances()->collect(e| thisModule.fils2child(e))
->select(c| c.type='a')
)
}
lazy rule fils2child{
from s : mms!objFils(s.isA())
to t : mmt!child(
name <- s.name,
type <- s.type
)
}
helper context mms!objFils def: isA() : Boolean =
if self.type = 'a' then
true
else
false
endif;
but the result is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children name="001" type="a"/>
<children name="001" type="a"/>
<children name="011" type="a"/>
<children name="101" type="a"/>
</father>
<child name="010" type="b"/>
<child name="100" type="c"/>
<child name="110" type="d"/>
</xmi:XMI>
And I want have a result like this:
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children>
<child name="001" type="a"/>
<child name="001" type="a"/>
<child name="011" type="a"/>
<child name="101" type="a"/>
</children>
</father>
</xmi:XMI>
Thnak's
[Updated on: Mon, 31 May 2010 18:40] Report message to a moderator
|
|
|
Re: [ATL] How to get the elements and put them in a target element [message #537108 is a reply to message #536977] |
Tue, 01 June 2010 11:14 |
ayoub Messages: 25 Registered: March 2010 |
Junior Member |
|
|
Hi wafaa and all people who want to join us!
I wrote the following transformation but I still have the problem to regroup elements "child" within children's "element":
rule mms2mmt {
from s : mms!objPere
to t : mmt!father (
name <- s.name,
children<-mms!objFils.allInstances()->iterate(e; res: Set(mms!objFils) =Set{} |
if(res->collect(f| f.name)->includes(e.name)) then
res
else
res->including(e)
endif
)->select(c| c.type='a')->flatten()->asOrderedSet()
->collect(e| thisModule.fils2child(e))
)
}
lazy rule fils2child{
from s : mms!objFils
to t : mmt!child(
name <- s.name,
type <- s.type
)
}
the result of this transformation is:
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children name="001" type="a"/>
<children name="011" type="a"/>
<children name="101" type="a"/>
</father>
</xmi:XMI>
but I want a result like this:
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children>
<child name="001" type="a"/>
<child name="011" type="a"/>
<child name="101" type="a"/>
</children>
</father>
</xmi:XMI>
It's possible with this metamodel?
[Updated on: Tue, 01 June 2010 16:09] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03436 seconds