We will now create three custom checks on the instance links that will connect the various robustness objects. These checks, which are written in VB, do not prevent users from creating diagrams not supported by the robustness methodology, but define rules that will be verified by the Check Model function.
For more information on VBS syntax, see Scripting PowerDesigner.
Field |
Value |
|---|---|
Name |
Incorrect Actor Collaboration |
Comment |
This check verifies if actors are linked to boundary objects. Linking actors to control or entity objects is not allowed in the robustness analysis. |
Help message |
This check ensures that actors only communicate with boundary objects. |
Output message |
The following instance 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 then
Exit Function
End if
If 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
ElseIf 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 it's target object
If Obj.IsShortcut() Then
CompareObjectKind = CompareObjectKind(Obj.TargetObject, Kind)
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 it's stereotype value
Function CompareStereotype(Obj, Kind, Value)
' Default return is false
CompareStereotype = False
' Check object
If Obj is Nothing then
Exit Function
End If
if (not Obj.IsShortcut() and not Obj.HasAttribute("Stereotype")) Then
Exit Function
End If
' Shortcut specific case, ask to it's target object
If Obj.IsShortcut() Then
CompareStereotype = CompareStereotype(Obj.TargetObject, Kind, Value)
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
' This global function copy the standard attribute
' from source to target
Function Copy (src, trgt)
trgt.name = src.name
trgt.code = src.code
trgt.comment = src.comment
trgt.description = src.description
trgt.annotation = src.annotation
Dim b, d
for each b in src.AttachedRules
trgt.AttachedRules.insert -1,b
next
for each d in src.RelatedDiagrams
trgt.RelatedDiagrams.insert -1,d
next
output " "
output trgt.Classname & " " & trgt.name & " has been created."
output " "
End Function
|
Field |
Value |
|---|---|
|
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] |
Check Script |
Function %Check%(link)
' Default return is True
%Check% = True
' The object must be an instance link
If link is Nothing then
Exit Function
End if
If 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
|
|
Field |
Value |
|---|---|
|
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] |
Check Script |
Function %Check%(link)
' Default return is True
%Check% = True
' The object must be an instance link
If link is Nothing then
Exit Function
End if
If 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
ElseIf 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
|