private IdlType createUnion(CorbaTypeImpl ctype, IdlScopeBase scope,
String local) throws Exception {
Union u = (Union)ctype;
boolean undefinedCircular = false;
IdlType disc = findType(u.getDiscriminator());
IdlUnion union = IdlUnion.create(scope, local, disc);
scope.holdForScope(union);
Iterator it = u.getUnionbranch().iterator();
while (it.hasNext()) {
Unionbranch ub = (Unionbranch)it.next();
QName qname = ub.getIdltype();
IdlType bt = findType(qname);
boolean isDefault = false;
if (ub.isSetDefault()) {
isDefault = ub.isDefault();
}
IdlUnionBranch b = IdlUnionBranch.create(union, ub.getName(), bt, isDefault);
Iterator it2 = ub.getCase().iterator();
while (it2.hasNext()) {
b.addCase(((CaseType)it2.next()).getLabel());
}
// Ensure that this union will not be written until all of its circular members are
// defined, unless the undefined circular members are of sequence type.
if (!undefinedCircular && !(bt instanceof IdlSequence)) {
String mlocal = qname.getLocalPart();
String mname[] = unscopeName(mlocal);
undefinedCircular = null != root.lookup(mname, true);
}
union.addBranch(b);
}
if (undefinedCircular) {
scope.parkHeld();
} else {
scope.promoteHeldToScope();
if (union.isCircular()) {
// resolving this union closed a recursion
scope.flush();
}
}
return union;