Create Custom Checks on Instance Links

The robustness analysis implies some behavioral rules between objects. For example, an actor should always communicate with a boundary object (an interface), entity objects should always communicate with control objects, and so on. To represent these constraints, you are going to define custom checks on the instance links.

Custom checks do not prevent users from performing a syntactically erroneous action, but they allow you to define rules that will be verified by the Check Model function.

You define custom checks with VB scripting.

For more information on VBS syntax, see Scripting PowerDesigner.

  1. Double-click the arrow beside Robustness Extension in the List of Extended Model Definitions to display the resource editor.
  2. Right-click the Profile category and select Add Metaclass.

    The Metaclass Selection dialog box is displayed.

  3. Select InstanceLink in the list of metaclasses displayed in the PdOOM tab and click OK.

    The InstanceLink category is displayed under Profile.

  4. Right-click the InstanceLink category and select New > Custom Check.

    A new check is created.

  5. Type Incorrect Actor Collaboration in the Name box.

    This check verifies if actors are linked to boundary objects. Linking actors to control or entity objects is not allowed in the robustness analysis.

  6. Type "This check ensures that actors only communicate with boundary objects." in the Help Message box.

    This text is displayed in the message box that is displayed when the user selects Help in the custom check context menu in the Check Model Parameters dialog box.

  7. Type " The following instance links are incorrect:" in the Output Message box.
  8. Select Error as default severity.
  9. Select the Execute the Check by Default check box.

  10. Click the Check Script tab.

    The Check Script tab is the tab where you type the script for the additional check.

  11. Type the following script in the text zone.
    Function %Check%(link)
     ' Default return is True
     %Check% = True
     ' The object must be an instance link
     If link is Nothing or not link.IsKindOf(PdOOM.cls_InstanceLink) then
      Exit Function
     End If
     ' Retrieve the link extremities
     Dim src, dst
     Set src = link.ObjectA
     Set dst = link.ObjectB
     ' Source is an Actor
     ' Call CompareObjectKind() global function defined in Global Script pane
     If CompareObjectKind(src, PdOOM.Cls_Actor) Then 
      ' Check if destination is an UML Object with "Boundary" Stereotype
      If not CompareStereotype(dst, PdOOM.Cls_UMLObject, "Boundary") Then
       %Check% = False
      End If
    Elsif CompareObjectKind(dst, PdOOM.Cls_Actor) Then 
      ' Check if source is an UML Object with "Boundary" Stereotype
      If not CompareStereotype(src, PdOOM.Cls_UMLObject, "Boundary") Then
       %Check% = False
      End If
     End If
    End Function
  12. Click the Global Script tab.

    The Global Script tab is the tab where you store functions and static attributes that may be reused among different functions.

  13. Type the following script in the text zone.
    ' This global function check if an object is of given kind
    ' or is a shortcut of an object of given kind
    Function CompareObjectKind(Obj, Kind)
     ' Default return is false
     CompareObjectKind = False
    ' Check object
     If Obj is Nothing Then
      Exit Function
     End If
    ' Shortcut specific case, ask to its target object
     If Obj.IsShortcut() Then
      CompareObjectKind = CompareObjectKind(Obj.TargetObject)
      Exit Function
     End If
    If Obj.IsKindOf(Kind) Then
      ' Correct object kind
      CompareObjectKind = True
     End If
    End Function
    ' This global function check if an object is of given kind 
    ' and compare its stereotype value
    Function CompareStereotype(Obj, Kind, Value)
     ' Default return is false
     CompareStereotype = False
     ' Check object
     If Obj is Nothing or not Obj.HasAttribute("Stereotype") Then
      Exit Function
     End If
    ' Shortcut specific case, ask to its target object
     If Obj.IsShortcut() Then
      CompareStereotype = CompareStereotype(Obj.TargetObject)
      Exit Function
     End If
    If Obj.IsKindOf(Kind) Then
      ' Correct object kind
      If Obj.Stereotype = Value Then
       ' Correct Stereotype value
       CompareStereotype = True
      End If 
     End If
    End Function
  14. Click Apply.

    You are going to repeat steps 4 to 14 and create one check to verify that an instance link is not defined between two boundary objects:

    Check definition

    Content

    Name

    Incorrect Boundary to Boundary Link

    Help Message

    This check ensures that an instance link is not defined between two boundary objects

    Output Message

    The following links between boundary objects are incorrect:

    Default Severity

    Error

    Execute the check by default

    Selected

  15. Type the following check in the Check Script tab:
    Function %Check%(link)
    
     ' Default return is True
     %Check% = True
    
     ' The object must be an instance link
     If link is Nothing or not 
    link.IsKindOf(PdOOM.cls_InstanceLink) then
      Exit Function
     End If
     
     ' Retrieve the link extremities
     Dim src, dst
     Set src = link.ObjectA
     Set dst = link.ObjectB
     
     ' Error if both extremities are 'Boundary' objects
     If CompareStereotype(src, PdOOM.Cls_UMLObject, "Boundary") Then
      If CompareStereotype(dst, PdOOM.Cls_UMLObject, "Boundary") Then
       %Check% = False
      End If
     End If
     
    End Function
  16. Repeat steps 4 to 14 and create one check to verify that entity objects are accessed only from control objects:

    Check definition

    Content

    Name

    Incorrect Entity Access

    Help Message

    This check ensures that entity objects are accessed only from control objects

    Output Message

    The following links are incorrect:

    Default Severity

    Error

    Execute the check by default

    Selected

  17. Type the following check in the Check Script tab:
    Function %Check%(link)
     ' Default return is True
     %Check% = True
     ' The object must be an instance link
     If link is Nothing or not link.IsKindOf(PdOOM.cls_InstanceLink) then
      Exit Function
     End If
     ' Retrieve the link extremities
     Dim src, dst
     Set src = link.ObjectA
     Set dst = link.ObjectB
     ' Source is and UML Object with "Entity" stereotype?
     ' Call CompareStereotype() global function defined in Global Script pane
     If CompareStereotype(src, PdOOM.Cls_UMLObject, "Entity") Then 
      ' Check if destination is an UML Object with "Control" Stereotype
      If not CompareStereotype(dst, PdOOM.Cls_UMLObject, "Control") Then
       %Check% = False
      End If
     Elsif CompareStereotype(dst, PdOOM.Cls_UMLObject, "Entity") Then 
      ' Check if source is an UML Object with "Control" Stereotype
      If not CompareStereotype(src, PdOOM.Cls_UMLObject, "Control") Then
       %Check% = False
      End If
     End If
    End Function
  18. Click Apply.

  19. Click OK in the resource editor.
  20. Select Tools > Check Model to display the Check Model Parameters dialog box.

    The custom checks appear in the Instance Link category.



    You can test the checks by creating instance links between Customer and Application server for example, and then press F4 to start the check model feature.

    For more information on the Check Model feature, see "Checking a Model" in the Models chapter of the Core Features Guide.