model merging [message #1007653] |
Wed, 06 February 2013 16:45  |
Eclipse User |
|
|
|
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 #1009270 is a reply to message #1008988] |
Thu, 14 February 2013 14:50   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Re: model merging [message #1010024 is a reply to message #1009810] |
Sat, 16 February 2013 04:43  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.26560 seconds