OOPortal OOPortal


IDL Constructed Types   «Prev 

Union example Weather Service

The IDL union ForecastDetail is mapped to a corresponding Java class
//union.idl
// Union example - Weather Service
The IDL union ForecastDetail is mapped to a corresponding Java class

The branch type is mapped to a corresponding discriminator field
package Module 4;
public final class ForecastDetail 
implements org.omg.CORBA.portable.IDLEntity{
.....
  public Module4.ForecastType discriminator();
The branch type is mapped to a corresponding discriminator field and a discriminator() accessor for the field.

The hot/humidity branch is mapped to the corresponding field
The hot/humidity branch is mapped to the corresponding field, an accessor and a mutator.

The cold/wind chill branch is mapped to the corresponding field
package Module 4;
public final class ForecastDetail 
 implements org.omg.CORBA.portable.IDLEntity
{
.....
  private double windchill;
...
  private double windchill()
  { 
   if (discriminator != Module4.ForecastType.cold)
    throw new org.omg.CORBA.BAD_OPERATION();
   return windchill;
  }
  public void windchill(double _x)
  {
   discriminator = Module4.ForecastType.cold;
   windchill = _x;
  }
The cold/wind chill branch is mapped to the corresponding field, an accessor, and a mutator.