Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Copy UML with Profiles(UML, Profile, QVT, QVTo, deepclone, copy)
[QVTo] Copy UML with Profiles [message #629023] Sun, 26 September 2010 10:01
Kirsten M. Z. is currently offline Kirsten M. Z.Friend
Messages: 132
Registered: July 2010
Senior Member
Hi @all,

I have a QVT transformation like this:

modeltype UML uses 'http://www.eclipse.org/uml2/3.0.0/UML';

transformation CopyUML(in umlIn : UML, out umlOut : UML);

main() {
    umlIn.rootObjects()->deepclone();
}


The "deepclone" copies the incoming UML data perfectly (if not considering profiles).

Now please image an UML model like this (just a Pseudo-example, hopefully, I have no errors):

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:AProfile="http:///schemas/AProfile/_17z4wLG_Ed-lv6bWENUH4A/1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http:///schemas/AProfile/_17z4wLG_Ed-lv6bWENUH4A/1 ../../AProfile/model/AProfile.profile.uml#_170f0LG_Ed-lv6bWENUH4A">
  <uml:Model xmi:id="_qb8akM37EdqwVrslYOdUDA">
    <profileApplication xmi:id="_W8q33cl2Ed-scY4ABJH6aA">
      <eAnnotations xmi:id="_W8q33sl2Ed-scY4ABJH6aA" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="../../AProfile/model/AProfile.profile.uml#_170f0LG_Ed-lv6bWENUH4A"/>
      </eAnnotations>
      <appliedProfile href="../../AProfile/model/AProfile.profile.uml#_XkGiwB07Ed-QQ4mYkrb7Gg"/>
    </profileApplication>
  </uml:Model>
  <AProfile:AStereoType xmi:id="_2QTfQLR2Ed-ziokMYBQHfA" base_Model="_qb8akM37EdqwVrslYOdUDA"/>
</xmi:XMI>


The problem is the "copied" result:

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:AProfile="http:///schemas/AProfile/_17z4wLG_Ed-lv6bWENUH4A/1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http:///schemas/AProfile/_17z4wLG_Ed-lv6bWENUH4A/1 ../../AProfile/model/AProfile.profile.uml#_170f0LG_Ed-lv6bWENUH4A">
  <uml:Model xmi:id="_B7XAkMlREd-eUuo2OtWjMg">
    <profileApplication xmi:id="_ot6r4KbOEd-XsKyHUt7WaA">
      <eAnnotations xmi:id="_ot6r4abOEd-XsKyHUt7WaA" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="../../AProfile/model/AProfile.profile.uml#_170f0LG_Ed-lv6bWENUH4A"/>
      </eAnnotations>
      <appliedProfile href="../../AProfile/model/AProfile.profile.uml#_XkGiwB07Ed-QQ4mYkrb7Gg"/>
    </profileApplication>
  </uml:Model>
  <AProfile:AStereoType xmi:id="_H2aIp5lZep-tUu44KeXjGv">
    <base_Model href="incomingUML.uml#_qb8akM37EdqwVrslYOdUDA"/>
  <AProfile:AStereoType />
</xmi:XMI>


As you can see, the applied stereotypeis references the "Model"-element in the incoming/source UML model.

Somehow, I can reconstruct what happened. Seems that each "root"-object is deep-cloned individually, so the "Stereotype"-element does not know that the "Model"-element has been copied as well, so it keeps the reference to the original "Model"-element. But how can I solve this problem? I simply want a "full" copy of my UML model. (Afterwards, I will do additional things, of course).

I know that it could be a workaround to copy the UML file and perform an in-place QVT transformation (inout). However, that would be exactly the workaround, I want to elude.

------

Another very similar thing which I also do not understand. There is also a "copy" operation. Please check the following code:

main() {
  var copied := umlIn.copy();

  umlIn.rootObjects().allSubobjects()->flatten()->forEach(_class)
  {
    if (not _class.oclAsType(UML::Model).getAppliedStereotype("AProfile::AStereotype").oclIsUndefined()) then
    {
      // this code is executed
    }
    endif
  };

  copied.rootObjects().allSubobjects()->flatten()->forEach(_class)
  {
    if (not _class.oclAsType(UML::Model).getAppliedStereotype("AProfile::AStereotype").oclIsUndefined()) then
    {
      // this code is NOT executed
    }
    endif
  };
}


As you can see, the second part when analyzing the copied UML, the stereotype cannot be found any more.

However, when debugging and checking the "locals", I can actually see that the whole UML is copied including the stereotypes! The copied stereotypes even get the correct (cloned) reference?

------

Offtopic - the dark secrets of main():

I have read many QVTo tutorials. Especially, the tutorials from the Eclipse community. However, the "strange" main-method is never explained in detail. I understood the semantics of "mapping" (with is implicit "result" object) and most other features perfectly, but the semantics of the "main"-method is still veiled by dark clouds for me.

For example (in main):

umlIn.rootObjects()->deepclone();


The code above "creates output" in "umlOut".

umlIn.copy();


This does not "create any output" in "umlOut".

object UML::Class {};


This simple creates an class in "umlOut".

Which calls "do generate"?
Which do not?

Somehow, this is not explained in detail anywhere.

------

Best regards,
Kirsten

[Updated on: Sun, 26 September 2010 14:02]

Report message to a moderator

Previous Topic:Broken Links within RSM Diagrams to regenerated Models
Next Topic:[ATL] transformation order
Goto Forum:
  


Current Time: Wed Jun 26 10:34:41 GMT 2019

Powered by FUDForum. Page generated in 0.01880 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top