Contents > 8 Defining Custom Design Metrics and Rules > 8.7 Defining Metrics for Profiles > 8.7.4 Profile Extensions with Regular Model Elements

8.7.4 Profile Extensions with Regular Model Elements

In our first and simplest approximation, we just define a new model element type "requirement" in our SDMetrics metamodel (Section 7.1 "SDMetrics Metamodel") to store the information from the <sysml:Requirement> XML element:
<modelelement name="requirement">
  <attribute name="base" type="ref">The extended class.</attribute>
  <attribute name="text">Text of the requirement.</attribute>
  <attribute name="reqid">ID of the requirement in the model.</attribute>
</modelelement>
The XMI transformation to process the <sysml:Requirement> XML element looks like this:
<xmitransformation modelelement="requirement" xmipattern="sysml:Requirement">
  <trigger name="base" type="attrval" attr="base_Class" />
  <trigger name="text" type="attrval" attr="Text" />
  <trigger name="reqid" type="attrval" attr="Id" />
</xmitransformation>
With these definitions in place, the SysML requirement of the SysML model is represented by two elements in SDMetrics: one "class" element and one "requirement" element.

How do we know if a class in the model represents a SysML requirement? The class represents a SysML requirement if there is a "requirement" element in the model whose reference attribute "base" points to the class. Using the "filtervalue" procedure (Section 8.1.7 "Value Filter"), we can define a "helper" metric that yields the requirement element extending the class, if one exists:

<metric name="Reqmt" domain="class" internal="true">
  <filtervalue relation="base" target="requirement"  />
</metric>
We can then use this metric to identify classes that represent requirements. For example, to count the number of requirements in a package, we count all classes where metric "Reqmt" is not empty:
<metric name="ReqCount" domain="package">
  <projection relation="context" target="class" condition="Reqmt!=''" />
</metric>