Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » model merging
model merging [message #1007653] Wed, 06 February 2013 21:45 Go to next message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
Hi to everyone,

I'm trying to merge two UML models in ATL:

Model1:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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:VaProfile="http:///schemas/VaProfile/_NoMJ4Gx_EeK4SYm4A9jwEQ/86" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http:///schemas/VaProfile/_NoMJ4Gx_EeK4SYm4A9jwEQ/86 ../VAMProfileCopy/psprofile.profile.uml#_Noz08Gx_EeK4SYm4A9jwEQ">
  <uml:Model xmi:id="_riNzQGSgEeKEuaD-A95eUA" name="localeUML2">
    <packageImport xmi:id="_riNzQWSgEeKEuaD-A95eUA">
      <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
    </packageImport>
    <packagedElement xmi:type="uml:Class" xmi:id="_Heyy4GShEeKEuaD-A95eUA" name="Room">
      <nestedClassifier xmi:type="uml:Class" xmi:id="_Vf7LUGShEeKEuaD-A95eUA" name="Pillar1"/>
      <nestedClassifier xmi:type="uml:Class" xmi:id="_V7Y_UGShEeKEuaD-A95eUA" name="Pillar2"/>
      <nestedClassifier xmi:type="uml:Class" xmi:id="_WYjccGShEeKEuaD-A95eUA" name="Server">
        <nestedClassifier xmi:type="uml:Class" xmi:id="_LVSGcGk6EeKqn4ij9uqv2g" name="HardDisk"/>
      </nestedClassifier>
    </packagedElement>
    <profileApplication xmi:id="_riNzQmSgEeKEuaD-A95eUA">
      <eAnnotations xmi:id="_riNzQ2SgEeKEuaD-A95eUA" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/schemas/Standard/1#/"/>
      </eAnnotations>
      <appliedProfile href="pathmap://UML_PROFILES/Standard.profile.uml#_0"/>
    </profileApplication>
    <profileApplication xmi:id="_zAZcEGSgEeKEuaD-A95eUA">
      <eAnnotations xmi:id="_zAdtgGSgEeKEuaD-A95eUA" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="../VAMProfileCopy/psprofile.profile.uml#_Noz08Gx_EeK4SYm4A9jwEQ"/>
      </eAnnotations>
      <appliedProfile href="../VAMProfileCopy/psprofile.profile.uml#_g3R-UCp7EeK9bM-qugGxvg"/>
    </profileApplication>
  </uml:Model>
  <VaProfile:Object xmi:id="_ZeXr8GSjEeKEuaD-A95eUA" base_Classifier="_Vf7LUGShEeKEuaD-A95eUA" location="_fZfmkGSjEeKEuaD-A95eUA"/>
  <VaProfile:Object xmi:id="_beLnkGSjEeKEuaD-A95eUA" base_Classifier="_V7Y_UGShEeKEuaD-A95eUA" location="_fZfmkGSjEeKEuaD-A95eUA"/>
  <VaProfile:Object xmi:id="_c5Ll8GSjEeKEuaD-A95eUA" base_Classifier="_WYjccGShEeKEuaD-A95eUA" location="_fZfmkGSjEeKEuaD-A95eUA"/>
  <VaProfile:Site xmi:id="_fZfmkGSjEeKEuaD-A95eUA" base_Classifier="_Heyy4GShEeKEuaD-A95eUA"/>
  <VaProfile:Object xmi:id="_TkduYGk6EeKqn4ij9uqv2g" base_Classifier="_LVSGcGk6EeKqn4ij9uqv2g" location="_fZfmkGSjEeKEuaD-A95eUA"/>
</xmi:XMI>


and Model2:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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:VaProfile="http:///schemas/VaProfile/_NoMJ4Gx_EeK4SYm4A9jwEQ/86" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http:///schemas/VaProfile/_NoMJ4Gx_EeK4SYm4A9jwEQ/86 ../VAMProfileCopy/psprofile.profile.uml#_Noz08Gx_EeK4SYm4A9jwEQ">
  <uml:Model xmi:id="_IkOT4HBoEeKcgp_s5TSrqg" name="protections">
    <packagedElement xmi:type="uml:Class" xmi:id="_IkOT4XBoEeKcgp_s5TSrqg" name="_OB0ToGSkEeKEuaD-A95eUA"/>
    <packagedElement xmi:type="uml:Class" xmi:id="_IkOT5HBoEeKcgp_s5TSrqg" name="_PQeYsGpCEeK6StkFpCf91Q"/>
    <profileApplication xmi:id="_IkOT5XBoEeKcgp_s5TSrqg">
      <eAnnotations xmi:id="_IkOT5nBoEeKcgp_s5TSrqg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="../VAMProfileCopy/psprofile.profile.uml#_Noz08Gx_EeK4SYm4A9jwEQ"/>
      </eAnnotations>
      <appliedProfile href="../VAMProfileCopy/psprofile.profile.uml#_g3R-UCp7EeK9bM-qugGxvg"/>
    </profileApplication>
  </uml:Model>
  <VaProfile:Sensor xmi:id="_IkOT53BoEeKcgp_s5TSrqg" base_Classifier="_IkOT4XBoEeKcgp_s5TSrqg" cost="100.0"/>
  <VaProfile:Sensor xmi:id="_IkOT6HBoEeKcgp_s5TSrqg" base_Classifier="_IkOT5HBoEeKcgp_s5TSrqg" cost="200.0"/>
</xmi:XMI>


More precisely I'm trying to pickup all classes and stereotypes from model2 and put them into model1.

At first I tried to figure it out with a refinement approach but I faced the problem to use the resolveTemp in an action block, but action blocks are forbidden in refinement mode.

Then I tryied a copy approach, generating all the elements needed and assigning them the values properly, but I faced a problem when managing nested elements.

I read this post http://www.eclipse.org/forums/index.php/m/989963/
where I noticed this sentence:

"In ATL, you can set references between elements from different models as long as these references are not containment references."

Than I'm a bit stuck and I don't know if my problam as a solution or I'm not able to find out one.
I don't know which approach follow and how to do.

I hope you can help me,

Claudio


Re: model merging [message #1007917 is a reply to message #1007653] Fri, 08 February 2013 08:10 Go to previous messageGo to next message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
up
Re: model merging [message #1007953 is a reply to message #1007917] Fri, 08 February 2013 13:08 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Do you have things to really merge ? Like two times the same Class ?
In this case you'd rather do that in EMF directly.
Re: model merging [message #1008027 is a reply to message #1007953] Fri, 08 February 2013 15:05 Go to previous messageGo to next message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
Thanks for the reply,

I really have things to merge.

As I explained, I have classes and stereotypes in model2 that are not present in model1. I would like to have those classes from model2 inserted in model1. Is it possible to do this in ATL?

Thaks in advance,

Claudio.
Re: model merging [message #1008068 is a reply to message #1008027] Fri, 08 February 2013 17:27 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Are things present in both models and should then become one single thing ? That's a real merge operation otherwise it's just a "sum" of the two models.
Re: model merging [message #1008114 is a reply to message #1008068] Sat, 09 February 2013 08:46 Go to previous messageGo to next message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
Thanks for your reply,

only the profile application is the same for both models. For the rest they are tipically different classes. Does this make any difference from the ATL point of view?

Thanks in advance,

Claudio Persico
Re: model merging [message #1008164 is a reply to message #1008114] Mon, 11 February 2013 08:42 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Do that with the UML2 APIs then it will me much simpler.
Re: model merging [message #1008769 is a reply to message #1008114] Wed, 13 February 2013 20:25 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Op 09-02-13 09:46, Claudio Persico schreef:
> Thanks for your reply,
>
> only the profile application is the same for both models. For the rest they
> are tipically different classes. Does this make any difference from the ATL
> point of view?
>
> Thanks in advance,
>
> Claudio Persico

You need to specify which element to copy into your output model in case there
are duplicates (i.e. occurrences in both input models).

In addition, copying stereotype applications is hard. EMFTVM makes this a bit
easier by allowing reflective copying of stereotype applications. That way you
can use a standard UML copy transformation:

http://soft.vub.ac.be/viewvc/UML2CaseStudies/uml2cs-transformations/transformations/UML2Copy.atl?view=markup

Note that the above transformation copies only a single input model. You'll
need to adapt each rule (by search-and-replace) to look like this:

rule Comment {
from s : UML2!"uml::Comment" (thisModule.inElements->includes(s))
...
}

and define thisModule.inElements like so:

helper def : inElements : Set(UML2!"ecore::EObject") =
UML2!"ecore::EObject".allInstancesFrom('IN')->union(
UML2!"ecore::EObject".allInstancesFrom('IN2'))->asSet();

This way, the transformation copies all elements from IN and IN2, but not PROFILE.

Regards,
Dennis


Cheers,
Dennis
Re: model merging [message #1008988 is a reply to message #1008769] Thu, 14 February 2013 08:57 Go to previous messageGo to next message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
Thank you for your reply,

I'm trying to make it works with EMFTVM as Dennis nicely suggested. I successfully copied my classes from IN2 in IN1 but they appear outside the uml:model.

I would like to have classes from model 2 (IN2) belonging to uml:model of model 1 (IN1). Tipically I do this whit a resolveTemp, but this time I'm not able to do this.

Any suggestion?

Thank you in advance.

Claudio
Re: model merging [message #1009258 is a reply to message #1008164] Thu, 14 February 2013 19:17 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Op 11-02-13 09:42, Sylvain EVEILLARD schreef:
> Do that with the UML2 APIs then it will me much simpler.

I suppose this is what you meant:

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.uml2.doc%2Freferences%2Fjavadoc%2Forg%2Feclipse%2Fuml2%2Fuml%2Futil%2FUMLUtil.PackageMerger.html

That looks like a boxed solution to merge two packages (or models). Definitely
worth a try.

Dennis


Cheers,
Dennis
Re: model merging [message #1009270 is a reply to message #1008988] Thu, 14 February 2013 19:50 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Op 14-02-13 09:57, Claudio Persico schreef:
> Thank you for your reply,
>
> I'm trying to make it works with EMFTVM as Dennis nicely suggested. I
> successfully copied my classes from IN2 in IN1 but they appear outside the
> uml:model.
> I would like to have classes from model 2 (IN2) belonging to uml:model of
> model 1 (IN1). Tipically I do this whit a resolveTemp, but this time I'm not
> able to do this.
>
> Any suggestion?
>
> Thank you in advance.
>
> Claudio

So you indeed have duplicates which need sorting out:

- The two UML2!Model elements at the root of each model
- Each UML2!Package with the same (qualified) name in each model

You need to adapt your inElements helper and the Model and Package rules for this:

uses lib::UML2; -- get this from
http://soft.vub.ac.be/viewvc/UML2CaseStudies/uml2cs-transformations/transformations/lib/UML2.atl?view=markup

helper def : inElements : Set(UML2!"ecore::EObject") =
UML2!"ecore::EObject".allInstancesFrom('IN')->union(
UML2!"ecore::EObject".allInstancesFrom('IN2')->select(e |
e.from('IN').oclIsUndefined()))->asSet();

helper context UML2!"ecore::EObject" def : from(model : String) :
UML2!"ecore::EObject" =
OclUndefined; -- base case: equivalent EObjects cannot be found back

helper context UML2!"uml::Package" def : from(model : String) :
UML2!"uml::Package" =
let packs : Sequence(UML2!"uml::Package") =
UML2!"uml::Package".allInstancesFrom(model)->select(p |
p.umlQualifiedName = self.umlQualifiedName)
in
if packs->isEmpty() then
OclUndefined
else
packs->first()
endif;

helper context UML2!"uml::Model" def : from(model : String) : UML2!"uml::Model" =
UML2!"uml::Model".allInstancesFrom(model)->first();

rule Model {
from s : UML2!"uml::Model" (thisModule.inElements->includes(s))
using {
s2 : UML2!"uml::Model" = s.from('IN2');
}
to t : UML2!"uml::Model" (
__xmiID__ <- s.__xmiID__,
name <- s.name,
visibility <- s.visibility,
viewpoint <- s.viewpoint,
eAnnotations <- s.eAnnotations,
ownedComment <- s.ownedComment,
clientDependency <- s.clientDependency,
nameExpression <- s.nameExpression,
elementImport <- s.elementImport,
packageImport <- s.packageImport,
ownedRule <- s.ownedRule,
templateParameter <- s.templateParameter,
templateBinding <- s.templateBinding,
ownedTemplateSignature <- s.ownedTemplateSignature,
packageMerge <- s.packageMerge,
packagedElement <- s.packagedElement->union(
if s2.oclIsUndefined() then
Sequence{}
else
s2.packagedElement->select(e | thisModule.inElements->includes(e))
endif),
profileApplication <- s.profileApplication)
}

rule Package {
from s : UML2!"uml::Package" in IN (s.oclIsTypeOf(UML2!"uml::Package")
and thisModule.inElements->includes(s))
using {
s2 : UML2!"uml::Package" = s.from('IN2');
}
to t : UML2!"uml::Package" (
__xmiID__ <- s.__xmiID__,
name <- s.name,
visibility <- s.visibility,
eAnnotations <- s.eAnnotations,
ownedComment <- s.ownedComment,
clientDependency <- s.clientDependency,
nameExpression <- s.nameExpression,
elementImport <- s.elementImport,
packageImport <- s.packageImport,
ownedRule <- s.ownedRule,
templateParameter <- s.templateParameter,
templateBinding <- s.templateBinding,
ownedTemplateSignature <- s.ownedTemplateSignature,
packageMerge <- s.packageMerge,
packagedElement <- s.packagedElement->union(
if s2.oclIsUndefined() then
Sequence{}
else
s2.packagedElement->select(e | thisModule.inElements->includes(e))
endif),
profileApplication <- s.profileApplication)
}

Here I've just started with packagedElement, but you may want to merge/filter
other containment references as well (e.g. profileApplication).

Regards,
Dennis


Cheers,
Dennis
Re: model merging [message #1009530 is a reply to message #1009270] Fri, 15 February 2013 09:28 Go to previous messageGo to next message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
Thank you so much for your reply and efforts,

The UML2 API java are the last resort to me. I will try them lastly.

Meanwhile I've made this changes:

1) added libraries UML2 and Strings (referenced by UML2)
2) commented previous rules Model and Package
3) added new rules Model and Package you provided (thanks again)
4) modified helpers you provided because they give me an error. I think this is because the name of the helpers if "from", that is a keyword, so I modified this in "comesFrom" in the helper and obviously in all callings (is this correct?)

Now It gives me this error:

org.eclipse.m2m.atl.emftvm.util.VMException: java.lang.UnsupportedOperationException: UML2!Class::comesFrom(#native!java.lang.String)
at static EMFTVM!ExecEnv::inElements: Set (staticValue: null)@0#2(platform:/resource//ecore2locale/UML2Copy.atl#[207:116-207:133])
	Local variables: [e = _OB0ToGSkEeKEuaD-A95eUA:UML2!Class]
at public org.eclipse.m2m.atl.emftvm.util.LazyList org.eclipse.m2m.atl.emftvm.util.LazyList.select(org.eclipse.m2m.atl.emftvm.CodeBlock)
	Local variables: []
at static EMFTVM!ExecEnv::inElements: Set (staticValue: null)#9(platform:/resource//ecore2locale/UML2Copy.atl#[207:2-207:163])
	Local variables: []
at rule Model@matcher#3(platform:/resource//ecore2locale/UML2Copy.atl#[229:4-229:40])
	Local variables: [s: UML2!uml::Model = protections:UML2!Model]
at static EMFTVM!ExecEnv::main() : Object(platform:/resource//ecore2locale/UML2Copy.atl)
	Local variables: []


But I don't understand what this means.
Have I made something wrong?

Thank you in advance,

Claudio
Re: model merging [message #1009810 is a reply to message #1009530] Fri, 15 February 2013 19:10 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Op 15-02-13 10:28, Claudio Persico schreef:
> Thank you so much for your reply and efforts,
>
> The UML2 API java are the last resort to me. I will try them lastly.
>
> Meanwhile I've made this changes:
>
> 1) added libraries UML2 and Strings (referenced by UML2)
> 2) commented previous rules Model and Package
> 3) added new rules Model and Package you provided (thanks again)
> 4) modified helpers you provided because they give me an error. I think this
> is because the name of the helpers if "from", that is a keyword, so I modified
> this in "comesFrom" in the helper and obviously in all callings (is this
> correct?)
>
> Now It gives me this error:
>
>
> org.eclipse.m2m.atl.emftvm.util.VMException:
> java.lang.UnsupportedOperationException:
> UML2!Class::comesFrom(#native!java.lang.String)
> at static EMFTVM!ExecEnv::inElements: Set (staticValue:
> null)@0#2(platform:/resource//ecore2locale/UML2Copy.atl#[207:116-207:133])
> Local variables: [e = _OB0ToGSkEeKEuaD-A95eUA:UML2!Class]
> at public org.eclipse.m2m.atl.emftvm.util.LazyList
> org.eclipse.m2m.atl.emftvm.util.LazyList.select(org.eclipse.m2m.atl.emftvm.CodeBlock)
>
> Local variables: []
> at static EMFTVM!ExecEnv::inElements: Set (staticValue:
> null)#9(platform:/resource//ecore2locale/UML2Copy.atl#[207:2-207:163])
> Local variables: []
> at rule
> Model@matcher#3(platform:/resource//ecore2locale/UML2Copy.atl#[229:4-229:40])
> Local variables: [s: UML2!uml::Model = protections:UML2!Model]
> at static EMFTVM!ExecEnv::main() :
> Object(platform:/resource//ecore2locale/UML2Copy.atl)
> Local variables: []
>
>
> But I don't understand what this means.
> Have I made something wrong?
>
> Thank you in advance,
>
> Claudio

Ah yes, I remember! UML2 got refactored such that its metaclasses no longer
inherit from EObject. You'll need to rewrite your helpers to use OclAny where
you specified EObject before (I called them equivFrom now):

helper context OclAny def : equivFrom(model : String) : OclAny =
OclUndefined; -- base case: equivalent EObjects cannot be found back

helper context UML2!"uml::Package" def : equivFrom(model : String) :
UML2!"uml::Package" =
let packs : Sequence(UML2!"uml::Package") =
UML2!"uml::Package".allInstancesFrom(model)->select(p |
p.umlQualifiedName = self.umlQualifiedName)
in
if packs->isEmpty() then
OclUndefined
else
packs->first()
endif;

helper context UML2!"uml::Model" def : equivFrom(model : String) :
UML2!"uml::Model" =
UML2!"uml::Model".allInstancesFrom(model)->first();

Dennis


Cheers,
Dennis
Re: model merging [message #1010024 is a reply to message #1009810] Sat, 16 February 2013 09:43 Go to previous message
Claudio Persico is currently offline Claudio PersicoFriend
Messages: 24
Registered: November 2012
Junior Member
This post is only to thank everyone who helped me. I finally got the transformation works.

I also modified the ApplyStereotypes rule to appear like this:

lazy rule ApplyStereotypes {
	from
		--s: UML2!"uml::Element" in IN
		s: UML2!"uml::Element" (thisModule.inElements -> includes(s))
	using {
		t: UML2!"uml::Element" = s.resolve();
	}
	do {
		for (st in s.getAppliedStereotypes()) {
			t.applyStereotype(st);
			for (a in st.getAllAttributes()) {
				if (not a.name.startsWith('base_') and s.hasValue(st, a.name)) {
					t.setValue(st, a.name, s.getValue(st, a.name));
				}
			}
		}
	}
}



Thank you again, in particular to Dennis.
Claudio
Previous Topic:I need some help in ATL transformation when use KDM
Next Topic:Using external parameters in ATL
Goto Forum:
  


Current Time: Tue Apr 16 21:03:01 GMT 2024

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

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

Back to the top