The following example is borrowed from tutorial used in an early version of ATLAS: Consider a model involving a Book that has a number of Chapters as depicted in the following figure.
We wish to write a model transform to convert models of Books to produce Publication objects which satisfy the following.
Download latest version of SiTra. If you use an IDE import the packages to your IDE. We make use of Eclipse IDE.
We will create Plain Old Java Objects (POJO) for representing metamodel of the Book and Publication. Create a Chapter.java as follows to model chapters of the book.
Metamodel of Chapter as a POJO
Similarly, create a Book.java as follows, in which chapters are put together as an ArrayList.
Metamodel of Book
We have added a constructor to the end so that Book objects can be produced. In this elementary tutorial we produce the metamodels manually as POJOs.
Metamodel of the destination can be produced in a similar form.
Metamodel of Publication
If we start the design of the metamodel in graphical notations such as UML class diagrams, EMF can be used to automatically produce the metamodels and Factory design Pattern for producing the objects.
Now we write our first model transformation. The interface Rule of the SiTra package is extended. So three methods must be implemented. check method will return true if the transformer come across a Book object, in which case the build method is invoked. The method build produces a Publication and sets its attributes. setProperties method is not used in here.
Transformation rule for mapping Book to Publication
We will produce some source objects that comply to the metamodel of the Book, apply BookToPublication transformation to produce a Publication object.
Testing the transformation
The program will produce the following
running the program
Welcome to our new site!