Contents > 9 Extending the Metrics and Rule Engine > 9.1 Metric Procedures > 9.1.3 Using the New Metric Procedure

9.1.3 Using the New Metric Procedure

Before we can use our new metric procedure, we must first register it with the metrics engine. We add the following XML element to our metric definition file:
<metricprocedure name="pairwise" 
	class="com.acme.MetricProcedurePairwise" />
Attribute name defines the name to denote the metric procedure in subsequent metric definitions, attribute class defines the fully qualified name of the metric procedure class.

We can then define metrics using our newly created metric procedure. Here's another example of a LCOM-style cohesion metric:

<metric name="LCOC_AttributeTypes" domain="package">
<description>The maximum number of attribute types shared by a pair 
   of classes in a package.</description>
<pairwise relation="context" target="class" 
   sum="size(_first.AttrTypeSet * _second.AttrTypeSet)" stat="max" />
For SDMetrics to find our new metric procedure, we have to ensure that the class is included in the class path when we run SDMetrics. The simplest way to achieve this is by putting the class files in the "bin" folder of the SDMetrics installation directory. SDMetrics searches this directory for class files.

Within the "bin" directory, we have to create a structure of subfolders that reflects the packages of the classes we provide. The class file for class com.acme.MetricProcedurePairwise therefore will be located at the path bin/com/acme/MetricProcedurePairwise.class.