%promote and %getbehavior statements (SDL script)
This topic applies to TDK SDL script extensions. For more information, see Overview of SDL script extensions for TDK (SDL script).
SDL Script Extensions for TDK:
%for %search ("", "Class", "Proxy")
%promote %c, "TProxyClass"
%endfor
%for %search ("", "Class", "Active")
%promote %c, "TActiveClass"
%endfor

%for %search ("", "Class")
%m %red %c:Name & " is a Class but has the behavior of " & %getbehavior (%c)
%endfor
%promote dynamically changes the type of an object. Because %promote is executed on a given object, that object acquires the behavior of the (generator model) class whose name is specified as the second argument.
%promote is of paramount importance in designing model-to-model transformations. By using %promote, it is possible to assign specified behaviors (sets of attributes and operations) to selected objects in such a way they can handle specific generation situations.
%promote works both on instances of user defined classes of the generator model and on standard metamodel, that is application model, instances.
In the example, it is suggested that all the classes having the «Proxy» stereotype assume the behavior of TProxyClass, that is, and user defined class of the generator model. In a similar way, all classes having the «Active» stereotype assume the behavior of TActiveClass.
In such a way, passive class instances of the metamodel classes can be forced to respond to specific operation calls.
Note the example changes the behavior of instances of the metaclass Class, but it is possible to change the behavior of any metatype, such as Attribute and Operation.
%promote works on selected instances of objects. One does not need to change the behavior of a whole metaclass.
%getbehavior (<object expression>) returns a string expression containing the name of the impersonated class. If no %promote statement has been executed on the specified instance yet, %getbehavior returns the name of the metaclass the object belongs to (or the name of a user defined class if the object is an instance of that).
%getbehaviour is a synonym of %getbehavior.