IBM Support

How to create Arrays with Java in Rational Rhapsody

Question & Answer


Question

How do you generate a Java array instead of a list object for an Association in IBM Rational Rhapsody?

Answer

Due to the way Rational Rhapsody implements array-based collections, a fixed multiplicity must be defined on the association.

For example, defining a multiplicity of 2 will generate code for an array but will also add initialization code in the constructor and helper functions to add and remove element to the collection, all based on the multiplicity value.

Because of this implementation, it is not possible to have multiplicity of * and generate an array.

Setting "Implementation" property of the association to "StaticArray" gives a code generation checker message.

A possible solution is to use a user defined collection template, defined on a stereotype.

  1. Add a new stereotype called "Array" that is applicable to association ends.
  2. Override following properties on the stereotype:
    • CG::Relation::Implementation = "User" // use user defined template for the association end
    • CG::Relation::GetGenerate = false // do not add auto-generated empty getter
    • CG::Relation::SetGenerate = false // same for setter
    • Java(1.5)Containers::User::CType = "$target[] $cname"
    • Java(1.5)Containers::User::IterType = "int" // has to be non-empty to allow setting multiplicity "*" for the association.
    Create an association end and apply the stereotype to it.

    The array will be now generated.

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.5.0.1;7.5.1;7.5.1.1;7.5.2;7.5.2.1","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21446052