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.
- Add a new stereotype called "Array" that is applicable to association ends.
- 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 Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21446052