%connect and %disconnect statements (SDL script)
SDL Script Extensions for TDK:
%operation ClassA.MyOp ()
....
$ Adds ClassBInstance to the MyRole association A-------B
$ *
$ My Role
%connect "My Role", ClassBInstance
$ As above, with qualifier
%connect "My Role", ClassBInstance, ClassBInstance.GetSomeKey ()
$ As above, assuming association is bidirectional A-------B
$ 1 *
$ ARole BRole
$ automatically also %connects "ARole", ClassAInstance:
%connect BRole, ClassBInstance
$ Bidiractional association with qualifiers at both ends (e.g. qualified many to many):
%connect BRole, ClassBInstance, ClassBInstance.GetSomeKey (), GetMyKey ()
%endoperation
%operation ClassA.MyOtherOp ()
....
%disconnect "My Role", ClassBInstance
%endoperation
%connect creates a link from one object to another, belonging to the association specified by the role expression. Roles can be bare words or literals, they follow the same rules of variable names.
%connect can be used from within on-instance class operation only. The %connect statement must mention a role (or a %list/%object attribute) defined in the generator model by the calling class.
If the association between class A and B is directed to B, the following statements are equivalent:
%connect "BRole", BInstance
%add Self->BRole, BInstance
The latter statements adds an element to the BRole attribute (%list type) of Self (an instance of A). The former statement does exactly the same. Model associations are translated to %list (=many) or %object (=one) on-instance attributes.
If the association between class A and B is bidirectional (1--1, 1--*,*--1, *--*, 0..1—1 and all the other combinations), the following statement:
%connect "BRole", BInstance
is equivalent to both of the following:
%add Self->BRole, BInstance
%add BInstance->ARole, Self
The metagenerator generates enough information for letting %connect to understand there is a reverse role to set.
Role members can be ordered lists. This corresponds to the qualifier UML concept. Regardless a qualifier is explicitly given in the model, one or both qualifier keys can be specified in the %connect statement, the first for the direct role, the second for the reverse role:
%connect "BRole", BInstance, KeyOfBRoleList
%connect "BRole", BInstance, KeyOfBRoleList, KeyOfARoleList
%connect "BRole", BInstance, , KeyOfARoleList $ only reverse role qualifier specified here
In a similar way, %disconnect removes one or both objects from the role list(s):
%disconnect "BRole", BInstance
is equivalent to (directed association)
%remove Self->BRole, BInstance
or equivalent to (bidirectional association)
%remove Self->BRole, BInstance
%remove BInstance->ARole, Self