Gentlemen!
I have returned from the untamed steppe, bearing a VBScript.
P.S. The integrity check did not moan upon a scrap value I inserted in t_xref and left it as it was.
Yeah, if you don't get it right when putting stuff in t_xref EA doesn't know when it should be deleted, but it doesn't seem to care. However, generalization sets created with the enclosed code work properly in that the t_xref rows are deleted when the corresponding connectors are. They also show up correctly in a diagram. I haven't tested anything else, but nothing's obviously broken so it seems to work just fine.
A few things.
Each generalization that is part of any generalization set has its own Xref.
There are four GUIDs to keep track of: the Xref GUID, the generalization set GUID, the connector GUID and the power type GUID (optional).
The Xref GUID has to be unique of course. The generalization set GUID has to be reused if you want to add more than one generalization to a set (which in all likelihood you do, otherwise why bother with the set at all). It is stored, fairly anonymously, in t_xref.Description (the field called 'GUID'). In my case I will be creating all my generalizations top-down in one go, so I won't need to look for existing generalization set GUIDs and pull them out of the Description. For a proper implementation, this would need to be addressed.
The connector GUID goes in t_xref.Client. A generalization set has no supplier; specify '<none>'.
The power type GUID also goes in Description, in a field called 'PowerTypeGUID'.
Namespace, Requirement, Constraint and Link are left empty.
Thanks again, fellas.
/Uffe
' Creates a GUID with {}'s and strips zero string terminator.
function CreateGUID
CreateGUID = Left(CreateObject("Scriptlet.TypeLib").Guid, 38)
end function
' Inserts a generalization set row into t_xref.
sub InsertGeneralizationSetXref(xrefGuid, genSetGuid, genSetName, isCovering, isDisjoint, powerTypeGuid, connectorGuid)
Repository.Execute("insert into t_xref " & _
"(XRefID, Name, Type, Visibility, Behavior, Partition, Description, Client, Supplier) values (" & _
"'" & xrefGuid & "', " & _
"'MOFProps', 'connector property', 'Public', 'generalizationSet', '0', " & _
"'GUID=" & genSetGuid & ";Name=" & genSetName & ";IsCovering=" & isCovering &";IsDisjoint=" & isDisjoint & _
";PowerTypeGUID=" & powerTypeGuid & ";', " & "'" & connectorGuid & "', " & _
"'<none>')")
end sub
' Creates a generalization set with the specified power type, and adds the specified connector to the set.
' Returns the GUID of the newly created generalization set.
function CreateGeneralizationSet(genSetName, isCovering, isDisjoint, powerType, connector)
dim genSetGuid
genSetGuid = CreateGUID()
InsertGeneralizationSetXref CreateGUID(), genSetGuid, genSetName, isCovering, isDisjoint, powerType.ElementGUID, connector.ConnectorGUID
CreateGeneralizationSet = genSetGuid
end function
' Adds a connector to an exidsting generalization set.
' If the generalization set attributes don't match what's in the database already, I've no idea what happens.
sub AddToGeneralizationSet(genSetGuid, genSetName, isCovering, isDisjoint, powerType, connector)
InsertGeneralizationSetXref CreateGUID(), genSetGuid, genSetName, isCovering, isDisjoint, powerType.ElementGUID, connector.ConnectorGUID
end sub
' Creates a simple class hierarchy with a generalization set.
sub FlyBySeatOfPants(package)
dim parent as EA.Element
dim child1 as EA.Element
dim child2 as EA.Element
dim powerType as EA.Element
dim connector as EA.Connector
dim genSetGuid
dim xrefGuid
dim stmt
set parent = package.Elements.AddNew("Parent", "Class")
parent.Update()
set child1 = package.Elements.AddNew("Child 1", "Class")
child1.Update()
set child2 = package.Elements.AddNew("Child 2", "Class")
child2.Update()
set powerType = package.Elements.AddNew("Power Type", "Class")
powerType.Update()
package.Elements.Refresh()
set connector = child1.Connectors.AddNew("", "Generalization")
connector.SupplierID = parent.ElementID
connector.Update()
genSetGuid = CreateGeneralizationSet(powerType.Name, "0", "0", powerType, connector)
set connector = child2.Connectors.AddNew("", "Generalization")
connector.SupplierID = parent.ElementID
connector.Update()
AddToGeneralizationSet genSetGuid, powerType.Name, "0", "0", powerType, connector
end sub