Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » lazy rule doesn't return class
lazy rule doesn't return class [message #896645] Thu, 19 July 2012 05:34 Go to next message
Martin Benedict is currently offline Martin Benedict
Messages: 22
Registered: June 2012
Junior Member

I'm working with lazy rules and currently I try to solve an issue on return types of lazy rules. I have defined a lazy rule that contains a do block. See code sample.

lazy rule DataTypeTransformation {
		dt: HL7!HL7GenericDataType
	using {
		titled: UML!Stereotype = thisModule.getStereotype('titled');
		dtpackage: UML!Package = UML!Package.allInstancesFrom('OUT') -> select(n | = 'Datatypes').first();
		cl: UML!Class (
			name <-			
	do {
		thisModule.debug('processing datatype ' +;
		thisModule.knownDatatypes.put(, cl);

the calling code is the following:

type <- if (thisModule.knownDatatypes.get( then
	thisModule.DataTypeTransformation(p.type.debug('create datatype ' + ))
	thisModule.getClass('class exists ') +

The problem I have is, that the lazy rule doesn't return the UML-class (cl). The type property of the attributes do not contain any class. If I remove the do block it works.
I have searched for a solution and found this:
I've added cl at the end of the do block, but this doesn't change anything. Are do blocks in lazy rules not allowed? Is the problem, that I add the class to dtpackage? How could I resolve this issue. I have to add the classes to the dtpackage, but only those that are refernced as type in a class.

It would be very nice, if there are some advices?
Thank You,

[Updated on: Thu, 19 July 2012 06:19]

Report message to a moderator

Re: lazy rule doesn't return class [message #896857 is a reply to message #896645] Fri, 20 July 2012 03:32 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 511
Registered: July 2009
Senior Member
First of all, you can never be sure of the order of execution of the rules.
So your :
dtpackage: UML!Package = UML!Package.allInstancesFrom('OUT') -> select(n | = 'Datatypes').first();

seems quite risky.

Concerning lazy rules, they do return the first "to" element.
The construction you're using with the object to return at the end of the do block is for called rules.
A called rule has no "from" section.
Here it would look like :
rule DataTypeTransformation(dt: HL7!HL7GenericDataType) {

Finally I think your way to apply a stereotype is wrong.
To understand that, you must know how UML2 handles stereotypes.
When you apply a stereotype, it will create an instance of this stereotype with a relation to the element that is stereotyped.
Now, this instance must be in a EMF resource of course.
What happens with ATL when you create an object, it doesn't belong yet to any resource.
When this object is linked to another one by a containment relation, then it gets added to the resource of the owner.
In your case, you are applying the stereotype to a Class that doesn't belong to a resource yet.
Only after you place the Class into an owner.
That will probably lose the stereotype.
I'd advise doing the contrary by first setting the owner and only then applying the stereotype.
Re: lazy rule doesn't return class [message #896943 is a reply to message #896857] Fri, 20 July 2012 09:41 Go to previous message
Martin Benedict is currently offline Martin Benedict
Messages: 22
Registered: June 2012
Junior Member
Sylvain, thanks for your help.

I have considered your suggestions in my ATL script, but there is a new problem that has appeared.

The models my ATL scripts generate are the base for another transformation with a given tool. To that there are some rules how the models should be generated. One rule is that there should be a package which is called 'external models'.
This package should contain a reference to another model which contains base datatypes. This datatypes have applied some stereotypes. The profile I use also for my model.
The imported model has the following containment tree. (I can't modify it)

| |-xmodel(Stereotype)
|-BaseDataTypes <<xmodel>>

Because normally the models are created with MagicDraw the import of the package BaseDataTypes is simple. But in my transformation there is a problem. I have to import the package BaseDataTypes. The problem is, that the stereotype xmodel isn't applied, because the 'Data'-Package is not imported. If I import it everything works fine and the stereotype is applied.

My model should look like the following hierarchy.

|-ProfileA (same as in the imported model)
| |-xmodel(Stereotype)
|-external models
| |-BaseDataTypes <<xmodel>> (same package as above)
|-MyModel <<model>>

This is my current ATL snippet for importing the BaseDataTypes package. But the stereotypes are lost.

pi: UML!PackageImport (
 importedPackage <- UML!Model.allInstancesFrom('BDT') -> select(p | = 	'BaseDataTypes').first()

-- if I remove this the stereotypes are applied, but the Data-package from the imported BDT is in the root of OUT, and I want to have the BaseDataTypes-model in external models
	externalModel.packagedElement.add(UML!Model.allInstancesFrom('BDT') -> 
                   select(p | = 'BaseDataTypes').first()); 

I already have tried with other properties of externalModel, but evertime the stereotypes of the package BaseDataTypes and all other packages are lost. The ProfileA I have applied to my root('Data')-model.

How could I preserve the stereotypes of BaseDataTypes

Could you or anybody else help me to solve this problem?

Thank You

[Updated on: Fri, 20 July 2012 09:43]

Report message to a moderator

Previous Topic:Problem finalizing Model with stereotypes on association ends applied
Next Topic:lazy rules with returning sequence
Goto Forum:

Current Time: Thu Apr 17 23:40:48 EDT 2014

Powered by FUDForum. Page generated in 0.03278 seconds