use of org.apache.cxf.binding.corba.wsdl.Unionbranch in project cxf by apache.
the class WSDLToCorbaHelper method createNillableUnion.
protected CorbaType createNillableUnion(QName name, QName schemaType, QName membertype, boolean isQualified) {
Union nilUnion = new Union();
nilUnion.setName(name.getLocalPart());
nilUnion.setType(schemaType);
nilUnion.setQName(name);
nilUnion.setDiscriminator(CorbaConstants.NT_CORBA_BOOLEAN);
String id = REPO_STRING + nilUnion.getQName().getLocalPart().replace('.', '/') + IDL_VERSION;
nilUnion.setRepositoryID(id);
Unionbranch branch = new Unionbranch();
branch.setName("value");
branch.setIdltype(membertype);
branch.setDefault(false);
if (isQualified) {
branch.setQualified(true);
}
CaseType caseType = new CaseType();
caseType.setLabel("TRUE");
branch.getCase().add(caseType);
nilUnion.getUnionbranch().add(branch);
nilUnion.setNillable(true);
return nilUnion;
}
use of org.apache.cxf.binding.corba.wsdl.Unionbranch in project cxf by apache.
the class CorbaObjectReader method readUnion.
public void readUnion(CorbaUnionHandler unionHandler) throws CorbaBindingException {
Union unionType = (Union) unionHandler.getType();
List<Unionbranch> branches = unionType.getUnionbranch();
CorbaObjectHandler discriminator = unionHandler.getDiscriminator();
if (!branches.isEmpty()) {
String discLabel = null;
if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
CorbaEnumHandler disc = (CorbaEnumHandler) discriminator;
readEnumDiscriminator(unionHandler, disc);
discLabel = disc.getValue();
} else {
read(discriminator);
discLabel = ((CorbaPrimitiveHandler) discriminator).getDataFromValue();
}
// Now find the label in the union to get the right case
Unionbranch defaultBranch = null;
boolean caseFound = false;
for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
Unionbranch branch = branchIter.next();
if (branch.isSetDefault() && branch.isDefault()) {
defaultBranch = branch;
}
List<CaseType> cases = branch.getCase();
for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
CaseType c = caseIter.next();
if (c.getLabel().equalsIgnoreCase(discLabel)) {
CorbaObjectHandler branchObj = unionHandler.getBranchByName(branch.getName());
this.read(branchObj);
unionHandler.setValue(branch.getName(), branchObj);
caseFound = true;
break;
}
}
if (caseFound) {
break;
}
}
// found the default case.
if (!caseFound && defaultBranch != null) {
CorbaObjectHandler branchObj = unionHandler.getBranchByName(defaultBranch.getName());
this.read(branchObj);
unionHandler.setValue(defaultBranch.getName(), branchObj);
}
}
}
use of org.apache.cxf.binding.corba.wsdl.Unionbranch in project cxf by apache.
the class CorbaHandlerUtils method initializeUnionHandler.
public static void initializeUnionHandler(ORB orb, CorbaObjectHandler obj, CorbaTypeMap typeMap, ServiceInfo serviceInfo, Map<QName, CorbaObjectHandler> seenTypes) {
Union unionType = (Union) obj.getType();
// First handle the discriminator
CorbaObjectHandler discObj = initializeObjectHandler(orb, new QName("discriminator"), unionType.getDiscriminator(), typeMap, serviceInfo, seenTypes);
((CorbaUnionHandler) obj).setDiscriminator(discObj);
QName typeName = unionType.getType();
seenTypes.put(obj.getIdlType(), obj);
// Now handle all of the branches
List<Unionbranch> unionBranches = unionType.getUnionbranch();
for (int i = 0; i < unionBranches.size(); i++) {
Unionbranch branch = unionBranches.get(i);
QName branchName;
if (branch.isSetQualified() && branch.isQualified() && (typeName != null)) {
branchName = new QName(typeName.getNamespaceURI(), branch.getName());
} else {
branchName = new QName("", branch.getName());
}
QName branchIdlType = branch.getIdltype();
CorbaObjectHandler branchObj = initializeObjectHandler(orb, branchName, branchIdlType, typeMap, serviceInfo, seenTypes);
((CorbaUnionHandler) obj).addCase(branchObj);
}
seenTypes.remove(obj.getIdlType());
}
use of org.apache.cxf.binding.corba.wsdl.Unionbranch in project cxf by apache.
the class CorbaUnionListener method processStartElement.
public void processStartElement(QName name) {
if (currentTypeListener == null) {
for (Unionbranch branch : branches) {
CorbaObjectHandler content;
QName unionName = null;
String branchName = branch.getName();
if (branch.getName().equals(name.getLocalPart())) {
unionName = name;
} else if (branches.size() == 1) {
unionName = handler.getName();
}
if (unionName != null) {
CorbaObjectHandler discObj = CorbaHandlerUtils.createTypeHandler(orb, new QName("discriminator"), unionType.getDiscriminator(), typeMap);
((CorbaUnionHandler) handler).setDiscriminator(discObj);
String descriminatorValue = determineDescriminatorValue(branch);
((CorbaUnionHandler) handler).setDiscriminatorValueFromData(descriminatorValue);
currentTypeListener = CorbaHandlerUtils.getTypeListener(unionName, branch.getIdltype(), typeMap, orb, serviceInfo);
currentTypeListener.setNamespaceContext(ctx);
content = currentTypeListener.getCorbaObject();
((CorbaUnionHandler) handler).setValue(branchName, content);
if (unionType.isSetNillable() && unionType.isNillable()) {
currentTypeListener.processStartElement(name);
}
} else {
QName emptyBranchContentQName = new QName(name.getNamespaceURI(), branchName);
content = CorbaHandlerUtils.initializeObjectHandler(orb, emptyBranchContentQName, branch.getIdltype(), typeMap, serviceInfo);
}
((CorbaUnionHandler) handler).addCase(content);
}
} else {
currentTypeListener.processStartElement(name);
}
}
use of org.apache.cxf.binding.corba.wsdl.Unionbranch in project cxf by apache.
the class CorbaUnionListener method processWriteAttribute.
public void processWriteAttribute(String prefix, String namespaceURI, String localName, String val) {
if ("nil".equals(localName)) {
CorbaPrimitiveHandler discObj = new CorbaPrimitiveHandler(new QName("discriminator"), unionType.getDiscriminator(), orb.get_primitive_tc(TCKind.from_int(TCKind._tk_boolean)), null);
discObj.setValue(Boolean.FALSE);
((CorbaUnionHandler) handler).setDiscriminator(discObj);
Unionbranch branch = branches.get(0);
QName emptyBranchContentQName = new QName(handler.getName().getNamespaceURI(), branch.getName());
CorbaObjectHandler content = CorbaHandlerUtils.initializeObjectHandler(orb, emptyBranchContentQName, branch.getIdltype(), typeMap, serviceInfo);
((CorbaUnionHandler) handler).addCase(content);
} else if (currentTypeListener != null) {
currentTypeListener.processWriteAttribute(prefix, namespaceURI, localName, val);
}
}
Aggregations