Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] multiple target & navigation in model
[ATL] multiple target & navigation in model [message #522347] Mon, 22 March 2010 13:08 Go to next message
Guillaume Landriu is currently offline Guillaume LandriuFriend
Messages: 4
Registered: March 2010
Location: Toulouse
Junior Member
Hello,

I am beginner with ATL. I would like to tranforme a Class with property to a other Class with same properties and 2 operations corresponding to the setter and getter of the properties.
I work with UML2 metamodel for the IN and OUT model.

I arrive to generate the properties inside the target Class but the operations don't inside the the target class.



My ATL code :
-- @path UML2=platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore

module persistence;
create OUT : UML2 from IN : UML2;

helper context String def : firstUpper() : String =
self.substring(1, 1).toUpper()+self.substring(2,self.size());

rule dao {
from a:UML2!Class
to d:UML2!Class (
name <- a.name +'DaoImpl',
ownedAttribute <- a.ownedAttribute->select(sf | sf.oclIsKindOf(UML2!Property)
)
)
}
rule attribute {
from a:UML2!Property
to p:UML2!Property (
name <- a.name,
owner <-a.owner),
get:UML2!Operation (name <- 'get'+a.name.firstUpper()),
set:UML2!Operation (name <- 'set'+a.name.firstUpper())
}



The model generated :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/uml2/3.0.0/UML platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore">
<uml:Class xmi:id="_BbNQpDWzEd-NCLTv9ULYUg" name="DepartementDaoImpl">
<ownedAttribute xmi:id="_BbNQpTWzEd-NCLTv9ULYUg" name="property1"/>
</uml:Class>
<uml:Operation xmi:id="_BbNQpjWzEd-NCLTv9ULYUg" name="getProperty1"/>
<uml:Operation xmi:id="_BbNQpzWzEd-NCLTv9ULYUg" name="setProperty1"/>
</xmi:XMI>







Re: [ATL] multiple target & navigation in model [message #522377 is a reply to message #522347] Mon, 22 March 2010 14:08 Go to previous messageGo to next message
Filipe Araujo is currently offline Filipe AraujoFriend
Messages: 7
Registered: July 2009
Junior Member
see Public To Private Example

getter : UML!Operation (
name <- 'get'+publicAttribute.name.toU1Case,
class <- publicAttribute.refImmediateComposite(),
type <- publicAttribute.type
),
Re: [ATL] multiple target & navigation in model [message #522402 is a reply to message #522347] Mon, 22 March 2010 14:52 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHEFriend
Messages: 129
Registered: July 2009
Senior Member
landriu a écrit :
> Hello,
>
> I am beginner with ATL. I would like to tranforme a Class with property
> to a other Class with same properties and 2 operations corresponding to
> the setter and getter of the properties.
> I work with UML2 metamodel for the IN and OUT model.
>
> I arrive to generate the properties inside the target Class but the
> operations don't inside the the target class.
>
>
>
> My ATL code : -- @path
> UML2=platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore
>
> module persistence;
> create OUT : UML2 from IN : UML2;
>
> helper context String def : firstUpper() : String =
> self.substring(1, 1).toUpper()+self.substring(2,self.size());
>
> rule dao {
> from a:UML2!Class
> to d:UML2!Class (
> name <- a.name +'DaoImpl',
> ownedAttribute <- a.ownedAttribute->select(sf |
> sf.oclIsKindOf(UML2!Property)
> )
> ) }
> rule attribute {
> from a:UML2!Property
> to p:UML2!Property (
> name <- a.name,
> owner <-a.owner),
> get:UML2!Operation (name <- 'get'+a.name.firstUpper()),
> set:UML2!Operation (name <- 'set'+a.name.firstUpper())
> }
>
Create a called rule which gives you a set of operations (your 2
accessors) for a property and add this set to the classe operations set.
Be care that in ATL the Union method on sets return a copy of the set so
you must reaffect the result to the class:
ownedOperation <- ownedOperation->union(yourCalledRule(xxx))
>
>
> The model generated : <?xml version="1.0" encoding="ISO-8859-1"?>
> <xmi:XMI xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xsi:schemaLocation="http://www.eclipse.org/uml2/3.0.0/UML
> platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore">
> <uml:Class xmi:id="_BbNQpDWzEd-NCLTv9ULYUg" name="DepartementDaoImpl">
> <ownedAttribute xmi:id="_BbNQpTWzEd-NCLTv9ULYUg" name="property1"/>
> </uml:Class>
> <uml:Operation xmi:id="_BbNQpjWzEd-NCLTv9ULYUg" name="getProperty1"/>
> <uml:Operation xmi:id="_BbNQpzWzEd-NCLTv9ULYUg" name="setProperty1"/>
> </xmi:XMI>
>
>
>
>
>
>
>
>


--
Cordialement

Vincent MAHÉ

Ingénieur plate-forme - Cesar/Artemisia - Équipe Espresso
IRISA-INRIA, Campus de Beaulieu, 35042 Rennes cedex, France
Tél: +33 (0) 2 99 84 71 00, Fax: +33 (0) 2 99 84 71 71
Re: [ATL] multiple target & navigation in model [message #522706 is a reply to message #522402] Tue, 23 March 2010 17:00 Go to previous messageGo to next message
Guillaume Landriu is currently offline Guillaume LandriuFriend
Messages: 4
Registered: March 2010
Location: Toulouse
Junior Member
Hello,

Thank you for the answers.

Vincent, I have try your solution, but i have a error.
It doesn't find a operation.
Have you got a idea for the solution ?
Thank.


see the error message bellow :
Operation not found: OUT!property1:UML2!Operation.not()
at __applydao(persistence.atl[14:21-14:75])
	local variables: self=thisModule, link=org.eclipse.m2m.atl.engine.emfvm.lib.TransientLink@166aa35, a=IN!Departement:UML2!Class, d=OUT!DepartementDaoImpl:UML2!Class, sf=IN!property1:UML2!Property
at __exec__(persistence.atl)
	local variables: self=thisModule, e=org.eclipse.m2m.atl.engine.emfvm.lib.TransientLink@166aa35
at main(persistence.atl)
	local variables: self=thisModule


see the code of my transformer :

module persistence;
create OUT : UML2 from IN : UML2;

helper context String def : firstUpper() : String = 
	self.substring(1, 1).toUpper()+self.substring(2,self.size());

rule dao {
	from a:UML2!Class
	to  d:UML2!Class (
		name <- a.name +'DaoImpl',
		ownedAttribute <- a.ownedAttribute->select(sf | sf.oclIsKindOf(UML2!Property)),
		ownedOperation <- a.ownedOperation->union(a.ownedAttribute->select(sf | thisModule.accessor(sf)))
		)
}

lazy rule accessor {
	from a:UML2!Property
	to o:UML2!Operation (name <- a.name)
}


Cordialement,
Guillaume Landriu
Re: [ATL] multiple target & navigation in model [message #522707 is a reply to message #522347] Tue, 23 March 2010 17:02 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
ownedOperation <- a.ownedOperation->union(a.ownedAttribute->collect(sf | thisModule.accessor(sf)))
Re: [ATL] multiple target & navigation in model [message #522708 is a reply to message #522347] Tue, 23 March 2010 17:07 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
BTW you can keep a declarative mode by using resolveTemp :

rule attribute {
from a:UML2!Property
to p:UML2!Property (
name <- a.name,
owner <-a.owner),
get:UML2!Operation (name <- 'get'+a.name.firstUpper()),
set:UML2!Operation (name <- 'set'+a.name.firstUpper())
}

ownedOperation <- a.ownedOperation->union(a.ownedAttribute->collect(sf | Sequence{thisModule.resolveTemp(sf,'get'),thisModule.resolve Temp(sf,'set')})- >flatten())
icon14.gif  Re: [ATL] multiple target & navigation in model [message #522709 is a reply to message #522707] Tue, 23 March 2010 17:09 Go to previous messageGo to next message
Guillaume Landriu is currently offline Guillaume LandriuFriend
Messages: 4
Registered: March 2010
Location: Toulouse
Junior Member
Yes, very good.
Thanks a lot.

Guillaume Landriu
Re: [ATL] multiple target & navigation in model [message #522715 is a reply to message #522708] Tue, 23 March 2010 17:28 Go to previous messageGo to next message
Guillaume Landriu is currently offline Guillaume LandriuFriend
Messages: 4
Registered: March 2010
Location: Toulouse
Junior Member
This solution is too difficulte for me.
I'm a begginer

I have to work on the doc before understand this kind of code.
but there isn't lot of tuto for ATL.

Thanks again.

Guillaume
Re: [ATL] multiple target & navigation in model [message #522725 is a reply to message #522715] Tue, 23 March 2010 17:57 Go to previous message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Guillaume Landriu wrote on Tue, 23 March 2010 13:28
This solution is too difficulte for me.
I'm a begginer

I have to work on the doc before understand this kind of code.
but there isn't lot of tuto for ATL.

Thanks again.

Guillaume

see ATL documentation
Previous Topic:urgent
Next Topic:[ATL] output model should have a reference to an element of the input model
Goto Forum:
  


Current Time: Tue Apr 23 13:07:16 GMT 2024

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

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

Back to the top