I want to use Tefkat to migrate my models so that they conform to a
new metamodel version. Let's say from one metamodel version to the
next most of the metamodel elements stay the same.
Is there a mechanism to copy most of the input model and specify only
the elements to transform?
Thanks in advance.
Markus Herrmannsdörfer
TRANSFORMATION copy : src -> tgt
IMPORT http://www.eclipse.org/emf/2002/Ecore
CLASS ObjToObj {
EObject src;
EObject tgt;
};
RULE copy(s, t)
FORALL _ s
MAKE EXACT $s.eClass() t
LINKING ObjToObj WITH src = s, tgt = t
;
RULE copyAttributes(s, t, a)
WHERE ObjToObj LINKS src = s, tgt = t
AND s.eClass() = c
AND c.eAllAttributes = a
AND a.changeable = true // skip read-only attributes
AND s.eIsSet(a) = true // and those with default values
AND v = s.$a
SET t.$a = v
;
RULE copyReferences(s, t, r)
WHERE ObjToObj LINKS src = s, tgt = t
AND s.eClass() = c
AND c.eAllReferences = r
AND r.changeable = true
AND s.eIsSet(r) = true
AND v = s.$r
AND ObjToObj LINKS src = v, tgt = tv
SET t.$r = tv
;
For the special-case elements you'll need a mechanism to disable the
generic rules. For example:
CLASS AlreadyCopied {
EObject src;
};
RULE copy(s, t)
FORALL _ s
WHERE NOT AlreadyCopied src = s
MAKE EXACT $s.eClass() t
LINKING ObjToObj WITH src = s, tgt = t
;
And you'll probably need to use the NAMESPACE declarations (rather
than the old IMPORT) to avoid ambiguities due to duplicate class
names:
NAMESPACE old http://model-1.ecore
NAMESPACE new http://model-2.ecore
RULE specialCase
FORALL old^Class cOld
WHERE comeCondition(c)
MAKE new^Class cNew
LINKING ObjToObj WITH src = oldC, tgt = newC
LINKING AlreadyCopied WITH src = oldC
;
Regards,
michael