section: < previous | next > | | | |
chapter: << previous | next >> |
2.3 SetClassifierRoles
SetClassifierRoles represent Sets, Bags and Sequences in OCL. Navigations over AssociationRoles can have Collections as a result. This subsection describes how to create SetClassifierRoles. In this version of the editor it only is possible to create Sets (SetClassifiers) . Moreover operations are present which can be hanled. These operations are isEmpty, isNotEmpty, size or sum.
2.3.1 Create a SetClassifierRoles
Follow these steps:- Select the palette entry ClassifierRoleSet and move the mouse cursor inside a Constraint that must have been created before and click into it.
- The dialog is similar to the ClassifierRole's dialog concerning the role name, role type and attribute section (see Fig. 2.3.1). However, can not define any method call here but you can choose several operations instead that are explained in detail later in this section.
- The role type refers to a name of a class on which the Constraint
should be defined.
- As a operation type you can choose isEmpty.
- Click Ok and the figure
will look like Fig. 2.3.2
Fig. 2.3.1 - dialog for creating SetClassifierRole
Fig. 2.3.2 - SetClassifierRole with an isEmpty operation
2.3.1.1 The size operator
If you want to create a SetClassifierRole that has an size-operation you have to do the same steps as above but you have to choose the operation type SIZE instead (see Fig. 2.3.3). This operation returns the number of objects. The number is a variable that can be used in a condition.Fig. 2.3.3 - dialog for creating SetClassifierRole with a size operation
Fig. 2.3.4 - SetClassifierRole with a size operation
2.3.1.2 The sum operator
With the sum operator you can iterate over a varible bound to an attribute. The result of the sum operation is assigned to another variable which can be used in a condition. The iterator variable can not be used in a condition. This is prohibited by the editor because it does not occur in the condition dialog.In Fig. 2.3.5 the dialog to define a sum operation is shown. There are two additional textfields in which you can define the iterator variable and the other variable name. The resulting SetClassifierRole can be seen in Fig. 2.3.6. The sum operator appears as a string "SUM" with the iterator variable as the argument at the right bottom side of the SetClassifierRole. The result of the sum operation is assigned to the other variable which can be used inside a Condition.
Fig. 2.3.5 - dialog for creating SetClassifierRole with a sum operation
Fig. 2.3.6 - SetClassifierRole with a sum operation
After clicking on Ok the correctness of the SetClassifierRole is checked. If the iterator variable has no correspondend variable that is bound to an attribute the dialog in Fig. 2.3.7 is show. Then you have to change either the name of iterator variable or the name of the variable being bound to an attribute, so that they are equal.
Fig. 2.3.7 - iterator variable is not bound at any attribute variable