use of org.apache.cxf.binding.corba.wsdl.Union in project cxf by apache.
the class CorbaObjectWriter method writeUnion.
public void writeUnion(CorbaObjectHandler obj) throws CorbaBindingException {
Union unionType = (Union) obj.getType();
List<Unionbranch> branches = unionType.getUnionbranch();
if (!branches.isEmpty()) {
CorbaObjectHandler discriminator = ((CorbaUnionHandler) obj).getDiscriminator();
this.write(discriminator);
CorbaObjectHandler unionValue = ((CorbaUnionHandler) obj).getValue();
if (unionValue != null) {
this.write(unionValue);
}
}
}
use of org.apache.cxf.binding.corba.wsdl.Union in project cxf by apache.
the class CorbaUnionEventProducer method checkIsNil.
private boolean checkIsNil(CorbaUnionHandler handler) {
boolean isItNil = false;
Union unionType = (Union) handler.getType();
if (unionType.isSetNillable() && unionType.isNillable()) {
CorbaPrimitiveHandler descHandler = (CorbaPrimitiveHandler) handler.getDiscriminator();
Boolean descValue = (Boolean) descHandler.getValue();
if (!descValue.booleanValue()) {
isItNil = true;
}
}
return isItNil;
}
use of org.apache.cxf.binding.corba.wsdl.Union in project cxf by apache.
the class WSDLToCorbaBindingTypeTest method testNillableType.
@Test
public void testNillableType() throws Exception {
try {
String fileName = getClass().getResource("/wsdl/nillable.wsdl").toString();
generator.setWsdlFile(fileName);
generator.addInterfaceName("NillablePortType");
Definition model = generator.generateCORBABinding();
Document document = writer.getDocument(model);
Element typemap = getElementNode(document, "corba:typeMapping");
assertNotNull(typemap);
assertEquals(2, typemap.getElementsByTagName("corba:union").getLength());
assertEquals(1, typemap.getElementsByTagName("corba:struct").getLength());
TypeMappingType mapType = (TypeMappingType) model.getExtensibilityElements().get(0);
WSDLToIDLAction idlgen = new WSDLToIDLAction();
idlgen.setBindingName("NillableCORBABinding");
idlgen.setOutputFile("nillable.idl");
idlgen.generateIDL(model);
Union un = (Union) mapType.getStructOrExceptionOrUnion().get(2);
assertEquals("Name is incorrect for Union Type", "long_nil", un.getName());
assertEquals("Type is incorrect for Union Type", "PEl", un.getType().getLocalPart());
Unionbranch unbranch = un.getUnionbranch().get(0);
assertEquals("Name is incorrect for UnionBranch Type", "value", unbranch.getName());
assertEquals("Type is incorrect for UnionBranch Type", "long", unbranch.getIdltype().getLocalPart());
File f = new File("nillable.idl");
assertTrue("nillable.idl should be generated", f.exists());
} finally {
new File("nillable.idl").deleteOnExit();
}
}
use of org.apache.cxf.binding.corba.wsdl.Union in project cxf by apache.
the class WSDLToCorbaHelper method processOMGUnion.
private CorbaType processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
QName name;
QName schematypeName = checkPrefix(complex.getQName());
if (schematypeName == null) {
schematypeName = defaultName;
name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
} else {
name = createQNameCorbaNamespace(schematypeName.getLocalPart());
}
Union corbaUnion = new Union();
corbaUnion.setName(name.getLocalPart());
corbaUnion.setQName(name);
String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
corbaUnion.setRepositoryID(id);
corbaUnion.setType(schematypeName);
XmlSchemaSequence stype = (XmlSchemaSequence) complex.getParticle();
Iterator<XmlSchemaSequenceMember> it = stype.getItems().iterator();
XmlSchemaParticle st1 = (XmlSchemaParticle) it.next();
XmlSchemaParticle st2 = (XmlSchemaParticle) it.next();
final XmlSchemaElement discEl;
final XmlSchemaChoice choice;
if (st1 instanceof XmlSchemaElement) {
discEl = (XmlSchemaElement) st1;
choice = (XmlSchemaChoice) st2;
} else {
discEl = (XmlSchemaElement) st2;
choice = (XmlSchemaChoice) st1;
}
CorbaType disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl.getSchemaType(), null, false);
corbaUnion.setDiscriminator(disctype.getQName());
List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName);
List<String> caselist = new ArrayList<>();
if (disctype instanceof Enum) {
Enum corbaenum = (Enum) disctype;
Iterator<Enumerator> iterator = corbaenum.getEnumerator().iterator();
while (iterator.hasNext()) {
Enumerator enumerator = iterator.next();
caselist.add(enumerator.getValue());
}
} else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
if ("long".equals(disctype.getQName().getLocalPart()) || "short".equals(disctype.getQName().getLocalPart())) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if ("char".equals(disctype.getQName().getLocalPart())) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if ("boolean".equals(disctype.getQName().getLocalPart())) {
if (fields.size() == 2) {
caselist.add("TRUE");
caselist.add("FALSE");
} else if (fields.size() == 1) {
caselist.add("TRUE");
} else {
String msg = "Discriminator Type does not match number of Choices in Union:" + name;
LOG.log(Level.WARNING, msg);
}
}
}
WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
return corbaUnion;
}
use of org.apache.cxf.binding.corba.wsdl.Union in project cxf by apache.
the class WSDLToCorbaHelper method createUnion.
protected Union createUnion(QName name, XmlSchemaChoice choice, QName defaultName, QName schematypeName) throws Exception {
if (recursionMap.get(name) instanceof Union) {
Union corbaUnion = (Union) recursionMap.get(name);
if (corbaUnion != null) {
return corbaUnion;
}
}
Union corbaUnion = new Union();
corbaUnion.setName(name.getLocalPart());
corbaUnion.setQName(name);
corbaUnion.setType(schematypeName);
String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
corbaUnion.setRepositoryID(id);
// Set Integer as Discriminator
corbaUnion.setDiscriminator(CorbaConstants.NT_CORBA_LONG);
// add to the list of possible recursive types
recursionMap.put(name, corbaUnion);
List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName);
// Choose an Integer as a Discriminator
List<String> caselist = new ArrayList<>();
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
corbaUnion = WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
recursionMap.remove(name);
if (!isDuplicate(corbaUnion)) {
typeMappingType.getStructOrExceptionOrUnion().add(corbaUnion);
}
return corbaUnion;
}
Aggregations