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 AnalysisWS.java 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.
@WebService()
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();
input.setByteStream(inStream);
InputStream is = this.getClass().getResourceAsStream("/transformers/XMItoSVG.xsl");
InputSource iss = new InputSource();
iss.setByteStream(is);
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 (AnalysisWS.java).
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"?>
<definitions
xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility- 1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns=http://webservices/
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://webservices/" name="AnalysisWSService">
<types>
<xsd:schema>
<xsd:import
namespace="http://webservices/"
schemaLocation="http://localhost:8080/AnalysisService/AnalysisWSService?xsd=1">
</xsd:import>
</xsd:schema>
</types>
<message name="ProcessXMI">
<part name="parameters" element="tns:ProcessXMI"></part>
</message>
<message name="ProcessXMIResponse">
<part name="parameters" element="tns:ProcessXMIResponse"></part>
</message>
<message name="GenerateSVG">
<part name="parameters" element="tns:GenerateSVG"></part>
</message>
<message name="GenerateSVGResponse">
<part name="parameters" element="tns:GenerateSVGResponse"></part>
</message>
<portType name="AnalysisWS">
<operation name="ProcessXMI">
<input message="tns:ProcessXMI"></input>
<output message="tns:ProcessXMIResponse"></output>
</operation>
<operation name="GenerateSVG">
<input message="tns:GenerateSVG"></input>
<output message="tns:GenerateSVGResponse"></output>
</operation>
</portType>
<binding name="AnalysisWSPortBinding" type="tns:AnalysisWS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="ProcessXMI">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
<operation name="GenerateSVG">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="AnalysisWSService">
<port name="AnalysisWSPort" binding="tns:AnalysisWSPortBinding">
<soap:address location="http://localhost:8080/AnalysisService/AnalysisWSService"></soap:address>
</port>
</service>
</definitions>
Listing Three: WSDL Standard description of the Web service interface (AnalysisWSService.wsdl).


