SDMetrics – Not For UML Models Only

SDMetrics advertizes itself as “The Software Design Metrics tool for the UML”. SDMetrics has a flexible XMI parser to import UML models, as XMI is the most common UML model interchange format. But XMI is not limited to UML model interchange. It can be used to serialize any MOF-based models to XML. Therefore, SDMetrics too is actually not restricted to analyzing UML models. With its customizable XMI import and user-definable metrics, we can use SDMetrics to measure structural properties for any MOF-based models. That’s what we’ll do in this post. All we’ll need is SDMetrics (the Demo Version will do), and a text editor to create some XML files.

KDM – the Knowledge Discovery Meta-model

To stay within the realm of software measurement, we’ll analyze KDM models. KDM – the Knowledge Discovery Meta-model – is a MOF-based meta-model for representing information related to existing software, its elements, associations, and operational environments. It is an OMG standard, and a core part of the OMG’s Architecture-driven Modernization initiative. You can find out more about KDM here or here.

To get an idea what a KDM model looks like, here’s some sample Java code and an excerpt of a XMI file of the KDM model for that code. You can find the full example in Section 12.8.2 of the current KDM 1.3 standard, or here.

To prepare SDMetrics for KDM models, we follow the same three steps. The only difference is that instead of adding to an existing UML meta-model, we have to start from scratch.

Define the KDM meta-model for SDMetrics

SDMetrics uses a simplified meta-model for UML that does not cover the entire UML standard in every last detail. It just contains the parts that are relevant to the metrics and rules it checks.

Likewise, our simplified KDM meta-model for SDMetrics will just contain a few KDM meta-types we’re interested in. The KDM model above has elements such as packages, classes (called class units), methods (called method units) with signatures, and so on. For these elements, we create a meta-model definition file, like so:

For for space reasons, I’m only showing an excerpt of the meta-model definition file here. I have prepared a Zip archive for download (just 3KB) that contains the entire meta-model definition file (file kdmmeta.xml) for about 20 KDM meta-types.

Provide XMI transformations

XMI transformations instruct SDMetrics what information to extract from the XMI file. Essentially, this is a mapping from the “official” KDM meta-model to our simplified version. Writing the XMI transformation file is straightforward: just create an XMI transformation for every meta-model element, and XMI triggers for every attribute.

The XMI transformations for the meta-model elements of the excerpt above look like this:

The file kdmmetrics.xml in the Zip archive contains this and a few more example metrics. If you want to try them out for yourself, unpack the Zip archive, and register the XML and XMI files with SDMetrics. Just drag and drop the four extracted files somewhere into SDMetrics window or the project file settings dialog, SDMetrics will figure out what to do with them. The project file settings should look something like this:

Then close the dialog, hit the “Calculate” button, et voilà, metrics for KDM models, calculated by SDMetrics.