'***Patrick Rutledge, Rational Support 10/98 'This script generates a component view which mirrors the logical view and 'assigns the classes to the created components. The user selects Java or C++ 'when the script is run. Function SelectLanguage As String Begin Dialog SelectLangDialog 150, 50, 100, 60,"Select a Language" OKButton 30,35,40,14 OptionGroup .LangGroup OptionButton 10, 10, 30, 12, "C++", .CPPOpt OptionButton 50, 10, 30, 12, "Java", .JavaOpt End Dialog SelectLanguage = "" Dim langDlog As SelectLangDialog r% = Dialog(langDlog) Select Case langDlog.LangGroup Case 0 SelectLanguage = "C++" Case 1 SelectLanguage = "Java" End Select End Function 'returns true if a module with this name and part exists in the subsystem Function ModuleExists (inSubsys As Subsystem, inName As String, inPart As String) As Boolean ModuleExists = False Dim aMod As Module For i% = 1 To inSubsys.Modules.Count Set aMod = inSubsys.Modules.GetAt(i%) If aMod.name = inName And aMod.Part = inPart Then ModuleExists = True Exit Function End If Next i% End Function 'takes category to duplicate in component view and subsystem which is the 'parent of subsystem to be created - yes, I know it would be cleaner 'if the function found that itself Sub ComponentsFromCat (inCat As Category, inParSubsys As Subsystem, inLang As String) Dim subsys As Subsystem Dim spec As Module Dim body As module Dim aClass As Class Dim nextCat As Category 'if it's logical view package, use component view susbsys (top level) If inCat Is RoseApp.CurrentModel.RootCategory Then 'Logical View package Set subsys = RoseApp.CurrentModel.RootSubsystem Else 'make sure it doesn't already exist Set subsys = inParSubsys.Subsystems.GetFirst(inCat.name) If subsys Is Nothing Then 'make it Set subsys = inParSubsys.AddSubsystem(inCat.name) End If End If 'make comps from classes For i% = 1 To inCat.Classes.Count Set aClass = inCat.Classes.GetAt(i%) If Not ModuleExists(subsys, aClass.name, "Specification") Then Set spec = subsys.AddModule(aClass.name) spec.Part = "Specification" spec.Type = "PackageType" spec.AssignedLanguage = inLang If inLang = "Java" Then spec.StereoType = "" 'plain component End If aClass.AddAssignedModule spec 'assign to class End If If inLang <> "Java" Then 'java doesn't use bodies If Not ModuleExists(subsys, aClass.name, "Body") Then Set body = subsys.AddModule(aClass.name) body.Part = "Body" body.Type = "PackageType" body.AssignedLanguage = inLang aClass.AddAssignedModule body 'assign to class End If End If Next i% 'recursive bit, call this procedure on child categories For j% = 1 To inCat.Categories.Count Set nextCat = inCat.Categories.GetAt(j%) ComponentsFromCat nextCat, subsys, inLang Next j% End Sub Sub Main Dim subsys As Subsystem lang$ = SelectLanguage() ComponentsFromCat RoseApp.CurrentModel.RootCategory, subsys, lang$ MsgBox "Done" End Sub