'This script is intended to use with Rose98/Java Reverse Engineering '------------------------------------------------------------------- 'Problem: On reverse engineering attributes of type String or Vector ' etc. ("extended" basic types) are substituted by ' association roles. 'Solution: This script deletes associations to String etc. and ' creates attributes of the specific type instead. '------------------------------------------------------------------- 'Holger Dörnemann, Rational Software, July 1998 '------------------------------------------------------------------- Sub WorkOnClasses (theCat As Category, offset As String) '============================ ' please specify types below '============================ Dim theTypes(1) As String theTypes(0) = "String" theTypes(1) = "Vector" types = 2 Dim theClasses As ClassCollection Dim theClass As Class Dim theAssocColl As AssociationCollection Dim theAssocRole As Role Dim delAssoc(100) As Association Dim theAttribute As Attribute Set theClasses = theCat.Classes For cls% = 1 To theClasses.Count Set theClass = theClasses.GetAt(cls%) Print offset + " - " + theClass.name Set theAssocColl = theClass.GetAssociations i% = 1 For role% =1 To theAssocColl.Count Set theAssocRole = theAssocColl.GetAt(role%).role2 For t% = 0 To types-1 If (theAssocRole.getClassname = theTypes(t%)) Then Print offset + " - " + theAssocRole.name Set delAssoc(i%) = theAssocColl.GetAt(role%) i% = i% + 1 Set theAttribute = theClass.AddAttribute(theAssocRole.name, theTypes(t%), "") theAttribute.Documentation = theAssocRole.Documentation theAttribute.ExportControl = theAssocRole.ExportControl End If Next t% Next role% For role% = 1 To i%-1 bool=theClass.DeleteAssociation(delAssoc(role%)) Next role% Next cls% End Sub Sub CreateBrowserCategoriesArray (aCategory As Category, theList () As String, iCurElm As Integer, iDepth As Integer) If iDepth > 1 Then Elm$ = Elm$ + Space$ (iDepth * 2) Elm$ = Elm$ + aCategory.Name theList(iCurElm-1) = Elm$ For i% = 1 To aCategory.Categories.Count iCurElm = iCurElm + 1 CreateBrowserCategoriesArray aCategory.Categories.GetAt(i%), theList, iCurElm, iDepth + 2 Next i% End Sub Function DialogLoop(controlname$, action%, suppvalue%) As Integer Dim CategoryId As Integer Dim AllCategories As CategoryCollection Set AllCategories = RoseApp.CurrentModel.GetAllCategories () Dim CategoryName As String Dim FileName As String Dim Results As String Dim SelectedCategory As Category '---------------------------------------------- 'If user presses a button do appropriate action '---------------------------------------------- ' Print controlname$, action%, suppvalue% Select Case action% Case 1 ' Init Dialog Case 2 If controlname$ = "Cancel" Then BrowserDialogLoop = 0 ElseIf ControlName$ = "GoBtn" Then ' Find out the current selected category CategoryName = Trim (DlgText$("CategoryListBox")) CategoryId = allCategories.FindFirst (CategoryName$) Set SelectedCategory = allCategories.GetAt (CategoryId) ' Check if this category has associated classes ' Create a result set file 'FileName = "C:\temp\" + CategoryName 'Open FileName For Output Access Write As #1 ' Generate the set and get methods for each class in the category WorkOnCategory selectedCategory, "" MsgBox "Attributes have been rebuild for this category. See viewport for details.",,"Operation Complete" End If End Select End Function Public Function displayDialog As Integer Dim categories() As String Dim currentCategory As Category Dim Status As String ' Define and extract all teh categories from the model Dim allCategories As CategoryCollection Set allCategories = RoseApp.CurrentModel.GetAllCategories () 'Craete a basic dialog box Begin Dialog CategoryDialog ,,260,60,"Rebuild Attributes",.DialogLoop PushButton 210,8,40,14,"Rebuild",.GoBtn CancelButton 210,28,40,14 Text 12,24,80,8,"Category",.Label DropListBox 48,24,150,80,Categories$,.CategoryListBox End Dialog Dim MyDialog As CategoryDialog ' Redimension the categories array and construct the drop down box ReDim Categories$ (AllCategories.Count) CreateBrowserCategoriesArray RoseApp.CurrentModel.RootCategory, Categories, 1, 0 While TRUE result% = Dialog (MyDialog) Select Case result% ' Cancel Btn Clicked Case 0 End End Select WEnd End Function Sub WorkOnCategory (theCat As Category, offset As String) Dim catsInCat As CategoryCollection Print offset + "+" + theCat.name Set catsInCat = theCat.Categories WorkOnClasses theCat, offset For cat% = 1 To catsInCat.Count WorkOnCategory catsInCat.GetAt(cat%), offset + " " Next cat% End Sub Sub Main Viewport.open result% = displayDialog 'Dim theCats As CategoryCollection 'Set theCats = RoseApp.CurrentModel.GetSelectedCategories 'For i% = 1 To theCats.Count ' WorkOnCategory theCats.getAt(i%), "" 'Next i% End Sub