' Merge 2 Uni -> 1 Bi Association Script ' ' (c) 2000 by Michael Moors ' http://www.rationalrose.com/michael ' ' Author: Michael Moors ' Date: 11 May 2000 ' ' Description: ' This script merges 2 uni-directional association ' into 1 bi-directional association. ' Sub Main dim c as class Dim cc As classcollection Dim ac As associationCollection Dim otherrole As role Dim CorresRole As role Dim a As association Dim co As class Dim aco As associationCollection Dim otherroleo As role Dim CorresRoleo As role Dim ao As association Dim skips As New AssociationCollection Set cc = RoseApp.currentmodel.getallclasses zapped = 0 Dim rollo As role For i% = 1 To cc.count set c = cc.getat(i) If c.stereotype <> "Actor" Then set ac = c.getAssociations for j% = ac.count to 1 step -1 set a = ac.getat(j) Set OtherRole = a.getotherRole(c) Set CorresRole = a.getcorrespondingrole(c) If otherRole Is Not Nothing Then If otherRole.class Is Not Nothing Then If otherRole.Navigable = true _ And CorresRole.Navigable = false Then ' found first unidirection association Set co = otherrole.class If co.stereotype <> "Actor" Then Set aco = co.getAssociations For j% = aco.count To 1 Step -1 Set ao = aco.getat(j) If Not a Is ao Then Set OtherRoleo = ao.getotherRole(c) Set CorresRoleo = ao.getcorrespondingrole(c) If otherRole Is Not Nothing Then If otherRoleo.class Is Not Nothing Then If otherRoleo.Navigable = false _ And CorresRoleo.Navigable = true _ And CorresRoleo.class Is c Then ' found second unidirection association going back ' merging: a.role2 = otherroleo ' Not yet supported: properties, keys, externaldocuments corresrole.navigable = true corresrole.Name = corresroleo.Name corresrole.Constraints = corresroleo.Constraints corresrole.Friend = corresroleo.Friend corresrole.Cardinality = corresroleo.Cardinality corresrole.Containment = corresroleo.Containment corresrole.aggregate = corresroleo.aggregate corresrole.static = corresroleo.static corresrole.ExportControl = corresroleo.ExportControl corresrole.stereotype = corresroleo.stereotype corresrole.localizedstereotype = corresroleo.localizedstereotype corresrole.documentation = corresroleo.documentation ' removing second dummy = co.deleteassociation(ao) zapped = zapped + 1 ' keep count End If End If End If End If Next j End If End If End If End If Next j End If Next i End Sub