Chapter 3 Getting Started with Objects Manipulation Using Scripts


Extending the Metamodel Using Scripts

When you import a file using scripts, you can import as extended attributes or extended collections some properties that may not correspond to standard attributes. In the following example, we:

Example

If not ExistingModel Is Nothing Then
   ' Creating a new extended model definition
   Dim ModelExtension
   Set ModelExtension = ExistingModel.ExtendedModelDefinitions.CreateNew()
   If not ModelExtension is Nothing Then
      output "Model extension successfully created in model"
      ' Initialize model extension attributes
      ModelExtension.Name = "Extension for Import of XXX files"
      ModelExtension.Code = "importXXX"
      ModelExtension.Family = "Import"
      ' Defines a new Stereotype for the Class metaclass in the profile section
      Dim MySttp
      Set MySttp = ModelExtension.AddMetaExtension(PdOOM.Cls_Class, Cls_StereotypeTargetItem)
      If not MySttp Is Nothing Then
         output "Stereotype extension successfully created in extended model definition"
         MySttp.Name = "MyStereotype"
         MySttp.UseAsMetaClass = true   ' The stereotype will behave as a new metaclass (specific list and category in browser)
         ' Defines an extended attribute for this stereotype
         Dim MyExa
         Set MyExa = MySttp.AddMetaExtension(Cls_ExtendedAttributeTargetItem)
         If not MyExa is Nothing Then
            output "Extended Attribute successfully created in extended model definition"
            MyExa.Name = "MyAttribute"
            MyExa.Comment = "custom attribute coming from import"
            MyExa.DataType = 10  ' This corresponds to integer
            MyExa.Value = "-1"   ' This is the default value
            Set MyExa = Nothing
         End If
         ' Defines an extended collection for this stereotype
         Dim MyExCol
         Set MyExCol = MySttp.AddMetaExtension(Cls_ExtendedCollectionTargetItem)
         If not MyExCol is Nothing Then
            output "Extended collection successfully created in extended model definition"         
            MyExCol.Name = "MyCollection"
            MyExCol.Comment = "custom collection coming from import"
            MyExCol.DestinationClassKind = PdOOM.Cls_class  ' The collection can store only classes
            MyExCol.Destinationstereotype = "MyStereotype"  ' The collection can store only classes with stereotype "MyStereotype"
            Set MyExCol = Nothing
         End If
         Set MySttp = Nothing
      End If
      Set ModelExtension = Nothing
   End If
End If

 


Copyright (C) 2007. Sybase Inc. All rights reserved.