|
|
Re: [ATL] multiple target & navigation in model [message #522402 is a reply to message #522347] |
Mon, 22 March 2010 14:52 |
Vincent MAHE 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 |
Guillaume Landriu 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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03844 seconds