SysML Plugin 19.0 LTR Documentation


Before creating a new Constraint element, you must decide the Constraint type to create. The Constraint type defines a target for which the validation rule will be evaluated.

There are three types of Constraints that can be evaluated:

  • Classifier level Constraints. Constraints placed on the classes, datatypes and other classifiers of the model are evaluated on all the instances of these classifiers (i.e. those Instance Specifications that have the particular classifier set as their type). Constraints defined on some particular classifiers are evaluated on the instances of these particular classifiers when validating. Inheritance is taken into account; instances of the subclasses of the class are also validated.
  • Constraints on Metaclasses. When a Constraint is placed on a metaclass (one of the classes in the UML Standard Profile > UML2 Metamodel), this Constraint is evaluated on all the model elements of that kind (e.g. if the Constraint is placed on the Actor metaclass, then this Constraint applies to all actor elements in the model). The following is an example of a rule (specified in OCL2.0) mandating that all actor names in the model must be capitalized. These Constraints are useful for specifying generic rules that must apply on all the model elements of a particular kind.

    context Actor inv capitalize:
    let startswith:String = name.substring(1,1) in
    startswith.toUpper() = startswith
  • Constraints on Stereotypes. When a Constraint is placed on some Stereotypes of the Profile, that Constraint applies to all the model elements that have these Stereotypes applied to them. These Constraints are useful when creating domain specific profiles. When adapting UML to some specific modeling domain, a Profile is usually created with extensions for that domain - Stereotypes, tags etc. The Constraints on these Stereotypes allow enforcing the rules of that domain.

Recommendation

It is strongly recommend not to mix the Constraints from different metalevels into one validation suite. Learn more how to create validation suite >>

Examples of Constraint types

The examples of each Constraint type can be found in the model validation sample model. To open this sample do one of the following:

  • Download model validation.mdzip.
  • Find in your modeling tool <modeling tool installation directory>\samples\product features\model validation.mdzip.


You can create a new Constraint for :


To create Constraint for a classifier or Stereotype


  1. Open the Specification window of a classifier or Stereotype. How to open the Specification window >>
  2. On the left side of the window, select the Constraints property group.
  3. On the right side of the window, click the Create button and select Constraint.
  4. Type its name.
    The new Constraint is created in the model.


To create Constraint for a metaclass


  1. Select a package where you want to store the rule.
  2. Right-click this package, select Create Element > Constraint.
  3. Type its name.
    The new Constraint is created in the model.

    If you create a new Constraint for a metaclass, you must specify the Constrained Element property in the Constraint Specification window. How to specify Constrainted Element property >>


  • No labels