throws CorbaBindingException {
CorbaUnionHandler obj = null;
CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
try {
Union unionType = (Union)typeDefinition;
StartElement unionStartEl = reader.nextEvent().asStartElement();
obj = new CorbaUnionHandler(unionStartEl.getName(), idlType, tc, unionType);
// Read the discriminator value from the reader. We can't rely on the value from
// Stax since it may be a default value if the caller has forgotten to explicitly
// set the discriminator in their union class. This could cause all sorts of
// problems when we try create the CORBA union. For now, we'll just read and ignore.
// TODO: Revisit this if we want to make this assumption.
reader.nextEvent().asStartElement().getName();
reader.nextEvent().asCharacters();
reader.nextEvent().asEndElement();
// Build the entire union with all branches, etc. Then read info from the XML Event Reader
StartElement branchElement = reader.peek().asStartElement();
String branchName = branchElement.getName().getLocalPart();
List<Unionbranch> branches = unionType.getUnionbranch();
for (Iterator<Unionbranch> iter = branches.iterator(); iter.hasNext();) {
Unionbranch branch = iter.next();
CorbaObjectHandler branchObj = null;
if (branch.getName().equals(branchName)) {
branchObj = readObjectFromStax(reader, branch.getIdltype(), true);
// We also need to set the discriminator since this is the branch with the actual
// union value
CorbaObjectHandler discObj =
CorbaHandlerUtils.createTypeHandler(orb, new QName("discriminator"),
unionType.getDiscriminator(), typeMaps);
obj.setDiscriminator(discObj);
// Determine the value of the discriminator.
List<CaseType> branchCases = branch.getCase();
String discValue = null;