UML-to-Java transformations

The UML-to-Java transformations transform UML model elements into Java™ code. The UML-to-Java 1.4 transformation generates code that is compatible with the Java 2 Platform, Standard Edition 1.4 (J2SE 1.4). The UML-to-Java 5.0 transformation provides the same functionality as the UML-to-Java 1.4 transformation, and generates code that is compatible with the Java 2 Platform, Standard Edition 5.0 (J2SE 5.0).

UML-to-Java transformation profiles

The UML-to-Java 1.4 transformation profile and the UML-to-Java 5.0 transformation profile contain several stereotypes that control how the transformation transforms each model element into Java code. After you apply the profile, you can run the model validation feature, or run the transformation. See the Problems view for warnings about invalid model elements.

Validation of the source model

You can apply the UML-to-Java 1.4 transformation profile or the UML-to-Java 5.0 transformation profile to your model to validate your model for potential transformation problems that cause compilation errors in the generated Java code. The validation process checks for problems such as multiple inheritances, circular generalizations, naming conflicts, property conflicts, and visibility conflicts of private or protected top-level classes and interfaces.

The UML-to-Java 5.0 transformation validates the model elements that you specify as the source of the transformation.

Valid transformation sources

The UML-to-Java 1.4 and the UML-to-Java 5.0 transformations generate Java classes from the following UML sources:
  • UML models
  • Packages and their contents
  • Non-nested classes and their contents
  • Non-nested interfaces and their contents
  • Enumerations

The transformations transform the contents of UML models, packages, classes, and interfaces. For example, when the transformation transforms a class, the transformation also transforms the operations and properties of the class.

If you select a model or model elements from the Project Explorer view instead of using the Transformation Configuration editor, the project that you select overrides the source project specified in the transformation configuration. The transformation configuration is not affected and the source that you specify on the Source and Target page of the Transformation Configuration editor or wizard does not change.

Valid transformation targets

You can specify a Java project as the destination for the output of the UML-to-Java 1.4 transformation.

You can specify a Java project, or a source folder in a Java project, as the destination for the output of the UML-to-Java 5.0 transformation.

Alternate names for generated output

You can create a mapping model to specify alternate names for the elements that the transformation generates, without modifying the source model. You might want to specify alternate names if you want to include Java-specific details, such as naming restrictions in platform-independent models, or if the logical organization of the source model is not appropriate as target packaging.

You can specify a qualified name such as com.ibm.NewName or an unqualified name such as NewName. Specifying alternate names for packages affects all classifiers in that package, unless the classifier specifies a fully qualified name. You can also specify alternate locations in the same project for elements that the transformation generates.

Parameterized types that the UML-to-Java 5.0 transformation supports

You can specify the following Java collection types as the generic interface for parameterized types, or generics, when you create or configure a UML-to-Java 5.0 transformation:
  • AbstractCollection
  • AbstractList
  • AbstractMap
  • AbstractSequentialList
  • AbstractSet
  • ArrayList
  • BitSet
  • Collection
  • HashMap
  • HashSet
  • Hashtable
  • LinkedList
  • List
  • Map
  • Set
  • SortedMap
  • SortedSet
  • Stack
  • TreeMap
  • TreeSet
  • WeekHashMap
  • Vector

The transformation does not generate parameterized type information for other Java collections.

Annotation of Java source code with UML collection information

The UML-to-Java 5.0 transformation adds comments about UML collection types to the Java collection types that it generates. These comments enable the visual development tools to create accurate visual representations of the Java collection types. The UML-to-Java 1.4 transformation does not generate comments about UML collection types in the Java source that it generates.

The following table lists an example of an association relationship between Class1 and Class2; the association relationship specifies a multiplicity. The table also lists the generated source code and visual representation of the association relationship.
UML elements UML-to-Java 5.0 transformation output Visual representation of transformation output
This image shows UML model elements named Class1 and Class2, with an association relationship  that specifies a multiplicity. The transformation generates the following source code if the Use Java 5 check box is selected in the transformation configuration:
public class Class1 {
	/** 
	 * @uml.annotations for <code>class2</code>
	 *     collection_type="Class2"
	 * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
	 */
	private Set<Class2> class2;
}
This image shows the visual representation of Class1, which contains a  collection of  Class2 classes.
The transformation generates the following source code if the Use Java 5 check box is not selected in the transformation configuration:
public class Class1 {
	/** 
	 * @uml.annotations for <code>class2</code>
	 *     collection_type="Class2"
	 * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
	 */
	private Set class2;
}

Documentation of relationships in transformation output

The UML-to-Java 5.0 transformation transforms UML relationship documentation into Javadoc information for the following UML relationships:
  • Associations
  • Generalizations
  • Implementations
  • Realizations
To transform usage relationship documentation into Javadoc information, you must configure the UML-to-Java 5.0 transformation to generate J2SE 5.0 code.

The transformation adds documentation for generalization, implementation, and realization relationships to the UML documentation for the originating class in each relationship. The transformation also adds the documentation for these relationships to the Javadoc information for the generated target class of each relationship.

For associations, the transformation adds the UML documentation to the documentation of each associated property.

Modeling of Java exceptions

In a UML model, you can use a UML operation to represent a Java method. In the RaisedException property of a UML operation, you can specify the UML classes that represent the exception objects that are associated with the operation. When you run the UML-to-Java 5.0 transformation, the transformation generates a Java throws statement that contains the classes that you specify in the RaisedException property.

Visualization of generated Java elements

If you want the output of the UML-to-Java transformation to be the primary engineering artifact, you can specify that the transformation create a direct relationship between the source UML objects and the generated Java code. Creating direct relationships deletes the source UML objects and replaces them with visual representations of the source objects. Both the UML-to-Java 1.4 transformation and UML-to-Java 5.0 transformation enable you to replace UML objects with visual representations of the source objects.

Derived relationships

Both the UML-to-Java 1.4 transformation and the UML-to-Java 5.0 transformation enable you to create derived relationships from UML source model elements to the generated Java classes. You can then view the derived relationships in a topic diagram by creating and running model queries.

Integration with team support

Both the UML-to-Java 1.4 transformation and the UML-to-Java 5.0 transformation provide integration functionality with CVS, Rational® ClearCase®, and Rational ClearCase LT version control systems, which enables you to automatically check out files or add new files.

Related tasks
Transforming UML models into Java code
Applying UML-to-Java transformation profiles
Specifying exceptions in UML operations
Specifying sources and targets for UML-to-Java transformations
Specifying the Java collection types that UML-to-Java transformations generate
Enabling team capabilities
Related reference
Interpretation of UML elements by UML-to-Java transformations

Feedback