Create and edit constraints

Creation and edition comprises includes multiple use case, namely creation of a constraint and its context and setting a specification.


Define a constraint and its context

Papyrus supports the creation of UML constraints. To create a constraint, and associated context, do one of the following:

   
The constraint and context-link tools in the palette


Create a constraint via the model explorer


Set the context via the property view

Define constraint specification

Each constraint has a specification containing a condition. Whereas it may be an arbitrary value specification, such as a StringExpression or LiteralInteger, it is in most cases useful to define an opaque expression consisting of a pair of language and body (a list of these pairs). The constraint body may be written in at least OCL, JAVA, or natural language. In order to make constraints evaluable by Papyrus the constraint must be written in either OCL or JAVA. To define a constraint's specification, first select a constraint on either a diagram or in the Model Explorer, then do the following:


Explicitly choose the editor for the constraint

Use the property view to create a new or open an existing specification, as shown in the following figure. In the sequel, we assume that the specification is an opaque expression.


Open the specification via the property view

You can add the language, as in the following figure:


Specify a language.


Write the body of the opaque expression

This method is a bit more complicated, but gives the user full control over the opaque specification. In particular, it is possible to enter more than one language, body pair (even if this is rarely needed).