Model transformation primitives
Overview
Model transformation primitives are used to:
· create a metaclass instance
· add a link
· destroy an element
· delete a link
· sort part of the model (for example, the attributes of a class)
It is possible, for example, to create a class, name it and add methods with parameters, using MDA Modeler.
Low level primitives
|
The primitive ... |
is used to ... |
example ... |
|
new |
create an element |
... creation of a class (*) Class C; C = Class.new; |
|
set<AttributeName> |
assign the value of an attribute. |
C.setName("client"); C.setVisibility(Public); |
|
append<RoleName> |
create a link in the metamodel |
M :Operation ;... C.appendPart(M); ...add an operation to a class |
|
delete |
destroy an element. Its links are updated and its components are
destroyed. This primitive modifies the Objecteering model at
the root. Its consequences are
irreversible. It should only,
therefore, be used advisedly. To delete an object from a diagram, the "erase<RoleName>" method should be used (see next line). |
C.delete; ...destruction of C and its components (therefore M) |
|
erase<RoleName> |
destroy a link |
C.erasePart(M); ...deletes the link between the C class and the M operation (note : M is not destroyed) |
|
sortSemanticAssociation(in String pSortedRoleName, in boolean pAscendingSort) |
sort elements accessible from the current object, through the pSortedRoleName role. Elements are sorted according to their names. Elements with no name are not handled. This primitive requires a persistent J session. |
currentPackage.sortSemantic Association ("OwnedNameSpace", true) ...sorts the accessible objects by name through the "OwnedNameSpace" role from the "currentPackage" package. |
(*): it is necessary to attach this class to a project, so that the creation be definite.
Example
We are going
to create accessors with "set<AttributeName>" and
"get<AttributeName>" for each class attribute.
Note: The "addAccessor" command on a class is used to execute the program below.
Class#addAccessor
{
Operation M;
Parameter P;
Class C;
sessionBegin ("addAccessor", true);
C = this;
PartAttribute
{
M = Operation.new;
M.setName("set_" + Name);
C.appendPart(M);
P=Parameter.new;
P.setName("AttValue");
M.appendIO(P);
M = Operation.new;
M.setName("get_" + Name);
C.appendPart(M);
P = Parameter.new;
P.setName("R");
M.appendReturn(P);
}
sessionEnd();