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
- In the Project Explorer view, right-click
a stereotype; then click .
- Type a name and press Enter.
- In the Properties view, click the General page.
- On the General page, in the Language list,
select a language.
- In the Value field, depending on
the selected language, type a description of the constraint.
- 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.
- 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.
- Optional: To specify the severity level to
display in the Problems view when a constraint
is validated, beside Severity, select a severity
level.