Contents > 7 SDMetrics Metamodel and XMI Transformation Files > 7.1 SDMetrics Metamodel

7.1 SDMetrics Metamodel

The SDMetrics metamodel defines which UML model elements types (e.g., classes, packages, associations, and so on) SDMetrics knows about, and what information is stored with each UML model element. This information provides the basis for the definition and calculation of design metrics.

The SDMetrics metamodel is defined in an XML file of the following structure (for a formal definition, see Appendix E: "Project File Format Definitions"):

<sdmetricsmetamodel version="2.0" >
  <modelelement name="element1">
    <attribute name="attr1" type="data" multiplicity="one" />
    <attribute name="attr2" type="ref" multiplicity="many" />
    ..
  </modelelement>
  <modelelement name="element2" parent="element1">
    <attribute name="attr3" type="extref" multiplicity="one" />
     ...
  </modelelement>
  ...
</sdmetricsmetamodel>
The metamodel definition file is a list of metamodel element definitions enclosed in <sdmetricsmetamodel> tags. The attribute "version" indicates the version number of the oldest version of SDMetrics with which the file can be used.

A metamodel element definition is enclosed in <modelelement> tags. The required attribute name specifies the name of the metamodel element (e.g., class, operation etc). The optional attribute parent specifies a parent metamodel element; the inheritance mechanism will be explained at the end of the section. Stored with each metamodel element is a set of metamodel attributes representing data fields and cross-references to other model elements. These are specified in a list of <attribute> definitions. We distinguish data attributes, cross-reference attributes, and extension references.

We also distinguish single-valued and multi-valued attributes: An <attribute> definition has three XML attributes: For example, the definition of the metamodel element "operation" is as follows:
<modelelement name="operation">
  <attribute name="id" />
  <attribute name="name" />
  <attribute name="context" type="ref" />
  <attribute name="visibility" />
</modelelement>
An operation has four single-valued attributes: data attributes id, name, and visibility, and cross-reference attribute context. In the example, the meaning of the attributes is as follows: These attribute meanings are not expressed in the metamodel definition. It is the job of an XMI transformation file (see Section 7.2 "XMI Transformation Files") to retrieve the intended information for each model element and attribute from an XMI file.

Note that extension reference attributes must be single-valued. A metamodel element can have at most one extension reference attribute.

Metamodel inheritance

To simplify the specification of metamodels, a metamodel element may inherit the attributes of another metamodel element. The parent metamodel element is specified via the parent attribute in the metamodel element definition:

<modelelement name="element2" parent="element1">
     <!-- additional attributes of element2 (optional) -->
</modelelement>
In the example, an instance of model element "element2" has all attributes of "element1", and possibly additional attributes.

By default, all metamodel elements inherit from a special metamodel element named sdmetricsbase, which must be defined explicitly in every metamodel definition file. In the default metamodel that is shipped with SDMetrics, the sdmetricsbase element defines the attributes "id", "name", and "context" which all elements must possess. See Appendix A: "Metamodels" for a list of all metamodel elements and a description of their attributes.

Note that parent model elements must be defined before any of their child elements in the metamodel definition file. Consequently, the "sdmetricsbase" model element must be the first one defined in the file.

If the parent model element defines an extension reference attribute, the child model elements inherit the extension reference and therefore cannot define new extension references of their own.