discriminator = check_val;
return;
}
}
// no unused value found
throw new TypeMismatch();
}
case TCKind._tk_char:
{
// assume there is a printable char not used as a label!
boolean found;
org.omg.CORBA.Any check_val = null;
// 33 to 126 defines a reasonable set of printable chars
for (int i = 0; i < 127; i++)
{
check_val = orb.create_any ();
check_val.insert_char ((char) i);
found = false; // is the value used as a label?
for( int j = 0; j < type().member_count() && !found; j++ )
{
if( check_val.equal( type().member_label(j)) )
{
found = true;
}
}
if( !found )
{
// the value is not found among the union's label
discriminator = check_val;
return;
}
}
// no unused value found, should not happen
throw new TypeMismatch();
}
case TCKind._tk_short:
{
// assume there is an unsigned short not used as a label!
boolean found;
org.omg.CORBA.Any check_val = null;
short max_short = 32767;
for (short i = 0; i < max_short; i++)
{
check_val = orb.create_any ();
check_val.insert_short (i);
found = false; // is the value used as a label?
for( int j = 0; j < type().member_count() && !found; j++ )
{
if( check_val.equal( type().member_label(j)) )
{
found = true;
}
}
if( !found )
{
// the value is not found among the union's label
discriminator = check_val;
return;
}
}
// no unused value found, should not happen
throw new TypeMismatch();
}
case TCKind._tk_long:
{
// assume there is an unsigned int not used as a label!
boolean found;
org.omg.CORBA.Any check_val = null;
int max_int = 2147483647;
for (int i = 0; i < max_int; i++)
{
check_val = orb.create_any ();
check_val.insert_long (i);
found = false; // is the value used as a label?
for( int j = 0; j < type().member_count() && !found; j++ )
{
if( check_val.equal( type().member_label(j)) )
{
found = true;
}
}
if( !found )
{
// the value is not found among the union's label
discriminator = check_val;
return;
}
}
// no unused value found, should not happen
throw new TypeMismatch();
}
case TCKind._tk_longlong:
{
// assume there is an unsigned long not used as a label!
boolean found;
org.omg.CORBA.Any check_val = null;
long max_long = 2147483647; // this should be sufficient!
for (long i = 0; i < max_long; i++)
{
check_val = orb.create_any ();
check_val.insert_longlong (i);
found = false; // is the value used as a label?
for( int j = 0; j < type().member_count() && !found; j++ )
{
if( check_val.equal( type().member_label(j)) )
{
found = true;
}
}
if( !found )
{
// the value is not found among the union's label
discriminator = check_val;
return;
}
}
// no unused value found, should not happen
throw new TypeMismatch();
}
case TCKind._tk_enum:
{
org.omg.DynamicAny.DynEnum dynEnum = null;
try
{
dynEnum = (org.omg.DynamicAny.DynEnum) dynFactory.create_dyn_any_from_type_code (discriminator.type());
}
catch( InconsistentTypeCode e )
{
throw unexpectedException(e);
}
boolean found;
for( int i = 0; i < discriminator.type().member_count(); i++ )
{
try
{
dynEnum.set_as_string( discriminator.type().member_name(i) );
}
catch( InvalidValue e )
{
throw unexpectedException(e);
}
found = false; // is the value used as a label?
for( int j = 0; j < type().member_count() && !found; j++ )
{
if( dynEnum.to_any ().equal( type().member_label(j) ) )
{
found = true;
}
}
if( !found )
{
// the enum value is not found among the union's label
discriminator = dynEnum.to_any();
return;
}
}
// no unused value found
throw new TypeMismatch();
}
default:
throw new TypeMismatch();
}
}
catch (org.omg.CORBA.TypeCodePackage.BadKind e)
{
throw unexpectedException(e);