Channels ▼

Web Development

A Web Service for Calculating the Metrics of UML Class Diagrams

A Web Service for Calculation of Metrics in UML Class Diagrams

We have developed a Web service (named AnalysisWSService) with two methods that accept the input of UML class diagrams in XMI format and generate design metrics. Figure 2 shows the Web service installed in a Web server (right side). As an example of use, we have programmed a Web application that invokes the service methods (left side).

Figure 2: Context of the deployed Web service.

A total of 37 different metrics, shown in Table 1, are implemented in our application. These metrics are carefully explained in the article "A Survey of Metrics for UML Class Diagrams.")

Method Description
WMC Weighted Methods per Class
DIT Depth of Inheritance

NOC Number Of Children (or direct descendents of a class)
IC_Attr Import Coupling with Class-Attribute interaction between a class and the rest
EC_Attr Export Coupling with Class-Attribute interaction between a class and the rest
IC_Par Import Coupling with Class-Method interaction between a class and the rest
EC_Par Export Coupling with Class-Method interaction between a class and the rest
MHF Method Hiding Factor
AHF Attribute Hiding Factor
MIF Method Inheritance Factor
AIF Attribute Inheritance Factor
PF Polymorphism Factor
PIM Public Instance Methods
NIM Number of Instance Methods

NIV Number of Instance Variables
NCM Number of Class Methods
NCV Number of Class Variables
NMO Number of Methods Overridden
NMI Number of Methods Inherited
NMA Number of Methods Defined

NumAttr Number of attributes in a class
NumOps Number of operations in a class
NumPubOps Number of public operations in a class
NumDesc Number of descendents of a class
NumAnc Number of ancestors of a class
CLD Class to Leaf Depth

OpsInh Number of inherited operations
AttrInh Number of inherited attributes
Dep_Out Number of elements on which a class depends
Dep_In Dep_In: Number of elements that depend on a class
NumAssEl_ssc Number of associated elements in the same scope (namespace) as a class

Table 1. Object-oriented metrics implemented in the Web service.

A Web service can be created using any programming language. In our case, the Web service was developed in Java. Figure 3 shows the three Java classes of our Web service.

The class includes the source code of the two Web methods offered by the Web service (see Listing Two):

  • ProcessXMI: This Web method receives an XMI file as a byte array (that represent a class diagram encoded in XMI format), and returns a table (serialized as a string) with the calculation of 37 object-oriented metrics.
  • GeneratesSVG: This method is responsible for converting an XMI file into a standard SVG picture that represent the graphical form of the class diagram.

Also shown in Figure 3, the Web service uses these classes to calculate the object-oriented metrics:

  • ClassXMI: This class contains all the functionality for processing XMI files.
  • ClassXMIMetrics: This class includes the functionality related to the evaluation of the object-oriented metrics. It contains an object (ClassXMIObject) necessary to explore the XMI file with the class diagram to be evaluated.

Figure 3: Java classes used in the Web service.

public class AnalysisWS 

    @WebMethod(operationName = "ProcessXMI")
    public String ProcessXMI(@WebParam(name = "xmiFile")
    byte[] xmiFile)
        //Attributes needed for processing of xmi file
        String result = "ok";
        Document resultDoc = null;
        ClassXMI classXMI = null;        // This 2 specific classes have been developed
        ClassXMIMetrics metrics = null;  // for XMI file processing and metrics calculation 

        ... rest of the method “ProcessXMI” source code

    @WebMethod(operationName = "GenerateSVG")
    public String GenerateSVG(@WebParam(name = "xmiFile")
    byte[] xmiFile)
        String result = "ok";
        try {
            InputStream inStream = new ByteArrayInputStream(xmiFile);
            InputSource input = new InputSource();
            InputStream is = this.getClass().getResourceAsStream("/transformers/XMItoSVG.xsl");
            InputSource iss = new InputSource();
            result = this.TransformXMItoSVG(input, iss);
        catch(Exception ex) {
            result = ex.getMessage();
        finally {
            return result;

     private String TransformXMItoSVG(InputSource input, InputSource xslt)
            throws TransformerException, TransformerConfigurationException, 
SAXException, IOException
     {... local function used by “GenerateSVG” Web method...}

Listing Two: Java source code of the Web service (

A programmer who wants to use a Web service need only know the description of its interface in WSDL format, which is shown in Listing Three.

<?xml version="1.0" encoding="UTF-8"?>
 " 1.0.xsd"  xmlns:soap="" xmlns:tns=http://webservices/
 xmlns:xsd="" xmlns="" 
 targetNamespace="http://webservices/" name="AnalysisWSService">
 <message name="ProcessXMI">
  <part name="parameters" element="tns:ProcessXMI"></part>
 <message name="ProcessXMIResponse">
  <part name="parameters" element="tns:ProcessXMIResponse"></part>
 <message name="GenerateSVG">
  <part name="parameters" element="tns:GenerateSVG"></part>
 <message name="GenerateSVGResponse">
  <part name="parameters" element="tns:GenerateSVGResponse"></part>
 <portType name="AnalysisWS">
  <operation name="ProcessXMI">
   <input message="tns:ProcessXMI"></input>
   <output message="tns:ProcessXMIResponse"></output>
  <operation name="GenerateSVG">
   <input message="tns:GenerateSVG"></input>
   <output message="tns:GenerateSVGResponse"></output>
 <binding name="AnalysisWSPortBinding" type="tns:AnalysisWS">
  <soap:binding transport="" style="document"></soap:binding>
  <operation name="ProcessXMI">
   <soap:operation soapAction=""></soap:operation>
    <soap:body use="literal"></soap:body>
    <soap:body use="literal"></soap:body>
  <operation name="GenerateSVG">
   <soap:operation soapAction=""></soap:operation>
    <soap:body use="literal"></soap:body>
    <soap:body use="literal"></soap:body>
 <service name="AnalysisWSService">
  <port name="AnalysisWSPort" binding="tns:AnalysisWSPortBinding">
   <soap:address location="http://localhost:8080/AnalysisService/AnalysisWSService"></soap:address>

Listing Three: WSDL Standard description of the Web service interface (AnalysisWSService.wsdl).

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
Dr. Dobb's TV