Chapter 4 Extending your Models with Profiles
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 the Scripting PowerDesigner chapter.
To create custom checks on instance links:
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
' 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
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 |
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
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 |
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
Copyright (C) 2008. Sybase Inc. All rights reserved. |