public int helperType (int index, String indent, TCOffsets tcoffsets,
String name, SymtabEntry entry, PrintWriter stream)
{
TCOffsets innerOffsets = new TCOffsets ();
UnionEntry u = (UnionEntry)entry;
String discTypeCode = "_disTypeCode" + index;
String membersName = "_members" + index;
// Build discriminator tc
stream.println (indent + "org.omg.CORBA.TypeCode " + discTypeCode + ';');
index = ((JavaGenerator)u.type ().generator ()).type (index + 1, indent,
innerOffsets, discTypeCode, u.type (), stream);
tcoffsets.bumpCurrentOffset (innerOffsets.currentOffset ());
stream.println (indent + "org.omg.CORBA.UnionMember[] " + membersName +
" = new org.omg.CORBA.UnionMember [" + unionLabelSize(u) + "];");
String tcOfMembers = "_tcOf" + membersName;
String anyOfMembers = "_anyOf" + membersName;
stream.println (indent + "org.omg.CORBA.TypeCode " + tcOfMembers + ';');
stream.println (indent + "org.omg.CORBA.Any " + anyOfMembers + ';');
innerOffsets = new TCOffsets ();
innerOffsets.set (entry);
int offsetForUnion = innerOffsets.currentOffset ();
for (int i = 0; i < u.branches ().size (); ++i) {
UnionBranch branch = (UnionBranch)u.branches ().elementAt (i);
TypedefEntry member = branch.typedef;
Vector labels = branch.labels;
String memberName = Util.stripLeadingUnderscores (member.name ());
if (labels.size() == 0) {
stream.println ();
stream.println (indent + "// Branch for " + memberName +
" (Default case)" );
SymtabEntry utype = Util.typeOf (u.type ());
stream.println (indent + anyOfMembers + " = org.omg.CORBA.ORB.init ().create_any ();");
// For default member, label is the zero octet (per CORBA spec.)
stream.println (indent + anyOfMembers + ".insert_octet ((byte)0); // default member label");
// Build typecode
innerOffsets.bumpCurrentOffset (4); // label value
index = ((JavaGenerator)member.generator ()).type (index, indent, innerOffsets, tcOfMembers, member, stream);
int offsetSoFar = innerOffsets.currentOffset ();
innerOffsets = new TCOffsets ();
innerOffsets.set (entry);
innerOffsets.bumpCurrentOffset (offsetSoFar - offsetForUnion);
// Build union member
stream.println (indent + membersName + '[' + i + "] = new org.omg.CORBA.UnionMember (");
stream.println (indent + " \"" + memberName + "\",");
stream.println (indent + " " + anyOfMembers + ',');
stream.println (indent + " " + tcOfMembers + ',');
stream.println (indent + " null);");
} else {
Enumeration enumeration = labels.elements() ;
while (enumeration.hasMoreElements()) {
Expression expr = (Expression)(enumeration.nextElement()) ;
String elem = Util.parseExpression( expr ) ;
stream.println ();
stream.println (indent + "// Branch for " + memberName +
" (case label " + elem + ")" );
SymtabEntry utype = Util.typeOf (u.type ());
// Build any
stream.println (indent + anyOfMembers + " = org.omg.CORBA.ORB.init ().create_any ();");
if (utype instanceof PrimitiveEntry)