3. OCL statement
OCL rules are used to execute constraints against XML file. These rules always return a boolean value, either true or false.
OCL rule (can also be referred by "rule") contains multiple parts
All these parts are defined by the creator of the rule. The core parts being context and OCL-statement.
It is crucial to first understand the concept of context. In short, context is set to be complex or simpleType defined in the relevant schema, and OCL-rule is ran whenver the type defined in the context is found within the XML-file.
Restriction defined in the OCL-statement returns a boolean value. Whenever false is returned, XMLdation service will return an error message to a pre-defined location within the XML-file (defined by OCL-query), with a pre-defined error message. Whenever true is returned, the restriction passes and XML file is considered valid against that rule.
Rule is written so that it matches the business rule it is depicting. For example, when a business rule is:
Debtor name must be "The initiator"
OCL-restriction is written in same form, so that valid case is depicted in the rule
|OCL:||self.Debtor.Name = "The initiator"|
|Description:||Rule defines a specific value for Debtor/Name.|
When an erreneous file against that rule is inserted to validation pipe, an error will be returned whenever Debtor Name is not the one defined in the statement.
Multiple rules may be present in validation pipe, together they form a ruleset. Multiple rulesets may be present as well. The names of these rulesets are returned in the validation results page.
Let's have a more thorough look at the business rule depicted above, 'Debtor name must be "The initiator"'. This business rule looks simple, but it contains two different rules. Following example scenarios are possible to be given:
The XML snippet below would the pass check.
However, there are two different possible cases which would not pass the rule
Two cases being:
- Debtor name is not present at all
- Debtor name is something else than defined in the business rule
One rule can only contain one error message, so in order to make the error messages as accurate as possible, this business rule has to be divided into two different OCL-rules
- Debtor name is mandatory
- When Debtor name is given, its value must be "The initiator"
|OCL:||self.Debtor.Name->size() = 1|
|Description:||Rule mandates Debtor name|
self.Debtor.Name->size() = 1 implies
self.Debtor.Name = "The initiator"
|Description:||Rule restricts the value of Dbtr Nm when it is given|