Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Problem when transforming a model stored in a .uml file into another model
[ATL] Problem when transforming a model stored in a .uml file into another model [message #548350] Wed, 21 July 2010 14:39 Go to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
I've just written a toy transformation between UML models that use profiles. Using the UML Editor I developed two profiles (profileA and profileB), each one extending the UML2 Class meta-class with the corresponding stereotype (AClass and BClass, respectively) defining two new tagged values (payload and tag). Then, I used UML Editor to create a source model that instantiated the stereotyped defined by profileA.

I wrote this simple .atl file:

module AClass2BClass;

create OUT: profileB from IN: profileA;

helper context profileA!AClass def: translate() : String =
	if self.payload > 0 then
		'Greater than zero'
	else
		'Equal to zero'
	endif;

rule main {
	from
			s: profileA!AClass
	to
-- payload is an Integer in AClass
-- payload is a String in BClass

			t: profileB!BClass (
				payload <- s.translate()
			)
}


The inputs to run this code I indicated to ATL Configuration were the two profiles (profileA.profile.uml and profileB.profile.uml), the source model (aclass_model.uml) and I indicated that ATL should generate the output model bclass_model.uml.

When I opened the generated output (bclass_model.uml) using the UML Editor I realized that the information about the profile was in the file, whereas the information about the transformed model element (the instance of the BClass meta-class) was not. When I open the bclass_model.uml file using a text editor I see XMI code that sets the payload tagged value as indicated by the transformation.

My questions are: is ATL able to transform .uml files properly? Do you see anything wrong in my procedure that prevents ATL from generating a proper .uml file?

Thanks a lot for your help.


/TB

[Updated on: Wed, 21 July 2010 14:47]

Report message to a moderator

Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #548353 is a reply to message #548350] Wed, 21 July 2010 14:49 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You transformed only the application of the stereotype, but the stereotype is applied on a class that you also want to transform otherwise it disapears.

So you have to add a rule to transform UML2 classes.

rule Class {
from s : profileA!Class
to t : profileB!Class(
name <- s.name
)
}

What you also want is that the transformed stereotype points to the transformed corresponding class. So you have to add a binding to your stereotype rule corresponding to the Class concerned by the stereotype.

t: profileB!BClass (
payload <- s.translate(),
base_Class <- s.base_Class
)
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #548381 is a reply to message #548353] Wed, 21 July 2010 15:52 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
Thanks a lot Sylvain. You have provided me with very useful hints.

I agree with the creation of the instances of the meta-class Class. However, I am not sure that

base_Class <- s.base_Class


works.

I included this code in the main rule. The result was that the instance of Class was created, but I still do not see the instance of BClass in the bclass_model.uml file. In addition, there is a <Model> element at the top on the containment hierarchy in aclass_model.uml that is missing in bclass_model.uml too.

I will work now in two directions:

1. Determine how to link the instance of Class and the instance of BClass (i.e. the extension relationship) to generate the correct bclass_model.uml file.
2. Determine the structure of a .uml file so I can instantiate every single component correctly.

I will appreciate any advice on how to do these thinks.

Kindest regards.



/TB

[Updated on: Wed, 21 July 2010 15:52]

Report message to a moderator

Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #548383 is a reply to message #548350] Wed, 21 July 2010 16:02 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
That's the same for the Model element, if you want to transform it, then you have to add the rule for it in your transformation (same if you have packages, and so on).

________

Normally, each stereotype is linked to the element stereotyped using an attribute base_{NameOfTheUMLElementTargeted}

So if you defined a stereotype on the class Class of the UML Metamodel, then that stereotype will have the attribute base_Class that references the Class concerned by this stereotype instance. If you want to transform this link between the stereotype and the element stereotyped then you have to add the binding base_Class <- s.base_Class.

This binding works together with the rule to transform classes because the ATL resolve mechanism will map the Class concerned with the Class resulting from the transformation using the rule on Class.
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #548469 is a reply to message #548383] Thu, 22 July 2010 00:02 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
Understood.

I think I have written the correct transformation that does everything it was intended to do. I can share the code in case it is useful to any user:

module AClass2BClass;

create OUT: profileB from IN: profileA;

helper context profileA!AClass def: translate() : String =
	if self.payload > 0 then
		'Greater than zero'
	else
		'Equal to zero'
	endif;

rule models {
	from
			source: profileA!Model
	to
			target: profileB!Model (
				name <- 'bclass_model'
			)
}

rule classes {
	from
			source: profileA!Class
	to
			target: profileB!Class (
				name <- 'Target',
				package <- source.package
			)
}

rule stereotypes {
	from
			source: profileA!AClass
	to

-- payload is an Integer in AClass
-- payload is a String in BClass

			target: profileB!BClass (
				payload <- source.translate(),
				base_Class <- source.base_Class
			)
}


All you need to do is create the profileA and profileB using the UML Editor and use any of them to build a source model with UML Editor as well.

Now I will check whether these .uml files can be created and rendered using a UML edition tool.

Thanks a lot for your help Sylvain, I appreciate it a lot.


/TB
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642525 is a reply to message #548469] Wed, 01 December 2010 16:36 Go to previous messageGo to next message
Pejman  is currently offline Pejman Friend
Messages: 18
Registered: June 2010
Junior Member
Hi,

I have tried to create the same example. you want to transform an instance of AClass in profileA to an instance of BClass in profileB.

when I ran this example the output model created but I could not open it (It was empty). Then I replaced your first rule with
rule models {
	from
			source: profileA!Package 
	to
			target: profileB!Package (
				name <- 'bclass_model'
			)
}


It worked but in the out put model I ended up having UML classes without the stereotype.
I wonder if we need to use applyProfile() and applyStereotype() APIs
Am I missing something?

Thanks in advance

[Updated on: Wed, 01 December 2010 16:38]

Report message to a moderator

Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642528 is a reply to message #548350] Wed, 01 December 2010 16:47 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You have to apply the stereotype to the element.
You should have a property base_XXX on the stereotype pointing to the element where XXX is the name of the UML2 type this stereotype can be applied on.
If that is a package, you have to add the binding :
base_Package <- source.base_Package
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642529 is a reply to message #642528] Wed, 01 December 2010 16:57 Go to previous messageGo to next message
Pejman  is currently offline Pejman Friend
Messages: 18
Registered: June 2010
Junior Member
But I'm applying the stereotype on the classes
module t;

create OUT : MM1 from IN : MM; 


rule models {
	from
			source: MM!Package
	to
			target: MM1!Package (
				name <- 'bclass_model'
			)
}

rule classes {
	from
			source: MM!Class
	to
			target: MM1!Class (
				name <- 'Target',
				package <- source.package
			)
}

rule stereotypes {
	from
			source: MM!A
	to
			target: MM1!B (
	
				base_Class <- source.base_Class
			)
}

I have defined the Stereotype A in the input profile and Stereotype B in the out profile. Now the input model has and instance of stereotype A and I wanted to transform it to an instance of stereotype B. I have tried the APIs but they did not work

Thanks
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642629 is a reply to message #642525] Thu, 02 December 2010 04:49 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
I developed the excercise by using UML Editor to create the model (instance of the meta-class Model) that contained the class Source (instance of the meta-class Class); then, I applied the profile profileA using a command in UML Editor. All of these elements were stored in the .uml file, I then ran the ATL rules.

Did you use UML Editor to build the two profiles and the source model?

Did you use UML Editor to apply the profile to the model previous the execution of the rules?



/TB

[Updated on: Thu, 02 December 2010 04:50]

Report message to a moderator

Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642780 is a reply to message #642629] Thu, 02 December 2010 16:43 Go to previous messageGo to next message
Pejman  is currently offline Pejman Friend
Messages: 18
Registered: June 2010
Junior Member
Thanks a lot Balderas for your hint,

Actually I have defined my profiles in RSA(Rational Software Architect) and then import(with the *.profile.uml extension) them to eclipse. Apparently the problem was due to the import. So I have defined them in eclipse from scratch and now it works!

So do you have any similar experience with RSA or any other tools?(Since I have already defined 3 huge profiles in RSA I need to find a solution to use them directly in Eclipse)
The other part which is still not clear for me is what is the difference between the method that you used in your example and using applyProfile and applyStereotype functions.

Something like this :
module A2B;
create OUT : MM1 from IN : MM;


rule test{
from s: MM! Class(s.getAppliedStereotypes()->collect(st | st.name) ->at(1) ='A')
to t: MM1! Class(
	name<- 'Target' 
	)
	do {
		t.applyStereotype('PB::B') 
	}
}
	



It would be insightful for me to have your opinion.

Thanks again

[Updated on: Thu, 02 December 2010 17:04]

Report message to a moderator

Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642800 is a reply to message #642780] Thu, 02 December 2010 18:08 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
These are my two cents:

1. I replicated this excercise using the eclipse plugin for Papyrus. I managed to create the .uml files using this tool, but the problem I had was that the .atl file in this poject was not compiled into the internal representation (.asm file) used by ATL's VM. I had to run the ATL rules from a similar file in another project. Weird stuff, do not know what happened here yet.

On the other hand, I tried to use Enterprise Architect as my first option, but had problems with importing. My little experience indicates that this inter-tool importing/exporting mechanisms for UML/XMI do not really work for most of the cases.

2. My understanding is that the developer wants to transform a model that has been extended as a result of the application of a profile; that is, the developer wants to build a complete model, that includes profile applications, before performing the transformation process. That is why I applied the profile to a model before running the transformation rules, instead of the transformation rules to apply the profile. My guess is that this is the correct procedure.

3. The target model produced by the transformation rules does not contain an instance of the ProfileApplication meta-meta-class; thus, it can not be seen as a model that has a profile (profileB) applied to it. Is this what you intended to do? In this case, we could not "de-apply" profileB from the target model produced by the rules I wrote because there is no such appication (instance of ProfileApplication), that is for sure. I would like to know the opinion of an expert on this, the specific question is:

If we have a source model to which we have applied a profile (profileA), and thus contains an instance of ProfileApplication, does our transformation have to generate a target model that also contains an instance of ProfileApplication?

Sylvian, what is your opinion on that?

Kindest regards.


/TB
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642886 is a reply to message #548350] Fri, 03 December 2010 08:34 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You can always create instances of ProfileApplication but that is a bit complicated whereas the call to applyProfile on the Model element is quite simple though you have to add the profile(s) as input to the transformation (actually you don't have to declare it in the "from" section of the transformation, you can just declare the profiles in your launch configuration/java code, that way they won't be transformed, just used in the transformation - don't forget to allowInterModelReferences then).

I, myself, prefer using stereotype as instances than the APIs because it lowers the risk of errors, facilitate the debug operations and allow to do things declaratively withouth using imperative sections.

To get back to the example, what happens if the class has another stereotype before 'A' ? your test rule won't work anymore because of the filter. The declarative technic is also really useful and clearer when using tagged values because they are just attributes of an instance of a stereotype whereas using APIs for that is just a nightmare.
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #642887 is a reply to message #548350] Fri, 03 December 2010 08:35 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
For the compilation of the ATL file, note that your project has to have the ATL nature otherwise the file won't be compiled.
Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #643061 is a reply to message #642887] Fri, 03 December 2010 19:37 Go to previous messageGo to next message
Pejman  is currently offline Pejman Friend
Messages: 18
Registered: June 2010
Junior Member
Thanks to both of you for the helpful information.

So if I understood correctly your suggestion is to go with the method that I had read in previous posts (which called is as static profile). And using this method we do not need to use the APIs.

And that was exactly happened in this example.
If so, what is the difference in the design process of the profiles?
I had fined a link that gives the tutorial for defining the static profile titled "Defining static profiles with Eclipse UML2 " but for this example I did not use these guidelines.

I have also tried to create two different Stereotypes as an output but I could not do so :
module A2B;

create OUT : MM1 from IN : MM;


rule models {
	from
			source: MM!Package
	to
			target: MM1!Package (
				name <- 'bclass_model'
			)
}

rule classes {
	from
			source: MM!Class
	to
			target: MM1!Class (
				name <- 'Target',
				package <- source.package
			)
}

rule stereotypes {
	from
			source: MM!A
	to
			target: MM1!B (
	
				base_Class <- source.base_Class
			),

			target2: MM1!C (
	
				base_Class <- source.base_Class
			)
	 
}


Thanks in advance for your time. It is great opportunity for me to learn from you guys since I'm pretty new with the topic.

Regards,

[Updated on: Sun, 05 December 2010 23:47]

Report message to a moderator

Re: [ATL] Problem when transforming a model stored in a .uml file into another model [message #649342 is a reply to message #643061] Tue, 18 January 2011 19:57 Go to previous message
Pejman  is currently offline Pejman Friend
Messages: 18
Registered: June 2010
Junior Member
Hi,

In the same example, have you guys ever tried to use the tagged definition in a helper function. For example working with the payload in a helper function.

Thanks in advance,

Pejman
Previous Topic:[ATL] ATL and IBM RSA 7.5.5+
Next Topic:*ToEcore: How to create primitive types
Goto Forum:
  


Current Time: Tue Nov 12 13:52:36 GMT 2019

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

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

Back to the top