Adding constraints to custom UML profiles

You can specify constraints within a stereotype in a custom UML profile. When you define Object Constraint Language (OCL) constraints, the constraints are validated syntactically, except for Java constraints. When you apply a stereotype to a model element, the attributes of the stereotype are added to the model element. Stereotype constraints apply to the attributes of the model element to which the stereotype is applied.

About this task

Before you can add attributes to stereotypes, a custom UML profile that contains at least one stereotype must be open in the Project Explorer view.

To add a constraint to a custom UML profile:

Procedure

  1. In the Project Explorer view, right-click a stereotype; then click Add UML > Constraint.
  2. Type a name and press Enter.
  3. In the Properties view, click the General page.
  4. On the General page, in the Language list, select a language.
  5. In the Value field, depending on the selected language, type a description of the constraint.
  6. Beside the Evaluation page, complete one of the following steps:
    • To validate the constraint when you run a validation, select Batch.
    • To validate the constraint when you modify the model element to which the stereotype is applied, select Live.
  7. Optional: To display a localized message when constraint validation fails, beside Message Key, type a key and press Enter. This key must correspond to a key in the properties file for the profile, which can be generated by right-clicking on the profile in the Project Explorer view and selecting Localize. Entries in the properties file are in the form of key=Localized Message.
  8. Optional: To specify the severity level to display in the Problems view when a constraint is validated, beside Severity, select a severity level.

Feedback