Interpretation of UML elements by UML-to-Java transformations

The Java™ elements that the transformations generate depend on the source UML elements and their characteristics.

The following table lists how the transformations transform UML elements into Java elements.

UML element Java element
Package Java package with the same name
Package with the «perspective» stereotype Ignored
Package with the «analysis» or «Analysis» keyword Ignored
Class Java class with the same name and visibility
Class with an Is Leaf property Java class is final if true
Class with an Is Abstract property Java class is abstract if true
Class with a generalization relationship Java class extends the specified superclass
Interface realization or Realization relationship between a class and an interface Java class implements the specified interface
Interface Java interface with the same name and visibility
Interface with a generalization relationship Java interface extends the specified interface
Enumeration Java enumeration

If the transformation is not configured to generate code that is compatible with J2SE 5.0, the transformation generates a Java interface with the same name and visibility.

Enumeration literal Enumerator
Operation Java method with the same name and visibility
Operation with an Is Static property Java method is static if true
Operation with an Is Abstract property Java method is abstract if true
Operation with an Is Leaf property Java method is final if true
Operation with the same name as its class Java constructor
Operation with the «create» stereotype Java constructor
Operation with one or more UML classes specified in the RaisedException property Java throws statement followed by the list of throwable classes
Parameter Java parameter with the same name
Parameter with a type property Java parameter has the specified type, which can be another class or a primitive type
Parameter with a direction property Java method has a return <param type> if it is set to return

Java method with <param type> <param name> in its method signature if it is not set to return

Parameter or property with multiplicities:
0..1 Attribute or reference
1 Attribute
N (N>1) Array
x..* (for example, 1..*), *, or x..y See the following table.
In a list of operation parameters, if the last operation parameter has a multiplicity of * or x..*, by default it is transformed into a Java vararg (variable arity argument, which is indicated by an ellipsis after the type).
Note: To override this default behaviour and transform the last parameter into a Java collection, select the corresponding extension in the transformation configuration.

If the operation parameter has a multiplicity of x..y, it is transformed into an array.

Property Java field with the same name and visibility
Property with an Is Static property Java field is static if true
Property with an Is Leaf property Java field is final if true
Property with a type property Java field has the specified type, which can be another class or a primitive type
Note: Some characters, such as a space, are not valid in Java identifiers. The transformations replace invalid characters with an underscore (_) to create a valid identifier. This replacement can cause name conflicts that prevent the transformations from generating duplicate classes and interfaces. To avoid these replacement issues, rename the elements or use the mapping feature to specify an alternate name that does not modify the source model.
The following table lists how the transformations process parameters and properties with multiplicity x..*, *, or x..y. When you create or configure a UML-to-Java transformation configuration, you can specify that the transformation generate a different Java collection type. The Java collection type defined in the UML-to-Java transformation configuration is applied to all parameters except the last one, which by default is transformed into a vararg. To transform the last parameter that has multiplicity x..*, *, or x..y into a Java collection, you must complete one of the following steps:
  • Select the corresponding transformation extension in the transformation configuration. See the related task topic below for information about configuring a UML-to-Java transformation.
  • Apply the «JavaCollection» stereotype to the corresponding UML parameter or property, and set the collectionType property of the stereotype.
isOrdered property isUnique property UML collection Generated Java type
true true Ordered set java.util.SortedSet
true false Sequence java.util.List
false true Set java.util.Set
false false Bag java.util.Collection

UML documentation

The transformation copies the text in the UML documentation field of a UML element and places it between the following tags in Java code that the transformation generates for the element:
/*
 * <!-- begin-UML-doc -->
 * <!-- end-UML-doc -->
 */

Feedback