Home » Modeling » ATL » Rule transforming one element to several elements(Only one of the transformed elements is properly situated in the packages)
Rule transforming one element to several elements [message #1037257] |
Tue, 09 April 2013 10:49 |
Javier García Messages: 129 Registered: April 2013 |
Senior Member |
|
|
Hi everybody,
I'm doing an UML to UML transformation, and I run into a problem.
I will copy the problematic code at the end of the message so that you can check it out.
I have a rule that takes one element as input and produces three as output. Now this gives me two different problems:
1 - The first one is that from the three output elements that are created only one of them is generated in the proper package, the other two are created outside of the model even.
My guess is that this is caused because the elements get added in other transformations (Model to model and Package to package transformations), but I guess there should be a way to make this right.
2 - The second problem seems a bit more tricky. As you can see I have Button and transform it into PushButton, RadioButton and CheckBox, so then when the properties of my class get generated, if one of these properties was of the type Button, it gets transformed into PushButton. Now I want to make it so that, depending on the value of the attribute 'style' owned by 'Button' these properties will get transformed accordingly to one of the different kinds of buttons (RadioButton, CheckBox or PushButton) How could I do this?
I tried several things and nothing seems to work.
Thank you all in advance, hopefully someone knows how to fix this.
Regards,
Javier
rule button{
from
s: UML2!Class (
s.name = 'Button'
)
to
r: UML2!Class (
name <- 'PushButton' -> debug('PushButton'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute
),
t: UML2!Class (
name <- 'CheckBox' -> debug('CheckBox'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute
),
w: UML2!Class (
name <- 'RadioButton' -> debug('RadioButton'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute
)
do {
}
}
|
|
| |
Re: Rule transforming one element to several elements [message #1037300 is a reply to message #1037257] |
Tue, 09 April 2013 11:48 |
Gunnar Arndt Messages: 82 Registered: June 2012 |
Member |
|
|
Javier, the given rule creates all three output Buttons for each input Button; I guess you need a seperate rule for each case, maybe like this:
rule pushbutton{
from
s: UML2!Class (
s.name = 'Button' and s.style = 'Push'
)
to
r: UML2!Class (
name <- 'PushButton' -> debug('PushButton'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute
)
}
rule radiobutton{
from
s: UML2!Class (
s.name = 'Button' and s.style = 'Radio'
)
to
w: UML2!Class (
name <- 'RadioButton' -> debug('RadioButton'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute
)
}
|
|
| |
Re: Rule transforming one element to several elements [message #1037324 is a reply to message #1037314] |
Tue, 09 April 2013 12:20 |
Javier García Messages: 129 Registered: April 2013 |
Senior Member |
|
|
Hi guys,
thanks for your answers.
Gunnar, the thing is that I have a class Button, which has the attribute style, and then another class has a few parameters of the type Button, and it is on those parameters where I would need to check the attribute style, since otherwise there is only one class called Button. I hope I explained myself properly, thanks for your help.
Sylvain:
I tried that and it doesn't work, the same thing happened, I wrote it in the 'do{}' part inside the rule, maybe I'm doing something else wrong?
Also, regarding your comment about attributes and operations, I forgot to mention this before, the operations from the class Button get copied only to the class RadioButton, the other two classes are empty. Does this mean I should create the operations three times? how else could I fix this?
All in all I think transformations from one element to several are a bit confusing, and there just doesn't seem to be enough information about this.
Thanks for your help really, if you need to see some other part of the code just let me know, hopefully we can find a way to fix this.
Thanks again,
regards,
Javier
|
|
| |
Re: Rule transforming one element to several elements [message #1038063 is a reply to message #1037339] |
Wed, 10 April 2013 11:04 |
Javier García Messages: 129 Registered: April 2013 |
Senior Member |
|
|
Ok so I changed my Package rule to:
rule Package {
from
up: UML2!Package (
not up.oclIsUndefined() and up.oclIsTypeOf(UML2!Package)
)
to
mp: UML2!Package (
name <- up.name -> debug('Package'),
packagedElement <- up.packagedElement,
packagedElement <- up.packagedElement -> collect(e | thisModule.resolveTemp(e,
't')),
packagedElement <- up.packagedElement -> collect(e | thisModule.resolveTemp(e,
'w'))
)
}
It works exactly as intended! thank a lot Sylvain.
I don't quite understand though how to do this regarding operations, I tried the following code:
rule button {
from
s: UML2!Class (
s.name = 'Button'
)
to
r: UML2!Class (
name <- 'PushButton' -> debug('PushButton'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute,
ownedOperation <- s.ownedOperation -> collect(e | thisModule.resolveTemp(e,
't'))
),
t: UML2!Class (
name <- 'CheckBox' -> debug('CheckBox'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute,
ownedOperation <- s.ownedOperation -> collect(e | thisModule.resolveTemp(e,
't'))
),
w: UML2!Class (
name <- 'RadioButton' -> debug('RadioButton'),
visibility <- s.visibility,
isAbstract <- s.isAbstract,
isLeaf <- s.isLeaf,
isActive <- false,
templateBinding <- s.templateBinding,
nestedClassifier <- s.nestedClassifier,
generalization <- s.generalization,
interfaceRealization <- s.interfaceRealization,
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute,
ownedOperation <- s.ownedOperation -> collect(e | thisModule.resolveTemp(e,
't'))
)
}
But I'm obviously doing something wrong, because it doesn't work still.
I think the problem might be when trying to reference just one operation from three different classes, shouldn't I create three different operations? I'm not sure at all about how to do this, so any help is appreciated.
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 05:18:23 GMT 2024
Powered by FUDForum. Page generated in 0.01952 seconds
|