Java transformation profile

The UML-to-Java transformation profile contains several stereotypes that you can apply to validate elements in the source model, and stereotypes that control how the transformation generates Java™ code.
Important: Do not apply the UML-to-Java (deprecated) transformation profile to a source model. Instead, you should apply the UML-to-Java transformation profile. The deprecated profile does not contain new stereotypes, and the validation rules are different for stereotypes with the same name as the stereotypes in the UML-to-Java transformation profile. The only time that you might apply the deprecated profile is if you migrate a UML model from a version 6 release of IBM® Rational® modeling products, and want to validate the source model automatically, using an older set of validation rules.
The UML-to-Java transformation profile contains stereotypes that can validate source model elements. Applying the profile to a model does not apply the stereotypes in the profile automatically. You must apply the appropriate stereotype to each model element that you want to validate. These validation stereotypes are used only in the modeling phase and do not affect how the transformation generates Java source 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. A warning dialog box is displayed if the element does not comply to the validation rules. For example, if you apply the «JavaClass» stereotype to a class in the source model and rename the class to My$Class, a warning message is displayed.
Note: Larger, complex models might take more time to open, save, or close, depending on the number of stereotypes applied that validate source model elements.
The following table lists the stereotypes that you can apply to validate source model elements.
Stereotype Validated source model element
«JavaClass» Class
«JavaEnum» Enumeration
«JavaEnumConstant» Enumeration literal
«JavaField» Attribute in a class
«JavaInterface» Interface
«JavaMethod» Operation in a class
«JavaPackage» Package
«JavaParameter» Input, output, or return parameter

The UML-to-Java transformation profile also contains stereotypes that the UML-to-Java transformation uses to generate Java code for arrays and collections. These stereotypes are applied automatically when you run the transformation. Applying these stereotypes does not affect modeling activities.

The following table lists the stereotypes that you can apply to specify how the transformation generates Java code.
Note: Applying the «JavaArray» or «JavaCollection» stereotype overrides the default collection information that you specify in the transformation configuration.
Stereotype Applicable UML element Properties Property description and values Transformation result
«JavaArray» Property, parameter dimensions Specifies the size of the array

Default value is 1

Java arrays of arbitrary dimensions

For example, to generate an array of the form int[][], apply the «JavaArray» stereotype to a property or parameter, set the type of the attribute to primitive type int, and set the dimensions value to 2

«JavaCollection» Property or parameter; represents Java collection classes such as Set, List collectionType Set to the fully qualified name of the Java collection to generate

Default value is java.util.Collection

Java collection classes such as Set, or List

For example, to generate a map of type Hashmap<String, Object>, you can apply the «JavaCollection» stereotype to a UML property or parameter, set the collectionType to java.util.Hashmap, and set the keyType to java.lang.String

keyType Set to the fully qualified name of a key type used in java.util.Maps

Do not specify a value if the collectionType property is not a Java map class

No default value

«JavaRedirect» Any UML type redirect Redirects to any other UML type The UML to Java transformation will generate all references to the «JavaRedirect» as the redirected type instead. This allows for any type to be specified as a UML template parameter, for the purposes of Java code generation.

The UML-to-Java transformation profile also contains stereotypes that you can apply to UML elements to model Java generic types.

The following table lists the stereotypes that you can apply to model elements to model Java generics:
Stereotype Applicable UML element
«JavaGenericInstance» Class
«JavaWildCard» TemplateParameterSubstitution
  • To specify an unbounded wildcard, apply the «JavaWildCard» stereotype to the actual parameter of the substitution in a template binding.
  • To specify a bounded wildcard, apply the stereotype as described for an unbounded wildcard, and set the extends or super stereotype property.
«JavaTypeParameter» TemplateParameter


Feedback