Skip to main content


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 09:34 Go to next message
Martin Benedict is currently offline Martin BenedictFriend
Messages: 22
Registered: June 2012
Junior Member
Hello,

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 {
	from
		dt: HL7!HL7GenericDataType
	using {
		titled: UML!Stereotype = thisModule.getStereotype('titled');
		dtpackage: UML!Package = UML!Package.allInstancesFrom('OUT') -> select(n | n.name = 'Datatypes').first();
	}
	to
		cl: UML!Class (
			name <- dt.baseType.name			
		)
				
	do {
		thisModule.debug('processing datatype ' + dt.baseType.name);
		cl.applyStereotype(titled); 		
		thisModule.knownDatatypes.put(dt.baseType.name, cl);
		dtpackage.packagedElement.add(cl); 
		cl;
	}
}


the calling code is the following:

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


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: http://wiki.eclipse.org/ATL_Language_Troubleshooter#ATL_Called_Rules_Troubles.
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,
Martin

[Updated on: Thu, 19 July 2012 10: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 07:32 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
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 | n.name = '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.
dtpackage.packagedElement.add(cl);
cl.applyStereotype(titled); 
Re: lazy rule doesn't return class [message #896943 is a reply to message #896857] Fri, 20 July 2012 13:41 Go to previous message
Martin Benedict is currently offline Martin BenedictFriend
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)

Data
|-ProfileA
| |-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.

Data
|-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 | p.name = 	'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
do{
	externalModel.packagedElement.add(UML!Model.allInstancesFrom('BDT') -> 
                   select(p | p.name = '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 13: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: Fri Apr 19 10:54:19 GMT 2024

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

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

Back to the top