我目前正在开发一个项目,需要使用qvto将一个模型转换为另一个模型。源模型是以表格形式表示的状态机。目标模型也是具有节点和边缘的状态机。源模型只有域元模型,但目标模型同时具有域和符号元模型。符号元模型是http://www.eclipse.org/gmf/runtime/1.0.2/notation。我从源域模型转换为目标域模型,但我的目标模型没有符号模型。我想要做的是从目标模型生成符号模型并将其序列化为相同的xmi文件。我阅读了EMF和GMF的文档,并试图这样做,但我无法做到。我也用谷歌搜索,这也没有帮助。目标模型的标题提到域和符号元模型。为清楚起见,请查看下面的xmi文件。
<?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:n1="http://www.target.com/EMF/1/SimpleStatechart" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation">
<n1:statemachine xmi:id="_QvItUPMjEeS6mNxtIz5_4Q" s_name="Sensor">
<transitions xmi:type="n1:Transition" xmi:id="_RzqFYPMjEeS6mNxtIz5_4Q" body="" from="_RNakwPMjEeS6mNxtIz5_4Q" to="_RzcqAPMjEeS6mNxtIz5_4Q"/>
<transitions xmi:type="n1:Transition" xmi:id="_BJd-wAeuEeaf_-AtraPkfA" body="in_ISensor:Activate/out_ISensor.send(sensorReply());" from="_RzcqAPMjEeS6mNxtIz5_4Q" to="_7UnrQAetEeaf_-AtraPkfA"/>
<transitions xmi:type="n1:Transition" xmi:id="_DaWcQAeuEeaf_-AtraPkfA" body="in_InternalOptional:DetectedMovement/out_ISensor_NI.send(detectedMovement());" from="_7UnrQAetEeaf_-AtraPkfA" to="_7Q_IcAetEeaf_-AtraPkfA"/>
<transitions xmi:type="n1:Transition" xmi:id="_EWLLUAeuEeaf_-AtraPkfA" body="in_ISensor:Deactivate/out_ISensor.send(sensorReply());" from="_7UnrQAetEeaf_-AtraPkfA" to="_7OB7EAetEeaf_-AtraPkfA"/>
<transitions xmi:type="n1:Transition" xmi:id="_F9AmQAeuEeaf_-AtraPkfA" body="in_ISensor:Deactivate/out_ISensor.send(sensorReply());" from="_7Q_IcAetEeaf_-AtraPkfA" to="_7OB7EAetEeaf_-AtraPkfA"/>
<transitions xmi:type="n1:Transition" xmi:id="_GXe7wAeuEeaf_-AtraPkfA" body="in_InternalInevitable:Deactivated/
out_ISensor_NI.send(deactivated());" from="_7OB7EAetEeaf_-AtraPkfA" to="_RzcqAPMjEeS6mNxtIz5_4Q"/>
<states xmi:type="n1:InitialState" xmi:id="_RNakwPMjEeS6mNxtIz5_4Q" name="InitialState"/>
<states xmi:type="n1:BasicState" xmi:id="_RzcqAPMjEeS6mNxtIz5_4Q" name="Deactivated"/>
<states xmi:type="n1:BasicState" xmi:id="_7OB7EAetEeaf_-AtraPkfA" name="Deactivating" internal=""/>
<states xmi:type="n1:BasicState" xmi:id="_7Q_IcAetEeaf_-AtraPkfA" name="Triggered"/>
<states xmi:type="n1:BasicState" xmi:id="_7UnrQAetEeaf_-AtraPkfA" name="Activated"/>
</n1:statemachine>
<notation:Diagram xmi:id="_QvItUfMjEeS6mNxtIz5_4Q" type="ConformiqStateChart" element="_QvItUPMjEeS6mNxtIz5_4Q" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_RNwjAPMjEeS6mNxtIz5_4Q" type="2007" element="_RNakwPMjEeS6mNxtIz5_4Q">
<children xmi:type="notation:DecorationNode" xmi:id="_RNxKEPMjEeS6mNxtIz5_4Q" type="5022"/>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_RNwjAfMjEeS6mNxtIz5_4Q"/>
<styles xmi:type="notation:FontStyle" xmi:id="_YRV_NegaEeSg-pTEoxDT6g" fontName="Segoe UI"/>
<styles xmi:type="notation:LineStyle" xmi:id="_RNwjA_MjEeS6mNxtIz5_4Q" lineColor="0"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_YRWmQegaEeSg-pTEoxDT6g" x="496" y="57"/>
</children>
<children xmi:type="notation:Node" xmi:id="_RzhigPMjEeS6mNxtIz5_4Q" type="2012" element="_RzcqAPMjEeS6mNxtIz5_4Q">
<children xmi:type="notation:DecorationNode" xmi:id="_RziJkvMjEeS6mNxtIz5_4Q" type="5017"/>
<children xmi:type="notation:DecorationNode" xmi:id="_RziJk_MjEeS6mNxtIz5_4Q" type="5018"/>
<children xmi:type="notation:DecorationNode" xmi:id="_RziJlPMjEeS6mNxtIz5_4Q" type="5019"/>
<children xmi:type="notation:DecorationNode" xmi:id="_RziwoPMjEeS6mNxtIz5_4Q" type="7001">
<styles xmi:type="notation:SortingStyle" xmi:id="_RziwofMjEeS6mNxtIz5_4Q"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_RziwovMjEeS6mNxtIz5_4Q"/>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_RzhigfMjEeS6mNxtIz5_4Q"/>
<styles xmi:type="notation:FontStyle" xmi:id="_YRXNUOgaEeSg-pTEoxDT6g" fontName="Segoe UI"/>
<styles xmi:type="notation:HintedDiagramLinkStyle" xmi:id="_RziJkPMjEeS6mNxtIz5_4Q"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_YRXNUugaEeSg-pTEoxDT6g" x="420" y="192" width="225" height="109"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_TAN_IPMjEeS6mNxtIz5_4Q" type="Note" fontName="Ubuntu" fontHeight="11" description="Describe the behavior of the
Sensor in this state machine." fillColor="0" transparency="0" lineColor="0" lineWidth="1">
<children xmi:type="notation:BasicDecorationNode" xmi:id="_TARCcPMjEeS6mNxtIz5_4Q" type="DiagramName">
<element xsi:nil="true"/>
</children>
<children xmi:type="notation:BasicDecorationNode" xmi:id="_TARpgPMjEeS6mNxtIz5_4Q" type="Description">
<element xsi:nil="true"/>
</children>
<styles xmi:type="notation:TextStyle" xmi:id="_TAN_IfMjEeS6mNxtIz5_4Q"/>
<styles xmi:type="notation:LineTypeStyle" xmi:id="_TAOmMPMjEeS6mNxtIz5_4Q"/>
<element xsi:nil="true"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_YRYbcOgaEeSg-pTEoxDT6g" x="708" y="36" width="293" height="98"/>
</children>
<children xmi:type="notation:Node" xmi:id="_7OMTIAetEeaf_-AtraPkfA" type="2012" element="_7OB7EAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_7OOIUAetEeaf_-AtraPkfA" type="5017"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7OOIUQetEeaf_-AtraPkfA" type="5018"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7OOIUgetEeaf_-AtraPkfA" type="5019"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7OOIUwetEeaf_-AtraPkfA" type="7001">
<styles xmi:type="notation:SortingStyle" xmi:id="_7OOIVAetEeaf_-AtraPkfA"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_7OOIVQetEeaf_-AtraPkfA"/>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_7OMTIQetEeaf_-AtraPkfA"/>
<styles xmi:type="notation:FontStyle" xmi:id="_7OMTIgetEeaf_-AtraPkfA" fontName="Segoe UI"/>
<styles xmi:type="notation:HintedDiagramLinkStyle" xmi:id="_7OMTIwetEeaf_-AtraPkfA"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_7OMTJAetEeaf_-AtraPkfA" x="552" y="756" width="225" height="109"/>
</children>
<children xmi:type="notation:Node" xmi:id="_7RAWkAetEeaf_-AtraPkfA" type="2012" element="_7Q_IcAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_7RA9oAetEeaf_-AtraPkfA" type="5017"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7RA9oQetEeaf_-AtraPkfA" type="5018"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7RA9ogetEeaf_-AtraPkfA" type="5019"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7RA9owetEeaf_-AtraPkfA" type="7001">
<styles xmi:type="notation:SortingStyle" xmi:id="_7RA9pAetEeaf_-AtraPkfA"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_7RA9pQetEeaf_-AtraPkfA"/>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_7RAWkQetEeaf_-AtraPkfA"/>
<styles xmi:type="notation:FontStyle" xmi:id="_7RAWkgetEeaf_-AtraPkfA" fontName="Segoe UI"/>
<styles xmi:type="notation:HintedDiagramLinkStyle" xmi:id="_7RAWkwetEeaf_-AtraPkfA"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_7RAWlAetEeaf_-AtraPkfA" x="324" y="588" width="225" height="109"/>
</children>
<children xmi:type="notation:Node" xmi:id="_7Uo5YAetEeaf_-AtraPkfA" type="2012" element="_7UnrQAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_7Uo5ZQetEeaf_-AtraPkfA" type="5017"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7UpgcAetEeaf_-AtraPkfA" type="5018"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7UpgcQetEeaf_-AtraPkfA" type="5019"/>
<children xmi:type="notation:DecorationNode" xmi:id="_7UpgcgetEeaf_-AtraPkfA" type="7001">
<styles xmi:type="notation:SortingStyle" xmi:id="_7UpgcwetEeaf_-AtraPkfA"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_7UpgdAetEeaf_-AtraPkfA"/>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_7Uo5YQetEeaf_-AtraPkfA"/>
<styles xmi:type="notation:FontStyle" xmi:id="_7Uo5YgetEeaf_-AtraPkfA" fontName="Segoe UI"/>
<styles xmi:type="notation:HintedDiagramLinkStyle" xmi:id="_7Uo5YwetEeaf_-AtraPkfA"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_7Uo5ZAetEeaf_-AtraPkfA" x="264" y="384" width="225" height="109"/>
</children>
<styles xmi:type="notation:DiagramStyle" xmi:id="_QvItUvMjEeS6mNxtIz5_4Q"/>
<edges xmi:type="notation:Edge" xmi:id="_Rzr6kPMjEeS6mNxtIz5_4Q" type="4002" element="_RzqFYPMjEeS6mNxtIz5_4Q" source="_RNwjAPMjEeS6mNxtIz5_4Q" target="_RzhigPMjEeS6mNxtIz5_4Q">
<children xmi:type="notation:DecorationNode" xmi:id="_RzshoPMjEeS6mNxtIz5_4Q" type="6002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_RzshofMjEeS6mNxtIz5_4Q" x="19" y="-12"/>
</children>
<styles xmi:type="notation:RoutingStyle" xmi:id="_X39ZA9krEeSNSYp_vqikKg" routing="Rectilinear"/>
<styles xmi:type="notation:FontStyle" xmi:id="_YRX0YugaEeSg-pTEoxDT6g" fontName="Segoe UI"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_YRX0Y-gaEeSg-pTEoxDT6g" points="[0, 0, 0, -94]$[0, 94, 0, 0]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_53a-Yfi3EeSDRc6--mGWrg" id="(0.48,1.0)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_YRX0ZOgaEeSg-pTEoxDT6g" id="(0.5,0.0)"/>
</edges>
<edges xmi:type="notation:Edge" xmi:id="_BJkFYAeuEeaf_-AtraPkfA" type="4002" element="_BJd-wAeuEeaf_-AtraPkfA" source="_RzhigPMjEeS6mNxtIz5_4Q" target="_7Uo5YAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_BJkscAeuEeaf_-AtraPkfA" type="6002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_BJkscQeuEeaf_-AtraPkfA" x="-3" y="24"/>
</children>
<styles xmi:type="notation:RoutingStyle" xmi:id="_BJkFYQeuEeaf_-AtraPkfA" routing="Rectilinear"/>
<styles xmi:type="notation:FontStyle" xmi:id="_BJkFYgeuEeaf_-AtraPkfA" fontName="Segoe UI"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_BJkFYweuEeaf_-AtraPkfA" points="[-39, 35, 117, -137]$[-159, 118, -3, -54]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_BJnIsAeuEeaf_-AtraPkfA" id="(0.17777777777777778,0.6788990825688074)"/>
</edges>
<edges xmi:type="notation:Edge" xmi:id="_DaXDUAeuEeaf_-AtraPkfA" type="4002" element="_DaWcQAeuEeaf_-AtraPkfA" source="_7Uo5YAetEeaf_-AtraPkfA" target="_7RAWkAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_DaXqYAeuEeaf_-AtraPkfA" type="6002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_DaXqYQeuEeaf_-AtraPkfA" x="29" y="6"/>
</children>
<styles xmi:type="notation:RoutingStyle" xmi:id="_DaXDUQeuEeaf_-AtraPkfA" routing="Rectilinear"/>
<styles xmi:type="notation:FontStyle" xmi:id="_DaXDUgeuEeaf_-AtraPkfA" fontName="Segoe UI"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_DaXDUweuEeaf_-AtraPkfA" points="[4, 22, 17, -161]$[65, 129, 78, -54]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_DaY4gAeuEeaf_-AtraPkfA" id="(0.5555555555555556,0.7981651376146789)"/>
</edges>
<edges xmi:type="notation:Edge" xmi:id="_EWLyYAeuEeaf_-AtraPkfA" type="4002" element="_EWLLUAeuEeaf_-AtraPkfA" source="_7Uo5YAetEeaf_-AtraPkfA" target="_7OMTIAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_EWLyZAeuEeaf_-AtraPkfA" type="6002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_EWLyZQeuEeaf_-AtraPkfA" y="40"/>
</children>
<styles xmi:type="notation:RoutingStyle" xmi:id="_EWLyYQeuEeaf_-AtraPkfA" routing="Rectilinear"/>
<styles xmi:type="notation:FontStyle" xmi:id="_EWLyYgeuEeaf_-AtraPkfA" fontName="Segoe UI"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_EWLyYweuEeaf_-AtraPkfA" points="[27, 27, -323, -315]$[335, 351, -15, 9]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_EWNnkAeuEeaf_-AtraPkfA" id="(0.10666666666666667,0.7522935779816514)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_EWOOoAeuEeaf_-AtraPkfA" id="(0.1688888888888889,0.9174311926605505)"/>
</edges>
<edges xmi:type="notation:Edge" xmi:id="_F9BNUAeuEeaf_-AtraPkfA" type="4002" element="_F9AmQAeuEeaf_-AtraPkfA" source="_7RAWkAetEeaf_-AtraPkfA" target="_7OMTIAetEeaf_-AtraPkfA">
<children xmi:type="notation:DecorationNode" xmi:id="_F9B0YAeuEeaf_-AtraPkfA" type="6002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_F9B0YQeuEeaf_-AtraPkfA" y="40"/>
</children>
<styles xmi:type="notation:RoutingStyle" xmi:id="_F9BNUQeuEeaf_-AtraPkfA" routing="Rectilinear"/>
<styles xmi:type="notation:FontStyle" xmi:id="_F9BNUgeuEeaf_-AtraPkfA" fontName="Segoe UI"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_F9BNUweuEeaf_-AtraPkfA" points="[54, 21, -125, -49]$[165, 67, -14, -3]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_F9DpkAeuEeaf_-AtraPkfA" id="(0.76,0.6605504587155964)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_F9DpkQeuEeaf_-AtraPkfA" id="(0.06222222222222222,0.3119266055045872)"/>
</edges>
<edges xmi:type="notation:Edge" xmi:id="_GXfi0AeuEeaf_-AtraPkfA" type="4002" element="_GXe7wAeuEeaf_-AtraPkfA" source="_7OMTIAetEeaf_-AtraPkfA" target="_RzhigPMjEeS6mNxtIz5_4Q">
<children xmi:type="notation:DecorationNode" xmi:id="_GXfi1AeuEeaf_-AtraPkfA" type="6002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_GXfi1QeuEeaf_-AtraPkfA" y="40"/>
</children>
<styles xmi:type="notation:RoutingStyle" xmi:id="_GXfi0QeuEeaf_-AtraPkfA" routing="Rectilinear"/>
<styles xmi:type="notation:FontStyle" xmi:id="_GXfi0geuEeaf_-AtraPkfA" fontName="Segoe UI"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_GXfi0weuEeaf_-AtraPkfA" points="[-10, -54, 76, 427]$[-74, -461, 12, 20]"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_GXhYAAeuEeaf_-AtraPkfA" id="(0.5955555555555555,0.8165137614678899)"/>
</edges>
</notation:Diagram>
</xmi:XMI>
&#13;
从转换开始,我有目标模型的顶部,直到n1:statemachine,这是域模型。从n1:statemachine,在病房上方的图形表示继续我想要生成。 如何为模型转换得到的域模型生成符号模型?
答案 0 :(得分:0)
我不熟悉QVT的EMF资源处理,但我尽力描述在EMF和GMF级别需要做什么。
从技术上讲,符号模型是与您已成功生成的域模型相同的EMF模型,只是它符合另一个名为http://www.eclipse.org/gmf/runtime/1.0.2/notation
的元模型,可从相应的GMF插件org.eclipse.gmf.runtime.notation
获得
您必须让您的转换知道此元模型,然后您可以生成与原始模型类似的实例。转换需要根据符号模型的定义将符号模型与目标域模型元素连接起来;但这是处理域模型已经支持的相同类型的交叉引用。
最后,为了让目标和符号模型序列化到同一个xmi文件中,您必须将两者都添加到同一个EMF资源中,具体如下:
EObject targetDomain = ...; //root element of the target domain model
EObject targetNotation = ...; //root element of the target notation model
EList<EObject> contents = targetResource.getContents();
contents.add(targetDomain);
contents.add(targetNotation);
这些步骤应该允许您相应地生成符号模型。