[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.modeling.m2m] Re: [ATL] transforming UML to EJB (continuing)
|
Hello again,
I tested the code I wrote in the previous message with the EJB and UML files you provided
some days ago in the post
(http://www.eclipse.org/newsportal/article.php?id=313&group=eclipse.modeling.m2m#313), and
it worked fine.
The transformation generated a EJBBusinessMethod with a set of parameters (2 on that example).
Regards,
Marcos.
PS.: I copied below the transformation I executed. Then you can add any extra processing
you need.
---------------------------------------------------------------------------------
module UML2EJB; -- Module Template
create OUT : EJB from IN : UML ;
-- Tested: OK
helper context UML!Class def: getAssociationEnds(): Sequence( UML!AssociationEnd) =
let associationEnds : Sequence(UML!AssociationEnd) = self.feature->
select( e | e.oclIsKindOf(UML!AssociationEnd)) in
if associationEnds->notEmpty() then
associationEnds->iterate( e;
acc: Sequence(UML!AssociationEnd) = Sequence{} |
acc.append(e) )
else
Sequence{}
endif;
-- Tested: OK
helper context UML!Class def:isAComposition(): Boolean =
self.getAssociationEnds()->exists(end | end.otherEnd.composition = true)
;
rule ClassToEntityComponent{
from class : UML!Class
( not class.isAComposition() )
to entityComponent : EJB!EJBEntityComponent (
name <- class.name.debug('debug here'),
feature <- class.feature,
usedTable <- EJBTable
),
EJBTable : EJB!Table (
)
}
rule Operation {
from
oper : UML!Operation
to
method : EJB!EJBBusinessMethod (
name <- oper.name,
parameter <- oper.parameter
)
}
rule Parameter {
from
parameter : UML!Parameter
to
out : EJB!EJBParameter (
name <- parameter.name
)
}
rule Attribute {
from
attr : UML!Attribute
to
out : EJB!EJBAttribute (
name <- attr.name
)
}
rule AssocEnds {
from
assocEnd : UML!AssociationEnd
to
ASSOCENDS : EJB!EJBAssociationEnd
(
name <- assocEnd.name,
lower <-assocEnd.lower,
upper <- assocEnd.upper,
composition <- assocEnd.composition
)
}
---------------------------------------------------------------------------------
Marcos Didonet Del Fabro wrote:
Hi Walcir,
maybe I am missing some details about your metamodels, but I think you
could write your transformations in a different way, taking advantage of
the declarative nature of ATL. See the example rewritten below:
walcir fontanini wrote:
Hi all,
Please, tell me if I am not in the wrong place. I am trying to
transform some UML model to an EJB model. The "parameter" target
pattern is not working, and I think I need a lot more
"distinct-foreach" !!! It seems that I need just one big "rule" with
every possible target pattern there .
Thanks,
-walcir
=== UML model ====
<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="UML">
<DataType name="String"/>
<DataType name="Integer"/>
<Class name="BreakfastOrder">
<feature xsi:type="Operation" name="calculatePrice">
<parameter name="year_price" type="/1"/>
<parameter name="rate" type="/1"/>
</feature>
<feature xsi:type="Attribute" name="deliveryStatus" type="/0"/>
<feature xsi:type="Attribute" name="deliveryDate" type="/0"/>
<feature xsi:type="AssociationEnd" name="customer" lower="1"
upper="1" otherEnd="/3/@feature.3"/>
<feature xsi:type="AssociationEnd" name="breakfasts" lower="1"
upper="-1" composition="true" otherEnd="/4/@feature.2"/>
</Class>
</xmi:XMI>
==== EJB model ====
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="EJB">
<EJBEntityComponent name="BreakfastOrder" usedTable="/1">
<feature xsi:type="EJBAttribute" name="deliveryStatus"/>
<feature xsi:type="EJBAttribute" name="deliveryDate"/>
<feature xsi:type="EJBAssociationEnd" name="customer" lower="1"
upper="1"/>
<feature xsi:type="EJBAssociationEnd" name="breakfasts" lower="1"
upper="-1" composition="true"/>
<feature xsi:type="EJBBusinessMethod" name="calculatePrice">
<parameter name="year_price" type="/1"/>
<parameter name="rate" type="/1"/>
</feature>
</EJBEntityComponent>
<Table/>
</xmi:XMI>
And I am using an ATL code like this:
.. some helpers deleted here ...
lazy rule kkkk {
from umlOper : UML!Operation
to Parameters : distinct EJB!EJBParameter
foreach (par in umlOper.parameter) (
name <- par.name ) }
rule ClassToEntityComponent{
from class : UML!Class
( not class.isAComposition() )
to entityComponent : EJB!EJBEntityComponent (
name <- class.name.debug('debug here'),
feature <- ATTRS->union(ASSOCENDS)->union(OPERS),
usedTable <- EJBTable
),
EJBTable : EJB!Table (
),
OPERS : distinct EJB!EJBBusinessMethod
foreach (oper in class.operations()) (
name <- oper.name,
parameter <- oper->collect(e | thisModule.kkkk(e))
),
ATTRS : distinct EJB!EJBAttribute
foreach (attr in class.attributes())(
name <- attr.name
),
ASSOCENDS : distinct EJB!EJBAssociationEnd
foreach (assocEnd in class.getAssociationEnds())(
name <- assocEnd.name,
lower <-assocEnd.lower,
upper <- assocEnd.upper,
composition <- assocEnd.composition
)
}