Defining CORBA unions

You can define CORBA unions in your model and have them generated in .idl files.

Procedure

To define a CORBA union:

  1. Add a new type to a package with the CORBAModule stereotype, or a class with the CORBAInterface stereotype.
  2. Open the Features window for the type you created, and set the Kind field to Union.
  3. For the type created, set the value of the property CORBA::Type::Discriminator to the type of the discriminator that you will be using, for example, short.
  4. Add attributes to the type, representing each of the data types in the union, for example, attributes named: length_short, length_long, and length_double.
  5. For each of the attributes, set the attribute type appropriately, for example: short for length_short, long for length_long, and double for length_double.
  6. For each of the attributes, open the Features window, and set the value of the property CORBA::Attribute::UnionCase. The value of the property should be the discriminator value to use for the attribute. The values should reflect the type you specified for the property CORBA::Type::Discriminator. Note that you can also set the property UnionCase to the string default for the data type that you want to use as the default data type for the union. For example, set the value of the UnionCase property to 1 for the attribute length_short, 2 for the attribute length_long, and default for the attribute length_double.

Example

If you use the example values mentioned in the steps, the generated code will resemble the following:

    union length switch (short) {
        case 1 :	short length_short;		//## attribute length_short
        case 2 :	long length_long;		//## attribute length_long
        default :	double length_double;		//## attribute length_double
    };