JRuby, Groovy, Javascript, or Jython scripting language can be used to create a validation rule which are used to validate elements in your model. The advantage of using script validation rules is that it is not necessary to compile and store them in a classpath. Oftentimes, the code is compact and simple.
How to create a a script 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 (JRuby, Groovy, Javascript, or Jython).
- Enter the validation code in the selected language.
Here is an example validation rule written in JRuby:
if $THIS.isAbstract() return $THIS.getOwner().isAbstract() end true
The rule validates operations in the model. If an operation is abstract, but its owning classifier isn't, the rule fails. "$THIS" variable references the element being validated. It should be used at least once in the code or in a comment.
Related pages