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. However, Java™ constraints
are not validated syntactically. 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 sterotype is applied. The model validation
process checks model element attributes for compliance with stereotype
constraints. If you specify a value for the attribute that does
not comply with the constraint, an error is displayed in the Problems view.
Before you can add attributes to stereotypes,
a custom UML profile that contains at least one stereotype must
be open in the Model Explorer view.
To add a constraint to a custom UML profile:
- In the Model Explorer view,
right-click a stereotype; then click .
- Type a name and press Enter.
- In the Properties view, click the General tab.
- On the General page, in the Language list,
click a language.
- In the Body field, type a description
of the constraint.
- Click the Advanced tab.
- On the Advanced page, expand Metamodel
Constraint.
- In the Property column, click Evaluation
Mode.
- Beside Evaluation Mode, in the
Value column, complete one of the following steps:
- To validate the constraint when you run a validation,
click Batch.
- To validate the constraint when you modify the model element
to which the stereotype is applied, click Live.
- Optional: To specify the severity level
to display in the Problems view when a constraint
is validated, beside Severity, in the Value
column, click a severity level.
- Optional: To display the message key that
is defined in the properties file of the profile when constraint validation
fails, beside Message Key, in the Value column,
type the message ID and press Enter.