ReqIF is a very flexible meta-model and exchange format definition. The possible attributes of requirements are not predefined, but can be defined within the standard itself. This makes implementation of queries and constraints somewhat more complex. But with Xtext, we can easily create a language that knows about the data model of a ReqIF file and implements a language.
A simple definition of a string attribute “Description” for a requirement type “XType” would look like this in XML:
|
1 2 3 4 5 6 7 8 9 |
<SPEC-OBJECT-TYPE IDENTIFIER="rmf-78d0fdbe-b30d-4c2c-9696-f7f046d3012b" LONG-NAME="XType"> <SPEC-ATTRIBUTES> <ATTRIBUTE-DEFINITION-STRING IDENTIFIER="rmf-d18a3c57-3354-44cb-a7c0-3eb08edb7d2e" LONG-NAME="Description"> <TYPE> <DATATYPE-DEFINITION-STRING-REF>rmf-214fc814-6ad3-4d8b-94df-dc705c48103a</DATATYPE-DEFINITION-STRING-REF> </TYPE> </ATTRIBUTE-DEFINITION-STRING> </SPEC-ATTRIBUTES> </SPEC-OBJECT-TYPE> |
Because of this flexibility, you will not find just an attribute with the name “Description” in your requirements, but so-called AttributeValues that reference their attribute definitions, which actually define the attribute names.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<SPEC-OBJECT IDENTIFIER="rmf-4a1e96c8-2198-4f05-9c08-91d3d6ab7b28"> <VALUES> <ATTRIBUTE-VALUE-STRING THE-VALUE="Start editing here."> <DEFINITION> <ATTRIBUTE-DEFINITION-STRING-REF>rmf-d18a3c57-3354-44cb-a7c0-3eb08edb7d2e</ATTRIBUTE-DEFINITION-STRING-REF> </DEFINITION> </ATTRIBUTE-VALUE-STRING> </VALUES> <TYPE> <SPEC-OBJECT-TYPE-REF>rmf-78d0fdbe-b30d-4c2c-9696-f7f046d3012b</SPEC-OBJECT-TYPE-REF> </TYPE> </SPEC-OBJECT> |
To retrieve the value of an attribute, you’d have to traverse a requirement’s attribute value, compare the names and fine the object. There is a helper object for that (ReqIF10Util) that comes with RMF:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public static AttributeValue getAttributeValueForLabel( SpecElementWithAttributes element, String label) { if (label == null) return null; for (AttributeValue value : element.getValues()) { if (value == null) continue; AttributeDefinition ad = getAttributeDefinition(value); if (ad != null && label.equals(ad.getLongName())) { return value; } } return null; } |
So, in your code you would have something like ReqIF10Util.getAttributeValueForLabel(element,”Description”). But since AttributeValue is an abstract class, your following code would have quite some case-statements depending on the actual type of AttributeValue, since the ReqIF meta-model does not define an abstract method for retrieving the actual value.
A user friendly language
We don’t want that. What we’d like to do is to have a language where we could just write requirement.Description. Actually, this is very easy to do in Xtext. As an example, we create a Xtext language that allows to specify expressions on requirement objects. It simply references the ReqIF object SpecObjectType and then is followed with an Expression.
All is needed is a JvMModelInferrer that creates JvmTypes from the referenced ReqIF model. And voila, a complete editor that knows about the types of the referenced ReqIF and provides their attributes directly:
Description is a defined attribute in ReqIF and can be accessed directly know.
A constraint interpreter
Specifying expressions is nice, but executing is what’s interesting. As you see in the screenshot above, there is an error marker at the expression. It says:
This is because we simply added an interpreter for the language that is executed on the ReqIF model and is integrated into the validator. So if we have a requirement that causes the expression to evaluate to false, an error is flagged.
Further uses
Of course, the constraint evaluation can be integrated in the tabular editor that comes with RMF, called ProR. In addition, there are further uses of the approach
- Could be used as a query language to filter requirements
- In combination with Xtend2 expressions might be used for reporting infrastructure
- It is not only possible to query models, but also to modify models.
Since the Xbase expressions can be both interpreted as well as compiled to Java, this is a fast and flexible infrastructure.

