Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Creating/inserting new element
[ATL] Creating/inserting new element [message #107749] Thu, 02 July 2009 15:30
Tom  is currently offline Tom Friend
Messages: 4
Registered: July 2009
Junior Member
Hello,
I've just started using ATL and I wanted to implement my first little
transformation. The transformation concerns the classical problem of
transforming an uml diagram into tables (with columns). Therefore I
defined my own little metamodel that looks like this:

The metaclass MyPackage has a name and contains zero to many MyClass's
(unidirectional). MyClass has a name too and contains zero to many
MyAttribute's (unidirectional). Moreover it can have zero to many
references to itself (MyClass). MyAttribute has a name and a boolean
attribute id.

The metamodel for the table looks like this: The metaclass
MyTableContainer contains zero to many MyTable's (and has a name). MyTable
has a name too and contains zero to many MyColumns. MyColumn has a name, a
type and two boolean attributes for the foreign key and a primary key.

The basic transformation is pretty straightforward.

Now I wanted to add something. At first I assumed that every instance of
MyClass has exactly one attribute (instance of MyAttribute) with the
characteristic: id = true. Now I wanted to omit this restriction. Instead
of it I wanted my transformation to create the instance of type MyColumn,
with the boolean attribute for the primarykey set to true, if the original
model does not possess an attribute with id = true. In such a case I
simply wanted to generate a MyColumn with a predefined name, type and so
on (and the primarykey set to true). Unfortunately I don't manage to do
this.

Here is my current transformation:

module Uml2Table; -- Module Template
create OUT : simpletable from IN : simpleuml;

helper def: dbType(type : simpleuml!MyPrimitiveType) : String =
//simply maps type to String, therefore omitted

rule package2container {
from
c:simpleuml!MyPackage
to
t:simpletable!MyTableContainer (
name <- c.name,
tables <- c.classes
)
}

rule class2table {
from
c:simpleuml!MyClass
to
t:simpletable!MyTable (
name <- c.name,
columns <- c.attributes,
columns <- c.refs->collect(e|thisModule.ref2column(e))
/* I think I have to add something here. If there is no attribute with id
= true, then I want to add a new column with a predefined name */
)
}

rule attribute2column {
from
c:simpleuml!MyAttribute
to
t:simpletable!MyColumn (
name <- c.name,
primaryKey <- c.id,
type <- thisModule.dbType(c.type)
)
}

lazy rule ref2column {
from
cl:simpleuml!MyClass
to
c:simpletable!MyColumn (
name <- cl.name + '_' + cl.attributes -> select(e | e.id = true) ->
first().name,
type <- thisModule.dbType(cl.attributes->select(e | e.id = true) ->
first().type),
foreignKey <- true
)
}

Can somebody please give me a hint? Basically I want to create a new
instance of MyColumn and add it to columns (in rule class2table). Thanks
in advance.

Regards,
Tom
Previous Topic:[ATL] Calling a transformation from Java
Next Topic:[ATL] Best method for java integration
Goto Forum:
  


Current Time: Thu Apr 25 21:41:54 GMT 2024

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

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

Back to the top