SDMetrics home page
The Software Design Metrics tool for the UML

Parsing the XMI Extensions of Enterprise Architect

January 2, 2018, Jürgen Wüst. Category: Announcements,Tips & Tricks

SDMetrics 2.35 introduces a small extension to the XMI parser. Assume we need to access information such as the author or a documentation string from the XMI extension part of Enterprise Architect. This information is encoded as follows:

<uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">
 <packagedElement xmi:type="uml:Package" xmi:id="4A3564" name="test" visibility="public" />
<xmi:Extension extender="Enterprise Architect" extenderID="6.5">
    <element xmi:idref="4A3564" xmi:type="uml:Package" name="test" >
      <properties isSpecification="false" sType="Package" scope="public" 
          documentation="Something important about this package." />
      <project author="jw" version="1.0" created="2018-01-02 09:05:22" 
          modified="2018-01-02 09:07:34" complexity="1" status="Proposed"/>

The XMI extension part contains an <element>-tag with an XMI idref attribute that identifies the extended element, and some sub-tags with attributes for documentation and author. This should be a simple task for SDMetrics: just add an “EA Extension element” to SDMetrics’ meta-model and write the appropriate XMI transformation, maybe like so:

<!-- new meta-model element -->
<modelelement name="eaextensionelement">
  <attribute name="eaextelemref" type="ref" />
  <attribute name="documentation" type="data" />
  <attribute name="author" type="data" />

<!-- XMI transformation for the new meta-model element -->
<xmitransformation modelelement="eaextensionelement" xmipattern="element" 
    requirexmiid="false" condition="geometry=''">
  <trigger name="eaextelemref" type="attrval" attr="xmi:idref" />
  <trigger name="name" type="attrval" attr="name" />
  <trigger name="documentation" type="cattrval" attr="documentation" src="properties" />
  <trigger name="author" type="cattrval" attr="author" src="project" />

Because the <element>-tag has no XMI ID, we need to set the requirexmiid attribute of the XMI transformation to false. We also add a condition geometry=” (the element must have no or an empty geometry attribute), because Enterprise Architect also uses <element>-tags to store diagram information and we don’t want to pick these up here.

However, when we add the above definitions to SDMetrics’ project files, nothing happens! The XMI parser does not recognise the new model element. This is because the following rule is hardcoded in the XMI parser: an XML tag in the input XMI file that has no XMI ID but does have an XMI idref attribute cannot trigger the creation of a new model element. The origin of this rule goes back to the days of XMI 1.0 and XMI 1.1, where element cross-references were serialized like this:

<UML:Generalization = '889' isSpecification = 'false'>
    <UML:Class xmi.idref = '888'/>
    <UML:Class xmi.idref = '866'/>

Without the hardcoded “idref rule”, lines such as the ones shown in boldface would trigger the creation of new, empty elements, which would mess up the measurement results.

Now we know that the <element>-tag is not recognized because it contains an XMI idref attribute, and there is no other workaround for this problem. Obviously, this situation needs to be remedied. SDMetrics 2.35 therefore introduces a new attribute allowxmiidref for XMI transformations to bypass the “idref rule” if needed:

<xmitransformation modelelement="eaextensionelement" xmipattern="element" 
    requirexmiid="false" allowxmiidref="true" condition="geometry=''">
  ... remainder of the triggers as above.

When we add this new attribute to our definition, SDMetrics 2.35 picks up the <element>-tag as expected. We can now go ahead and define custom metrics that use information from the Enterprise Architect extension part:

<metric name="EAAuthor" domain="package">
  <description>Author of the package.</description>
  <filtervalue relation="eaextelemref" target="eaextensionelement" 

<metric name="EADocumentation" domain="package">
  <description>Documentation for the package.</description>
  <filtervalue relation="eaextelemref" target="eaextensionelement" 

This will add two more columns to the metric view for packages, showing the author and documentation string for each package.