Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Rule transforming one element to several elements(Only one of the transformed elements is properly situated in the packages)
icon8.gif  Rule transforming one element to several elements [message #1037257] Tue, 09 April 2013 10:49 Go to next message
Javier García is currently offline Javier GarcíaFriend
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 #1037298 is a reply to message #1037257] Tue, 09 April 2013 11:47 Go to previous messageGo to next message
Gunnar Arndt is currently offline Gunnar ArndtFriend
Messages: 82
Registered: June 2012
Member
(Sorry, timed out.)

[Updated on: Tue, 09 April 2013 11:48]

Report message to a moderator

Re: Rule transforming one element to several elements [message #1037300 is a reply to message #1037257] Tue, 09 April 2013 11:48 Go to previous messageGo to next message
Gunnar Arndt is currently offline Gunnar ArndtFriend
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 #1037314 is a reply to message #1037300] Tue, 09 April 2013 12:06 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You can do it in the Package rule but you can also get back to the package in your Button rule :
s.owner.packagedElement <- t;
s.owner.packagedElement <- w;


Btw you should take care of :
ownedOperation <- s.ownedOperation,
ownedAttribute <- s.ownedAttribute

Yes you transform one class into three but that doesn't imply that the operations and attributes will also be copied. You have to specify that also and will probably then have to use resolveTemp. See the doc.
Re: Rule transforming one element to several elements [message #1037324 is a reply to message #1037314] Tue, 09 April 2013 12:20 Go to previous messageGo to next message
Javier García is currently offline Javier GarcíaFriend
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 #1037339 is a reply to message #1037324] Tue, 09 April 2013 12:39 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Have a look here
My example is almost like your use-case.
You have to use resolveTemp on s.owner before modifying the "packagedElement" reference.
Or you could try :
r.owner.packagedElement <- t;
r.owner.packagedElement <- w;

This should be equivalent.

To duplicate Attribute/Operation you can either use the same technic as for classes and use resolveTemp to specify who gets what, or you can also use lazy rules.
Re: Rule transforming one element to several elements [message #1038063 is a reply to message #1037339] Wed, 10 April 2013 11:04 Go to previous messageGo to next message
Javier García is currently offline Javier GarcíaFriend
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.
Re: Rule transforming one element to several elements [message #1038104 is a reply to message #1038063] Wed, 10 April 2013 12:10 Go to previous message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Yes, one operation becomes three but only if the operation is in a Button class.
Note that this is transitive. You'll have to do that also on the Parameter of an Operation and so on.
Previous Topic:From UML Class diagram to Relational DB
Next Topic:[ATL] Cannot import EMFTVM
Goto Forum:
  


Current Time: Fri Apr 19 05:18:23 GMT 2024

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

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

Back to the top