You can use the Alf editor to create an Alf body for an Opaque Action in an Activity or to edit the existing Alf body of an Opaque Action. The Alf code for an Opaque Action is stored as the body of the Opaque Action with the language Alf. Compiling this Alf code results in the creation of an executable Activity reflecting the behavior defined by the Alf code. This Activity is attached to the Opaque Behavior as a tagged value of the special CompiledRepresentation stereotype. (See also the discussion on the Alf compiler.)


To create an Alf body for an Opaque Action


  1. Select the Opaque Action in an Activity diagram (or in the Model Browser, though this usually not convenient) and open the Alf editor window (select Windows > Alf), if it isn't already open.
  2. Enter the Alf code for the Opaque Action and press Save to compile and save the code.

    The Alf code in an Opaque Action can comprise one or more Alf statements. The names of the Input and Output Pins of the Action may be used as local names in the Alf code. The local names for Input Pins have the values that are on the Pins when the Action executes. The local names for Output Pins are assignable with the values to be placed on those pins when the Action is done executing. (But see also Using Alf expressions in Opaque Actions.)


To edit the Alf code for an Opaque Action


  • Select the Opaque Action and open the Alf editor window (select Windows > Alf), if it isn't already open. The existing Alf code will appear in the window.


When the CompiledRepresentation stereotype is applied to an Opaque Action by the Alf compiler, MagicDraw may, by default, show the Stereotype and its tagged values in the Opaque Action symbol (as shown below). If you do not want this depicted in your diagram (as in the diagram above), you can turn it off in the Opaque Action symbol properties.

Opaque Action showing the CompiledRepresentation Sterotype


To not show Stereotypes or tagged values on Opaque Actions


  1. Right click on the Opaque Action symbol and select Symbol Properties to open the Symbol Properties window.
  2. Select Expert from the Apply Style menu at the top right (or All, if necessary).
  3. Uncheck the box for the Show Tagged Values property (so it is false).
  4. Click on the Show Stereotypes property and select Do Not Display from the drop down menu.
  5. Click on Close to close the Symbol Properties window.


To change the default for showing Stereotypes and tagged values on Opaque Actions


  1. Select Options > Project from the main menu.
  2. On the left, under Symbol styles > Default > Shapes, select Opaque Action.
  3. On the right, change the relevant symbol properties, as above.
    If you want to update the properties on existing diagrams, continue. Otherwise skip to step 9.
  4. Click on Apply. The Select Diagrams window will open.
  5. Click on Select All (or select specific diagrams on which to apply the new defaults).
  6. Click on OK. The Select Properties to Apply window will open.
  7. Under Selected, choose Show Tagged Values, click on the < button, then choose Show Stereotypes, and click on the < button again.
  8. Click on OK to close the Select Properties to Apply window.
  9. Click on OK to close the Project Options window.

The Alf code for an Opaque Action can also be entered or edited directly in the Body and Language property for it in the Specification window for the Opaque Action. If you open the Edit Body and Language window, then the Alf code may be edited just as in the Alf editor window. However, instead of Save and Revert buttons, this window has OK and Cancel buttons, either of which will close it. If you press OK, then the text is saved, and, if it has no errors, compiled. If you press Cancel, the Alf text is not saved.

Editing Alf code in an Opaque Action body

To be recognized as Alf code, the Body of an Opaque Action must have the Language Alf. If your project was created using the Alf project template, then Alf will be the default language. Otherwise, select Alf from the Language menu (you may have to scroll upwards in the menu to find the selection for Alf).

To make Alf the default language for Opaque Actions


  1. Select Options > Project.
  2. On the left, under Default model properties, select Opaque Action.
  3. Click on the Language field and then on the small + button on the right.
  4. Enter Alf (spelled and capitalized in exactly that way) and click on OK.
  5. Click on OK to close the options window.

If the Name Display Mode symbol property of an Opaque Expression is set to Body, then the Alf code for the Opaque Behavior can also be edited directly on an Activity diagram showing the Opaque Action. Since such editing does not use the Alf editor, no parsing or constraint checking happens while Alf code is being edited. The code is compiled once you finish editing it, and, if there are compilation errors, they will be recorded in an error annotation on the Opaque Action.