UML 2.1 to Java
From AcceleoWiki
| Module UML 2.1 to Java | |
| |
| Status: | Incubation |
| Licence: | EPL |
| Target: | Java |
| Metamodel: | UML 2.1 |
| Inital contributor: | CEA Obeo |
| Contact: | Gonzague Reydet |
This project aims to generate Java applications from UML 2.1 models.
Contents |
Guidelines
- Easy to use
- Standard UML input model (no complex UML profile)
Features
- Java files generated from model elements:
- Classes
- Interfaces
- Enumerations
- Generated files respect the package structure
- Comments generated from comment model elements
- Association management
- Generalization management
- Interface realization management
- Accessors generation
- Method return generation
- Constructors generation
- Type conversion and default value system configuration
- Model validator
See the history page for a more complete list of changes upon generator versions.
Planned features
- Implementation of abstract methods from interface realizations and inherited abstract classes
- Enhanced model validation rules
- Enhanced multiplicity and visibility management
Installation
The installation process is described on the installing a module web page.
Contribute!
- Access to the project sources using the Team Project Set file of the UML 2.1 to Java generator module. Understand how to use this file reading the tutorial: how to get and modify generator module sources.
- To report a bug, use the Acceleo module tracker.
How to use the generator?
Create a Module Launcher Chain
In a project (Java project), containing the input UML model, click on "New > Other..." and select "Module Launcher" on the Acceleo folder:

Then, select the UML 2.1 to Java generation module:

Then, give a name to your new chain:

Finally, enter the 3 parameters required by this generation module:
- The error log file
- The output source folder
- The input UML model
Launch the generation
To launch the generation process, right click on the chain, then "Launch":
Upon the generation process completed, the generated sources should appear on the specified output folder.
Optional parameters
Several parameters can be set to personalize the generation:
| Property name | Description | Default value |
|---|---|---|
| tuple.genArrays | Set the representation of multiple attributes. Can be either arrays or collections | false |
| tuple.ordered.class | Set the class used for ordered collections | java.util.ArrayList |
| tuple.notOrdered.class | Set the class used for not ordered collections | java.util.HashSet |
| gen.constructor | Enable/Disable constructor generation | true |
| gen.accessors | Enable/Disable accessor generation (get/set) | true |
| gen.listAccessors | Enable/Disable list accessor generation (add/remove) | true |
| gen.biDirections | Enable/Disable bi-directionality generation | true |
| gen.comment.date | Enable/disable the date/time generation in code heading comments | true |
| gen.root | Set the root package hierarchy of the generated code | |
| java.typeconversion.* | Set a type conversion for the given type. Replace the '*' by the name of your model type | Float -> double |
| java.defaultvalue.* | Set a specific default value for the given type. Replace the '*' by the name of your model type | Integer -> 0 Boolean -> true Float -> 0.0 |
| validator.genOutput | Enable/Disable the creation of a validation result log file | true |
To precise such parameters to the generation module, add a property file (with .properties extension) next to the chain you created to launch the generation. For example, you can create a file UML2Java.properties with the following content:
# Generate arrays instead of collections tuple.genArrays=true # Don't generate accessors gen.genAccessors=false # Don't add generation date and time in code heading comments gen.comment.date=false # Add type customization java.typeconversion.Integer=int java.typeconversion.Boolean=boolean java.defaultvalue.Integer=1


