'Author: Martha Andrews ' Rational Technical Support 'Date: May, 1999 'Purpose: 'In Rose 98, it was possible to set the Module Specification property AdditionalImports 'to generate import statements in a .java file. 'In Rose 98i, the AdditionalImports property is no longer used. So, the imports are not added when 'the .java file is generated 'This script cycles through all modules in the model and gets the import statements listed in the 'AdditionalImports property for each. It then creates dependency relations which will resolve to import 'statements when code is generated. 'Limitations: 'Each class must have a module assigned to it to get the additional imports 'This script works only for import statements that reference an entire package (i.e. end in '*') 'a good enhancement would be to make it work for import statements that reference only 1 class 'To run the script, follow these steps: '1. Make a backup copy of the model that you want to update '2. Start Rose '3. Load the model you want to update '4. Choose Tools|Open Script from the main menu '5. Choose the .ebs file from the Open File dialog '6. Click on the green arrow or select Debugger|Go to run the script Sub Main Dim theModel As model Set theModel = RoseApp.CurrentModel Dim defaultProps As DefaultModelProperties Set defaultProps = theModel.DefaultProperties Dim javaProps As PropertyCollection ' Get all modules in model Dim startingModules As ModuleCollection Set startingModules = theModel.GetAllModules Dim currentModule As Module Dim importArray() As String Dim currentComponentPkg As Subsystem Dim theSubsystems As SubsystemCollection Dim theRelation As ModuleVisibilityRelationship Viewport.open For startingModIndex = 1 To startingModules.Count 'Get currentModule Set currentModule = startingModules.GetAt(startingModIndex) 'Get the AdditionalImports theImports$ = currentModule.GetPropertyValue("Java", "AdditionalImports") 'Parse the Imports Call getIndividualImportStatements(theImports$, importArray()) 'after parsing ImportArray holds separate import statements For importStatementCount = 1 To UBound(importArray) importString$ = importArray(importStatementCount) 'get rid of first seven characters extendedPackageName$ = Trim( Right$(importString$, (Len(importString$)-7))) indexOfPkgNameStart% = 1 ' start with the component view Set currentComponentPkg = theModel.RootSubsystem For indexOfCurrentLetter% =1 To Len(extendedPackageName) If Mid(extendedPackageName, indexOfCurrentLetter%, 1) = "." Then ' get portion between periods importPackageName$ = Mid (extendedPackageName, (indexOfPkgNameStart), (indexOfCurrentLetter - indexOfPkgNameStart)) 'the next package name will start after this period indexOfPkgNameStart =indexOfCurrentLetter+1 'find the package in the model, or make it Set theSubsystems =currentComponentPkg.GetAllSubsystems() If theSubsystems.FindFirst( importPackageName$) Then 'package exists subsystemForImportPackage = theSubsystems.GetFirst(importPackageName$) Else 'package does not exist, so make it subsystemForImportPackage = currentComponentPkg.AddSubsystem(importPackageName$) End If Set currentComponentPkg = subsystemForImportPackage End If If Mid(extendedPackageName, indexOfCurrentLetter%, 1) = "*" Then Print "Adding import for " & importPackageName$ & " to " & currentModule.name ' add dependency from currentModule's parent to innermost subsystem Set theRelation = currentModule.parentSubsystem.AddSubsystemVisibilityRelationship(subsystemForImportPackage) 'add dependency from currentModule to the innermost subsystem Set theRelation = currentModule.AddSubsystemVisibilityRelationship(subsystemForImportPackage) End If Next indexOfCurrentLetter Next importStatementCount Next startingModIndex End Sub '--------------------------------------------------------------- Sub getIndividualImportStatements (imports As String, outputArray() As String) 'each import statement ends in a ';' 'this method divides the import string into separate strings, using ';' as a divider , 'then, it fills the outputArray with the import statements and return the outputArray 'index into array that holds individual import statements Dim importStatementCount As Integer importStatementCount = 1 ReDim outputArray (1 To 100) lowerbound% =1 For indexIntoString% = 1 To Len(imports) If Mid(imports,indexIntoString%,1) = ";" Then tempString$ = Mid ((Left (imports, indexIntoString%)), lowerbound% , indexIntoString%) outputArray(importStatementCount ) = tempString$ 'two characters after this will be beginning of next import 'preserve that index for next time through loop lowerbound% =indexIntoString +2 importStatementCount = importStatementCount+1 End If Next ReDim Preserve outputArray(importStatementCount-1) End Sub '--------------------------------------------