'RemoveCMPField.ebs from a CMP 2.0 Entity bean 'Workaround for defect 'Usage: 'select one <> class in the browser Option Explicit Dim CMPFieldNames() As String Dim selectedIdx As Integer Dim NumberOfFields As Integer Dim selectedClass As Class Sub CreateArray Dim theValue As String Dim i As Integer theValue = selectedClass.getpropertyvalue("Java","EJBCmpField") NumberOfFields = ItemCount(theValue,";")-1 If (NumberOfFields <=0)Then msgBox "The selected EJB has no CMP Fields, so none can be deleted!" End End If roseapp.Writeerrorlog "Property EJBCmpField of class "_ +selectedClass.getqualifiedname roseapp.writeerrorlog "Current value: "+theValue ReDim CMPFieldNames (0 To numberOfFields-1) 'the last is always empty For i = 1 To numberOfFields 'store with index from zero CMPFieldNames(i-1)=item$(theValue,i,i,";") Next i End Sub Function UserDlgProc(ControlName$, Action%, SuppValue%) If Action% = 1 Then 'set up the default choice selectedIdx = 0 DlgValue "theListBox", 0 End If If Action% = 2 And ControlName$ = "theListBox" Then selectedIdx=SuppValue% End If If Action% = 2 And ControlName$ ="OK" Then End If If Action% = 2 And ControlName$ ="Cancel" Then selectedIdx = -1 End If End Function Begin Dialog UserDialog ,,262,104,"Choose a CMP Filed to delete",.UserDlgProc OKButton 212,4,40,14 CancelButton 212,24,40,14 Text 8,4,108,8,"Available CMP Fields",.Text1 ListBox 8,20,196,72,CMPFieldNames$,.theListBox End Dialog Function TestUserSelection As class Dim themodel As model Set themodel = roseapp.currentmodel Dim theClass As class If themodel.getselectedclasses.count <> 1 Then msgbox "Select only 1 EJB class in the browser!" End Else Set theClass = themodel.getselectedclasses.getat(1) If theClass.stereotype <> "EJBEntity" Then msgbox "The selected EJB should have stereotype <>!" End End If If theClass.getPropertyValue("Java","EJBVersion") <>"2.0" Then msgbox "The selected EJB should have version 2.0!" End End If End If Set TestUserSelection = theclass End Function Sub RemoveProperty() Dim theValue As String Dim i As Integer Dim isoverridden As Boolean theValue = "" For i = 0 To NumberOfFields-1 If(i<>selectedIdx) Then thevalue = thevalue +CMPFieldnames(i)+";" End If Next i roseapp.Writeerrorlog "Overriding property EJBCmpField of class "_ +selectedClass.getqualifiedname roseapp.writeerrorlog "To new value: "+theValue isoverridden = selectedClass.overrideproperty _ ("Java","EJBCmpField",theValue) End Sub Sub CleanGettersAndSetters(theClass As Class, theStereotype As String) Dim theOp As operation Dim thegetter As operation Dim theSetter As operation Dim i As Integer Dim isdeleted As Boolean Dim getterName As String Dim setterName As String Dim theName As String theName = CMPFieldNames(selectedIdx) getterName = "get"+ Ucase$(Left(theName,1))+Right(theName,Len(theName)-1) setterName = "set"+ Ucase$(Left(theName,1))+Right(theName,Len(theName)-1) For i = 1 To theClass.operations.count Set theOp = theClass.operations.getAt(i) If (theOp.name = getterName And theOp.stereotype=theStereotype) Then Set theGetter = theOp End If If (theOp.name = setterName And theOp.stereotype=theStereotype) Then Set thesetter = theOp End If Next i If Not(thesetter Is Nothing) Then roseapp.writeerrorlog "Deleting operation: "+theSetter.getqualifiedname isDeleted = theClass.deleteOperation(theSetter) End If If Not(theGetter Is Nothing) Then roseapp.writeerrorlog "Deleting operation: "+theGetter.getqualifiedname isDeleted = theClass.deleteOperation(theGetter) End If End Sub Function FindRemoteInterface() As Class Dim theinterface As class Dim col As ClassdependencyCollection Dim theDep As Classdependency Dim theclient As class Dim i As Integer Set col = selectedClass.GetClassDependencies ( ) Set theInterface = Nothing For i = 1 To col.count Set theDep = col.getat(i) Set theclient = thedep.getSupplierClass If (theclient.stereotype = "EJBRemoteInterface" _ And thedep.stereotype="EJBRealizeRemote") Then Set theInterface = theclient End If Next i Set FindRemoteInterface = theInterface End Function Function FindLocalInterface() As Class Dim theinterface As class Dim col As ClassdependencyCollection Dim theDep As Classdependency Dim theclient As class Dim i As Integer Set col = selectedClass.GetClassDependencies ( ) Set theInterface = Nothing For i = 1 To col.count Set theDep = col.getat(i) Set theclient = thedep.getSupplierClass If (theclient.stereotype = "EJBLocalInterface" _ And thedep.stereotype="EJBRealizeLocal") Then Set theInterface = theClient End If Next i Set FindLocalInterface = theInterface End Function Sub deleteField 'remove the property Call Removeproperty() 'remove the getter and setter from the local or remote interface and the bean Dim theLocalInterface As class, theRemoteInterface As class Set theLocalInterface = FindLocalInterface() If Not(theLocalInterface Is Nothing) Then Call CleanGettersAndSetters(selectedClass,"EJBLocalMethod") Call CleanGettersAndSetters(theLocalInterface,"EJBLocalMethod") End If Set theremoteInterface = FindRemoteInterface() If Not(theremoteInterface Is Nothing) Then Call CleanGettersAndSetters(selectedClass,"EJBRemoteMethod") Call CleanGettersAndSetters(theRemoteInterface,"EJBRemoteMethod") End If End Sub Sub Main Set selectedClass = TestUserSelection() Call CreateArray() Dim inputDialog As UserDialog Dim r As Integer r = Dialog(inputDialog) If (selectedIdx <> -1 ) Then Call DeleteField() End If End Sub