I may have mentioned it before on this blog, but UML model interchange via XMI is difficult in practice. In this post we’ll look at a case study how to adapt SDMetrics’ XMI import to the idiosyncrasies of a modeling tool.
For this case study, I used the open source UML tool Modelio 2.1.0, with the SysML Architect module 2.1.4. Both are freely available from www.modelio.org. I created a small SysML model in Modelio, with a SysML block and some flow ports on it. I then exported the model to XMI, using the export options “OMG UML 2.3” and “with Modelio annotations”. Analyzing the XMI file with SDMetrics 2.3 and the new project files for SysML, I noticed that SDMetrics did not import the flow ports – block metrics “AtomicFlowPorts” and “NonAtomicFlowports” were both zero.
SysML 1.2 defines flow ports as a stereotype “FlowPort” that extends UML ports and adds an attribute “direction” of enumeration type “FlowDirection”. A standard-compliant XMI serialization of a flow port with direction “inout” looks like this:
<sysml:FlowPort xmi:id="..." base_Port="..." direction="inout"/>
Here’s an excerpt of the XMI file generated by Modelio. I truncated the XMI IDs for readability:
... <sysml:FlowPort_InOut xmi:id="c4Tyn" base_Port="UYfiX" FlowPort_direction="inout"/> ...
Modelio’s SysML profile defines a stereotype “FlowPort_InOut”, with an – apparently redundant – attribute “FlowPort_direction”. This explains why the flow ports were not properly imported. I cannot rule out that I did something wrong creating the model or the XMI file in Modelio, but for now let’s assume we’re stuck with what we have.
To account for Modelio’s modeling of flow ports, I opened SDMetrics’ XMI transformation file “xmiTrans_sysml.xml” for SysML in a text editor, and added this definition:
<xmitransformation modelelement="flowport" xmipattern="sysml:FlowPort_InOut"> <trigger name="base" type="attrval" attr="base_Port" /> <trigger name="direction" type="constant" attr="inout" /> </xmitransformation>
This instructs SDMetrics to recognize XML elements “sysml:FlowPort_InOut” in the XMI file as flow ports with direction “inout”. Flow ports with direction “in” or “out” are dealt with in the same manner:
<xmitransformation modelelement="flowport" xmipattern="sysml:FlowPort_In"> <trigger name="base" type="attrval" attr="base_Port" /> <trigger name="direction" type="constant" attr="in" /> </xmitransformation> <xmitransformation modelelement="flowport" xmipattern="sysml:FlowPort_Out"> <trigger name="base" type="attrval" attr="base_Port" /> <trigger name="direction" type="constant" attr="out" /> </xmitransformation>
Rerunning the analysis with the modified XMI transformation file, the flow ports were now properly extracted from the XMI file. Well, that wasn’t so difficult after all. A text editor and a few lines of XML code did the trick.