Stereotypes tag values: setValue to copy tag value [message #931388] |
Wed, 03 October 2012 06:32 |
iker zeziaga Messages: 2 Registered: October 2012 |
Junior Member |
|
|
Hi,
I'm new with ATL. I'm trying to copy some UML diagrams depending on the stereotypes that have the elements in the model. Everything is fine until I try to copy all the tag values the element may have. I don't find why the target model has no value on its tags. Any idea would be helpful.
helper context UML2!Element def:setTagValue(stereotype:String, tag:String, value:UML2!EObject):UML2!Element=
if(self.getAppliedStereotypes()->select(e|e.name=stereotype)->notEmpty())
then self.setValue(self.getAppliedStereotypes()->select(f|f.name=stereotype)->first(),tag,value)
else OclUndefined
endif;
rule copy{
...
do{
for(st in s.getAppliedStereotypes()){
t.applyStereotype(st);
thisModule.inStereotype<-st;
for(tag in st.getOwnedAttributes()){
thisModule.inTag<-tag;
t.setTagValue(thisModule.inStereotype.name,thisModule.inTag.name,s.getTagValue(thisModule.inStereotype.name,thisModule.inTag.name))
}
}
}
}
if I use setTagValue with concrete or specific values, it works fine.
iker
|
|
|
Re: Stereotypes tag values: setValue to copy tag value [message #937046 is a reply to message #931388] |
Mon, 08 October 2012 15:58 |
Ronan B Messages: 273 Registered: July 2009 |
Senior Member |
|
|
Hi Iker,
I'm not sure what is wrong there. You can try my version which I have been using for a few years. It is quite similar but a little more robust. The check for the base_ property could be improved though. Anyway it works!
do
{
--apply all the profile's stereotype values to the target model. they don't get copied by ATL automatically
thisModule.applyStereoTypesValue(false,s,t);
}
--apply all the profile's stereotype values to the target model. they don't get copied by ATL automatically
rule applyStereoTypesValue(required : Boolean, s : UML!Element, t : UML!Element)
{
do
{
--loop over all the stereotypes on an element
for (stereotype in s.getAppliedStereotypes())
{
--if the UML!Element does not get its stereotype automically applied (i.e. UML not required) then we must apply it manually
--note:surprisingly the "required" property doesn't seem to be exposed by UML2. maybe look into this more
if (not required)
{
t.applyStereotype(stereotype);
}
--loop over all the stereotype's properties
for (property in stereotype.getAllAttributes())
{
--apply the value if there is one. don't apply the base type property as ATL cannot handle this. also don't touch read-only properties.
if(s.hasValue(stereotype,property.name) and (not property.name.startsWith('base_')) and not property.isReadOnly())
{
t.setValue(stereotype,property.name,s.getValue(stereotype,property.name));
}
}
}
}
}
The comments come for free
Regards,
Ronan
|
|
|
|
Powered by
FUDForum. Page generated in 0.03346 seconds