Sometimes it is hard to specify the rule for some advanced concepts in OCL. For example, the string manipulation is rather weak in OCL2.0, hence the writing rule for string formats, parsing strings is very hard in OCL. In such cases the modeling tool offers possibility to write rules in Java language and invoke them when validating.
Common steps for creating a binary validation rule:
- Create a constraint
- Set the stereotype «UML Standard Profile::Validation Profile::validationRule» for the validation rule
- Set the severity level, error message, and abbreviation
- Specify constrained element(s)
- Specify the specification language binary
- Create a Java implementation class (see all possible cases)
- Compile Java code, resulting in one or several classes.
- Ensure that your modeling tool can find & load these classes. You can place them in the program classpath or use the modeling tool plugins mechanism. The same rules as writing the code for the open API are used here.
These steps are common to all possible binary validation cases and will not be repeated in each case description.
See the MyBinaryValidationRuleImpl.java example in the <program installation directory>\openapi\examples\validation directory.
The implementation class must be in the classpath of the program or if the implementation class is in a plugin then the plugin’s classloader must be registered to the validation system (see Binary validation rule in the plugin).