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. 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:
  1. In the Model 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 tab.
  4. On the General page, in the Language list, click a language.
  5. In the Body field, type a description of the constraint.
  6. Click the Advanced tab.
  7. On the Advanced page, expand Metamodel Constraint.
  8. In the Property column, click Evaluation Mode.
  9. 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.
  10. 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.
  11. 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.
Related concepts
Custom UML profiles
Related reference
Stereotypes and constraints
Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.