Collection classes and arrays in XDE Java code model import

The Rational® UML modeling products and Rational XDE™ represent Java™ collection classes and Java arrays differently in UML.

The XDE Java Project Import wizard converts attributes, associations, and operation parameters in the imported model that are implemented as collections and arrays to the appropriate representation. The imported model can then be used with the UML-to-Java 5 and Java-to-UML transformations to keep the link between the model and the code.

In Rational XDE, the Java RTE profile for XDE code models defines tagged values to represent JavaDimensions and JavaCollection tagged values. These values specify whether the type of element is an array or collection; they determine how Rational XDE for Java generates code for attributes, associations, and parameters. The UML modeling products represent the concept of collections in the UML domain differently. When an attribute, association, or parameter has multiplicity greater than 1, two extra properties are applied in UML: IsOrdered and IsUnique.

The following table lists how the UML-to-Java transformations process parameters, attributes and associations by default. When you create or configure a UML-to-Java transformation configuration, you can specify that the transformation generate a different Java collection type. For example, when both UML properties are true, the UML Collection type is Ordered set and the generated Java type after the transformation is java.util.SortedSet.

UML properties and corresponding collection types

IsOrdered UML property IsUnique UML 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
In addition to the table above, the Java transformation uses two stereotypes, <<JavaCollection>> and <<JavaArray>> to specify the collection class to generate and the dimension of an array, respectively. These stereotypes can be applied to attributes, associations, and operation parameters. If these stereotypes are applied, the mappings in the table are ignored by the UML-to-Java 5 transformation, and the Java collection class or array specified by the stereotypes will be generated instead. This does not apply to the UML-to-Java 1.4 transformation.
When you run the XDE Java code model import wizard, collection classes in the XDE model are properly represented in the imported model. If the JavaCollection tagged value is not blank, the model element is given the <<JavaCollection>> stereotype with the proper values. If the JavaDimensions tagged value is greater than 0, the JavaArray stereotype is applied with the proper value. If either of those stereotypes is applied, the multiplicity of the model element is set to an asterisk (*).
Note: In XDE, the default multiplicity of 1 was often ignored when the JavaCollection or JavaDimensions tagged values were used. In these rare instances, where you used a collection class or array but explicitly wanted a multiplicity of 1, you must correct this construct manually in the imported model.
Related concepts
Migration of Rational XDE Java projects and code models
Related tasks
Importing XDE Java projects and source files
Manually tagging XDE Java code elements

Feedback