我练习使用ATL,所以我尝试进行非常简单的模型转换,如下所示。
ATL:
module Form2NewForm;
create OUT : Form refining IN : Form;
-- @path Form=/Form2Form/Form.ecore
--parameter
helper def : subjectName : String = 'address';
helper def : newHeight : Integer = 500;
helper def : newWidth : Integer = 300;
helper context Form!ScreenItem def : isSbj() : Boolean =
if self.itemName = thisModule.subjectName
then true else false endif;
rule NewScreem{
from
s : Form!Screen
to
t : Form!Screen(
height <- thisModule.newHeight,
width <- thisModule.newWidth
)
}
--new three class are created below "address" class
rule Refinement{
from
s : Form!ScreenItem(s.isSbj())
to
t : Form!ScreenItem(
--
),
t1 : Form!SubScreenItem(
itemName <- 'City',
height <- s.height,
width <- (s.width-20) div 3,
x <- s.x - (s.width div 2) + (s.width-20) div 6,
y <- s.y
),
t2 : Form!SubScreenItem(
itemName <- 'Prefecture',
height <- s.height,
width <- (s.width-20) div 3,
x <- s.x,
y <- s.y
),
t3 : Form!SubScreenItem(
itemName <- 'Number',
height <- s.height,
width <- (s.width-20) div 3,
x <- s.x + (s.width div 2) - (s.width-20) div 6,
y <- s.y
)
}
输入模型:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="http://form/1.0">
<Screen height="250" width="600">
<screenItem itemName="lastName" width="200" height="30" x="150" y="65"/>
<screenItem itemName="firstName" width="200" height="30" x="450" y="65"/>
<screenItem itemName="address" width="500" height="30" x="300" y="145"/>
</Screen>
</xmi:XMI>
我想从输入模型和ATL获得这个预期的模型。
预期模式:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:Form="http://form/1.0">
<Form:Screen height="500" width="300">
<screenItem itemName="lastName" height="30" width="200" x="150" y="65"/>
<screenItem itemName="firstName" height="30" width="200" x="450" y="65"/>
<screenItem itemName="address" height="30" width="500" x="300" y="145">
<children itemName="City" height="30" width="160" x="130" y="145"/>
<children itemName="Prefecture" height="30" width="160" x="300" y="145"/>
<children itemName="Number" height="30" width="160" x="470" y="145"/>
</screenItem>
</Form:Screen>
</xmi:XMI>
但实际上这个下面的模型已经创建了。
输出模型:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:Form="http://form/1.0">
<Form:Screen height="500" width="300">
<screenItem itemName="lastName" height="30" width="200" x="150" y="65"/>
<screenItem itemName="firstName" height="30" width="200" x="450" y="65"/>
<screenItem itemName="address" height="30" width="500" x="300" y="145"/>
</Form:Screen>
<Form:SubScreenItem itemName="City" height="30" width="160" x="130" y="145"/>
<Form:SubScreenItem itemName="Prefecture" height="30" width="160" x="300" y="145"/>
<Form:SubScreenItem itemName="Number" height="30" width="160" x="470" y="145"/>
</xmi:XMI>
在这个转换中,我想创建一个新的类,其itemName是&#34; City&#34;,&#34; Prefecture&#34;和&#34;数字&#34;作为&#34;地址&#34;的孩子类似预期的模型。 但实际上这三个班级并没有定位为“#34;类。
我认为&#34;地址&#34;之间的关系class和这三个类应该用t:Form!ScreenItem(...)写成规则细化,但是我不能写出怎么写。
请告诉我如何编写可以创建预期模型的ATL代码。
Form.ecore:
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI 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">
<ecore:EPackage name="Form" nsURI="http://form/1.0" nsPrefix="Form">
<eClassifiers xsi:type="ecore:EClass" name="Screen">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="height" lowerBound="1"
eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="width" lowerBound="1"
eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="screenItem" upperBound="-1"
eType="#/0/ScreenItem" containment="true" eOpposite="#/0/ScreenItem/screen"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ScreenItem">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="itemName" eType="#/1/String"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="height" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="width" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="screen" lowerBound="1"
eType="#/0/Screen" changeable="false" eOpposite="#/0/Screen/screenItem"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="x" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="y" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#/0/SubScreenItem" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="SubScreenItem">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="itemName" eType="#/1/String"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="height" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="width" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="x" eType="#/1/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="y" eType="#/1/Integer"/>
</eClassifiers>
</ecore:EPackage>
<ecore:EPackage name="PrimitiveTypes">
<eClassifiers xsi:type="ecore:EDataType" name="String"/>
<eClassifiers xsi:type="ecore:EDataType" name="Integer"/>
<eClassifiers xsi:type="ecore:EDataType" name="Boolean"/>
</ecore:EPackage>
</xmi:XMI>
答案 0 :(得分:0)
你必须添加:
t:Form!ScreenItem(
children <- t1,
children <- t2,
children <- t3
)
此致
伊莎贝尔