' Merge 2 Uni -> 1 Bi Association Script ' ' Version 1.1 ' ' (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. ' If there are more then 2 assocations going back, ' the script will not merge that particular one. ' ' Known limitations and Problems: ' - Not supported: ' * properties ' * keys ' * externaldocuments ' ' History: ' 11-May-00 MM Created script ' 23-May-00 MM Added "Option Explicit" ' 24-May-00 MM Skip multiple assoc's ' Option Explicit 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 FirstRole As Role Dim FirstAsso As Association Dim multiple As Boolean Dim ao As association Dim dummy As Boolean Dim skips As New AssociationCollection Set cc = RoseApp.currentmodel.getallclasses Dim zapped As long zapped = 0 Dim i As Long Dim j As Long Dim k As Long 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 ' Start looking if there is another association ' also going to same class, we don't do multiples multiple = false For k = 1 To ac.count ' skip myself If (Not ac.getat(k) Is a) _ _ ' look for assoc to same target class And (ac.getat(k).getotherrole(c).class Is co) _ _ ' is assoc navigable to that class too? And (ac.getat(k).getotherrole(c).navigable) Then multiple = true End If Next k If Not multiple Then If co.stereotype <> "Actor" Then Set aco = co.getAssociations multiple = false Set firstrole = Nothing 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 If FirstRole Is Nothing Then Set FirstRole = CorresRoleo Set FirstAsso = ao ' start looking if there is more going back Else ' there are multiple asso's going back multiple = true End If End If End If End If End If Next j If (Not FirstRole Is Nothing) And (Not multiple) Then ' merging: a.role2 = FirstRole ' which is same as otherroleo ' Not yet supported: properties, keys, externaldocuments corresrole.navigable = true corresrole.Name = FirstRole.Name corresrole.Constraints = FirstRole.Constraints corresrole.Friend = FirstRole.Friend corresrole.Cardinality = FirstRole.Cardinality corresrole.Containment = FirstRole.Containment corresrole.aggregate = FirstRole.aggregate corresrole.static = FirstRole.static corresrole.ExportControl = FirstRole.ExportControl corresrole.stereotype = FirstRole.stereotype corresrole.localizedstereotype = FirstRole.localizedstereotype corresrole.documentation = FirstRole.documentation ' removing second dummy = co.deleteassociation(FirstAsso) zapped = zapped + 1 ' keep count End If End If End If End If End If End If Next j End If Next i End Sub