Documente Academic
Documente Profesional
Documente Cultură
User Tutorial
This handbook is the exclusive ownership of its authors and was conceded to the profit of Obeo SARL. This
handbook is protected by intellectual ownership rights.
It deals with a software product called ACCELEO, currently distributed under the open source Eclipse Public
License (EPL). The distribution of this handbook is however not free.
This handbook makes it possible to fully take advantage of the many advanced functionalities of ACCELEO
software and required on behalf of its authors and of OBEO an important compilation and synthesis work, as
well as consequent financial and time investments. Nevertheless, there may still be mistakes left in this
document, OBEO shall not be held responsible for any resulting inconvenience. ACCELEO as well as the
content of this document may be altered without prior notice.
This document is not under Free license. This document can be downloaded without any fee from the
OBEO website after proper registering. You may read and use it for any activity, commercial or not, related to
ACCELEO. Yet permission of copying, translating or distributing freely or commercially this manual is subject
to prior approval by OBEO.
____________________
OBEO, ACCELEO, as well as OBEO and ACCELEO logos are registered trademarks of Obeo in France
and in other countries.
All other names, titles, drawings, and logos are the exclusive ownership of their authors and are protected by
intellectual ownership rights.
This handbook was written with the following tools: OpenOffice
____________________
Authors: Jonathan MUSSET, tienne JULIOT, Stphane LACRAMPE
With the participation of: Goulwen LE FUR, Julien DUPONT, Guillaume RAIMBAULT, Nathalie LEPINE,
William PIERS, Cdric BRUN, and Laurent GOUBET
Copyright 2006 2008 Obeo. All rights reserved.
Summary
1 - Introduction.......................................................................................................................1
1.1 - Minimum knowledge required...................................................................................1
1.2 - Documentation for Acceleo.......................................................................................1
2 - Installation.........................................................................................................................2
3 - Quick Startup....................................................................................................................3
3.1 - Import a Project into Eclipse.....................................................................................3
3.2 - Launch the Generation Chain...................................................................................5
4 - Modeling...........................................................................................................................7
4.1 - Definition....................................................................................................................7
4.2 - The Modelers.............................................................................................................8
4.2.1 - The UML2 Meta-Model with the EMF Modeler..................................................8
4.2.1.1 - Creating a Project.......................................................................................9
4.2.1.2 - Creating a UML2 Model............................................................................10
4.2.1.2.a - Creating a Package...........................................................................11
4.2.1.2.b - Creating a Class................................................................................12
4.2.1.2.c - Creating an Attribute..........................................................................12
4.2.1.2.d - Adding a Profile to a Model...............................................................13
4.2.1.2.e - Create an Association.......................................................................14
4.2.1.2.f - Validate the Model..............................................................................16
4.2.2 - Using the Example...........................................................................................16
4.2.2.1 - Importing a Project into Eclipse................................................................17
4.2.2.2 - Creating a Project Dynamic Web Project ............................................19
4.2.2.3 - The model WebLog_fr.uml.......................................................................22
4.2.2.4 - Creating a Model......................................................................................23
5 - Initializing a Project.........................................................................................................26
5.1 - Importing Generation Modules................................................................................26
5.2 - Code Generation Files............................................................................................27
5.2.1 - Previewing the Results.....................................................................................27
5.2.1.1 - Synchronizing the Model Code.................................................................29
5.3 - Creating the Generation Chain...............................................................................30
5.3.1 - Creating a Generation Chain Using the Assistant...........................................30
5.3.2 - Creating a Generation Chain without the Assistant.........................................34
5.3.2.1 - Adding a Model.........................................................................................35
5.3.2.2 - Adding a Target Folder.............................................................................37
5.3.2.3 - Adding a Log.............................................................................................37
5.3.2.4 - Adding a Meta-Model...............................................................................38
5.3.2.5 - Adding the Generation File.......................................................................38
6 - Generation......................................................................................................................41
6.1 - Running a Generation Chain...................................................................................41
6.2 - Importing a Tomcat server......................................................................................42
6.2.1 - Importing the Tomcat Libraries........................................................................45
6.3 - Testing the Application............................................................................................47
7 - Parameters.....................................................................................................................49
7.1 - The Generation Chains...........................................................................................49
7.1.1 - Modifying a Generation Chain.........................................................................49
7.2 - The logs ..............................................................................................................50
7.3 - The Properties Files............................................................................................51
7.3.1 - Creating a Properties File............................................................................51
8 - Update Management......................................................................................................54
8.1 - Manual Development..............................................................................................54
8.1.1 - Adding code to the servlets.............................................................................54
8.2 - Functional Updates.................................................................................................55
8.2.1 - Modification of the Input Model........................................................................55
8.2.1.1 - Modification of an Attribute.......................................................................55
8.2.1.2 - Adding a Class..........................................................................................56
8.2.1.3 - Deleting a Class........................................................................................57
8.2.1.4 - Renaming a class.....................................................................................58
8.2.1.5 - Adding/Modifying a Relationship (association / inheritance)...................58
8.3 - The Lost Files.....................................................................................................58
8.4 - Acceleo Traceability................................................................................................60
9 - Advanced Use................................................................................................................61
9.1 - Launching a Generation Chain Automatically from within Eclipse.........................61
10 - Additional Environments ..............................................................................................62
10.1 - Managing Different Versions.................................................................................62
10.1.1 - Sharing a New Project...................................................................................62
10.1.2 - Sharing Modifications.....................................................................................63
10.1.3 - Loading the Modifications from Another User...............................................63
1 - Introduction
This document is a detailed tutorial aimed at allowing users to master the code generator Acceleo, a product
developed by Obeo.
The functions dealt with will permit the creation of generation modules within projects, as well as
management of products created using Acceleo over their life cycle.
Acceleo is designed for people willing to profit from MDA technologies to increase their software development
productivity. It allows the generation of files using UML, MOF, and EMF modules.
This plug-in features:
Complete integration with both the Eclipse environment and the EMF framework
Code/model Synchronization
Incremental generation
Java
Eclipse
Knowledge of the following concepts would also be an advantage, but none is essential for the understanding
of this document:
meta-models
UML2 meta-model
MDA or MDD
Reference: description and explanation of each keyword of the Acceleo script syntax
2 - Installation
Acceleo is an open source project, licensed under the Eclipse Public License (EPL), it can be downloaded
and used free of charge.
The first step in installing Acceleo is then to download and install the Eclipse platform along with EMF. It is
then possible to download and install Acceleo.
Acceleo can be installed in a number of distinct ways. Each is specific to the manner your Eclipse platform
has been installed.
The recommended installation
http://www.acceleo.org/update/.
method
is
to
make
use
of
the
following
update
site
3 - Quick Startup
This section of the tutorial is designed for those who wish to directly execute the example provided on the
Acceleo site: http://www.acceleo.org/pages/download-sample-modules/en.
Extract the contents of the archive into the directory of your choice.
The archive should contain three sub directories:
free.demo.weblog
free.uml2.gen.java
free.uml14.gen.java
Select the assistant Existing Project Into Workspace (cf. Figure 2).
Click Next .
Click Browse... (cf. Figure 3) in order to open a window which contains all the files on the disk
Click OK .
free.demo.weblog is added to the list (cf. Figure 5). Once the list contains all the desired files Click
Finish to add the project to Eclipse.
Please note that the directory src is empty (cf. Figure 6). The generation will fill this directory.
Note : The files generated are based on the UML model WebLog_fr.uml, which has been designed in
French. An English version of the model is also provided with the example. The following pages of this guide
shows pictures using the French version of the model, but it would work the same with the English version.
After clicking Launch , a progress bar shows up and once finished, the subdirectory src will contain three
packages with the generated Java files. (cf. Figure 8).
4 - Modeling
The Acceleo tool offers different modeling possibilities:
UML1.x
UML2
Ecore
DSL
4.1 - Definition
The following is a reminder of some UML specific definitions which could be helpful to
understand the tutorial.
Profile:
A profile is a standard extension mechanism for the UML language that allows the specialization of a UML
scheme for a particular domain.
It consists of a coherent set of stereotypes, tagged-values and constraints
NOTE: We do not add meta-classes, but rather annotations to existing UML meta-classes .
Standard profiles do exist: profile CORBA (OMG), profile EJB 1.0 (JCP), etc.
Stereotypes:
The stereotype concept enables elements to be classified (annotated) and acts as a new meta-model
element.
A stereotype is a GeneralizableElement . An inherited relation is therefore possible for stereotypes. It is
also possible to define abstract stereotypes in order to avoid duplications when stereotypes have common
properties.
Tagged-value:
The concept of tagged-values enables information to be added to classes. A tagged-value can be considered
as a new meta-attribute.
Constraints:
The concept of constraints is used to express the relationship between stereotypes and tagged-values.
We will now create a model folder (cf. Figure 14) in this new project.
To do so :
Right-click on the project root and select the folder creation assistant New>Folder (cf. Figure 13).
Click Finish to add the folder to Eclipse. An empty folder will then be created in the project.
Select the EMF model creation assistant New>Other>Example EMF Model Creation Wizards>UML2
Model (cf. Figure 15).
Click Next .
Enter the model name Tutorial.uml in the File name field. (cf. Figure 16).
Click Next .
From the Child list, select the Package element. (Figure 18)
Right-click on the myFirstPackage package, select the menu item " New Child>Class
Right-click on the class myClass, select the New Child>Property menu item.
Try and fill in the type of the attribute myAttribute. The type of an attribute is modified via the corresponding
property. Yet in this case, clicking on the field "type" will not allow you to use primitive types (such as String).
In the dialog that just appeared, the URI of the profile to load must be entered. The profile containing the
primitive types (integer, character string, boolean...) has the URI:
pathmap://UML_PROFILES/Standard.profile.uml. (cf. Figure 22)
Two new resources are then loaded within the model (cf. Figure 23).
It is now possible to select "String" as the type of myAttribute: select it in the modeler and modify the "type"
property (cf. Figure 24).
free.demo.weblog
free.uml2.gen.java
free.uml14.gen.java
Then select the Existing Project Into WorkSpace project import assistant (cf. Figure 33).
Click Browse... (cf. Figure 34) in order to open a window which contains all the files on the disk
Click OK .
Fill in the Project Name field with the desired name for the project and click Next (cf. Figure 40).
When the Open associated Perspective view (cf. figure 43) is displayed,
Name the new model in the following dialog then continue to the model object selection.
Open this new model, right-click on its root element and select the menu item New Child . A list of the
elements that can be added appears. (cf. Figure 50).
The following list describes the type of elements that can be added as children (presented above):
Profiles
Packages
Classes
Properties
Operations
Operation parameters
The attributes of these elements may be modified in the "properties" view (cf. figure 52).
If this view does not appear in Eclipse, right-click on the model (in the Reflective Editor ) and select the
Show Properties View menu item (cf. Figure 51).
5 - Initializing a Project
The WebLog_fr.uml model will be used for this section.
free.uml2.gen.java
This directory can be found in the archive downloaded in part 3 (cf. 3.2.2).
To import this project, refer to part 4.2.2.1 Importing a Project into Eclipse.
The two projects should appear in Eclipse (cf. Figure 53).
Now the desired generation templates should be selected; here, all of the templates contained within the
dto , dao , and ui directories (cf. Figure: 65). Continue via Next .
Finally, select the location and the name of this new generation chain (cf. Figure 66). This example chain
should be located in the free.demo.weblog directory and named MyWebLog_en.chain
This new generation chain consists of the following (cf. Figure 67):
Custom File : Other files that could be used by actions ( Custom Action )
The actions part, also called "ActionSet", contains all the tasks that must be launched. There are seven types
of actions:
Generate: applies a generator to a model, and places the whole hierarchy of the generated files the
specified target directory. The required meta-model is the one that describes the input model.
Convert Xmi: Converts an XMI 1.x file that has been exported by a non EMF modeler into an XMI 2.0 file
based on EMF. This conversion can handle UML13 and UML14 meta-models defined for EMF with either
the http://www.obeo.fr/acceleo/uml13 URI or the http://www.obeo.fr/acceleo/uml14 URI. This action is
often used before a generation action which will be applied on the resulting converted model.
Backup: Saves all the resources from one directory to another. Several levels of backup may be defined.
The backup of a target generation directory is especially useful during the template fine-tuning phase,
when the risk of getting errors is greater. However, this action may be redundant and does not always
work well with version management tools such as CVS or SVN. It should be used with moderation!
Clear: Empties the content of each file in a selected directory, including its subdirectories. This action
does not delete the resources; it simply empties their content and produces empty files.
Call : Launches the chains with the given path ( Chain Path ), substituting the declared parameters of
the sub chain by the given arguments. A double click on the new "Call" will allow the selection of the
chain to call.
Custom Action : Launch a custom action on the selected resources. To specify an action you have to put
the ID property.
The chain is created, but is empty. The required element for its operation must be added.
The first is to enter the URI of the model in the Path field of the properties view:
/free.demo.weblog/model/WebLog_fr.uml (cf. Figure 71).
Double-click on the "Model" element in the editor. This action opens a dialog box to allow a selection to
be made from among the available models. (cf. Figure 72).
Select the model directory (on the left). This selection displays the models that are present in the
directory on the right-hand side. To select a model, simply check the box at its side and click OK (cf.
Figure 73).
Then select Folder and fill the Path feature in the properties view with the
/free.demo.weblog for the target directory,
or
path
Then select the Log that has just been created, and complete the Path field of the properties view
as: /free.demo.weblog/WebLog_fr.log.txt ,
or
Double-click the Log element that has just been added to the generation chain.
Select the file that should be the generation's Error Log (cf. Figure 75).
Then select Emf Meta-model and fill in the Path property with:
http://www.eclipse.org/uml2/1.0.0/UML
or
Double-click on the meta-model that has just been created in the chain.
Select the desired meta-model URI from the list (cf. Figure 76).
Complete the Path field with the location of the desired generation file (.mt):
/free.uml2.gen.java/src/org/acceleo/modules/uml2/gen/java/dao/jdbc.mt.
or
Double-click the file to choose the generation file (.mt) (cf. Figure 77).
Documentation: Name that will be displayed by the editor for this action. The generator's file name may
be used, in order to locate it easily.
For each generation file (.mt) to launch, a corresponding Generate action must be defined. An example is
shown on Figure 79, that Generate corresponds to the template jdbc.mt .
For the other files, the manipulation is identical except for the Documentation property since it is a name
chosen by the user, which can be distinct for each file. (cf Figure 79).
6 - Generation
6.1 - Running a Generation Chain
Now that the generation chain has been created, it is possible to generate the files. Right-click the generation
chain weblog.chain and select Launch to launch the generation (cf. Figure 80).
free.demo.weblog/src/org/acceleo/sample/dto
free.demo.weblog/src/org/acceleo/sample/ihm
free.demo.weblog/src/org/acceleo/sample/jdbc
These three packages contain the Java files that have just been generated.
One of the three packages (free.demo.weblog/src/org/acceleo/sample/ihm) presents errors though. These
can be resolved by importing a Tomcat server into the project.
Right-click in the Servers view, and Select New>Server (cf. Figure 84).
Select the Apache server installed on the machine. We installed Tomcat Server 5.5 for this example (cf.
Figure 85).
Click Next then Select the server installation directory via Browse (cf. Figure 86).
Click Next .
Select the "free.demo.weblog" project and add it to the server by clicking on Add > (cf. Figure 87).
Select Add Externals JARs , find the installation directory for the Apache Software Foundation/Tomcat
5.5/common/lib server, select the servlet-api.jar file and click Open(cf. Figure 90).
Once the server has been launched, the Started icon appears for it in the Servers view (cf. Figure 94).
The next step is to open a Web Browser and go to the following URL: http://localhost:8080/free.demo.weblog/
A menu is then displayed on the browser. This page is the Index.html file (cf. Figure 96).
*NOTE* The functions are not implemented only the GUI is.
7 - Parameters
7.1 - The Generation Chains
In section 5.3 we detailed step-by-step how to create a generation chain. Yet the needs can change once the
generation chain has been created and it may happen that the generation chain no longer meets the its
needs.
It isn't necessary to create a new generation chain. Indeed, Acceleo allows the modification of an existing
generation chain.
Uncheck the previously selected template by clicking on it (cf. Figure 99). The file's check box will
then be cleared:
package
in
the
src
Right-click on this new package and select the New > File menu item.
In the file creation assistant enter the name config.properties (cf. Figure 103).
directory
for
the
The new config.properties file is created in the specified package (cf : Figure 104).
Type in the following two lines (both of which hereafter referred to as "keys"):
package.format=com.enterprise
project.name=weblog
Launch the weblog.chain chain. The files are now generated in the com.enterprise.weblog package
instead of org.acceleo.sample (cf figure 105).
file alongside the weblog.chain file, and place within it a new value for the project.name key, such as
web.weblog (supposing that the type of the product is web for the weblog). The next generation will now
include the type of product "web" in the name of the packages (cf figure 106).
8 - Update Management
8.1 - Manual Development
8.1.1 - Adding code to the servlets
It is possible to insert manual code into the generated code. Portions of the code where it is possible to insert
user code are surrounded by the tags:
//Start of user code
and
Refresh the current Web Browser page (F5). The action has been recognized.
If the generation chain is launched anew, the code surrounded by user tags is preserved.
The same test may be executed by adding code outside the Start of user code tags.
The modification is recognized when the server is restarted; however the code which was added outside the
Select the login attribute for the User class in the Business.blog package (cf. Figure 108).
Change its name property in the Properties view: change login in identifier.
String
String
String
String
String
email;
prenom;
nom;
login;
motDePasse;
In order for the modifications to be recognized, the files must be regenerated. Simply launch the generation
chain once again (cf. 6.1 Launching a Generation Chain).
The attributes are now generated as follows:
public class UtilisateurDto implements Serializable {
// serialVersionUID is used for serialization.
private static final long serialVersionUID = 1L;
protected
protected
protected
protected
protected
String
String
String
String
String
email;
prenom;
nom;
identifier;
motDePasse;
When an attribute is deleted, it is also removed from the generated files. For example, if the email attribute
is deleted from the model, it will no longer appear in the generated Java files.
Name it Administrator.
Create two String type attributes to it; name them surname and name .
Also add to it a keywords with the value Entity . Copy Paste it from one of the existing classes. (cf.
Figure 109).
Now that the class has been added to the model, the model must be saved and the generation chain must be
launch again. The new Java files have been created. (cf. Figure 110).
The files corresponding to the class have not been deleted. They must be deleted manually or use
chainweblog.clean.chain. Be careful, the code that was manually inserted between the two Start of user
code tags (cf: 8.1.1 Adding Code in the Servlets) will be deleted. This generation chain should only be used
if no code was manually inserted between the guides.
9 - Advanced Use
9.1 - Launching a Generation Chain Automatically from within Eclipse
It is possible to launch a generation chain from the application launch icon
within Eclipse.
Select Run... .
Double-click Chain .
Fill in the Name field with the desired name for the launching configuration.
10 - Additional Environments
10.1 - Managing Different Versions
In order to manage the different file versions, a version management tool such as CVS or SVN must be used.
These free software programs may be downloaded at http://www.nongnu.org/cvs/ (CVS) or
http://subversion.tigris.org/ (SVN). Once this software is installed, the easiest way to make use of them is to
install the corresponding Eclipse plug-ins. The CVS plug-in for Eclipse is installed by default. One of the SVN