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

  1. Create a constraint.
  2. Set the stereotype «UML Standard Profile::Validation Profile::validationRule» for the validation rule.
  3. Set the severity level, error message, and abbreviation.
  4. Specify constrained element(s).
  5. Specify the specification language (JRuby, Groovy, Javascript, or Jython).
  6. 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.