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 processComplexContentStructChoice.
protected MemberType processComplexContentStructChoice(XmlSchemaChoice choice, QName schematypeName, QName defaultName) throws Exception {
QName choicename = createQNameTargetNamespace(schematypeName.getLocalPart() + "ChoiceType");
Union choiceunion = createUnion(choicename, choice, defaultName, schematypeName);
MemberType choicemem = new MemberType();
if (choiceunion != null) {
String repoId = REPO_STRING + choiceunion.getQName().getLocalPart().replace('.', '/') + IDL_VERSION;
choiceunion.setRepositoryID(repoId);
choicemem.setName(choiceunion.getQName().getLocalPart() + "_f");
choicemem.setIdltype(createQNameCorbaNamespace(choiceunion.getQName().getLocalPart()));
if (!isDuplicate(choiceunion)) {
typeMappingType.getStructOrExceptionOrUnion().add(choiceunion);
}
}
return choicemem;
}
use of org.apache.cxf.binding.corba.wsdl.Union 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.Union in project cxf by apache.
the class WSDLToCorbaHelper method processChoice.
private CorbaType processChoice(XmlSchemaChoice choice, QName defaultName, QName schemaTypeName) throws Exception {
QName choicename = null;
if (schemaTypeName == null) {
choicename = createQNameCorbaNamespace(defaultName.getLocalPart());
} else {
choicename = createQNameCorbaNamespace(schemaTypeName.getLocalPart());
}
choicename = checkPrefix(choicename);
CorbaType corbatype = createUnion(choicename, choice, defaultName, schemaTypeName);
String repoId = REPO_STRING + corbatype.getQName().getLocalPart().replace('.', '/') + IDL_VERSION;
((Union) corbatype).setRepositoryID(repoId);
if (!(choice.getMaxOccurs() == 1) || !(choice.getMinOccurs() == 1)) {
QName name = createQNameTargetNamespace(corbatype.getQName().getLocalPart() + "Array");
CorbaType arrayType = createArray(name, corbatype.getQName(), corbatype.getQName(), choice.getMaxOccurs(), choice.getMinOccurs(), false);
if (arrayType != null && !isDuplicate(arrayType)) {
typeMappingType.getStructOrExceptionOrUnion().add(arrayType);
}
}
return corbatype;
}
use of org.apache.cxf.binding.corba.wsdl.Union in project cxf by apache.
the class WSDLToIDLAction method createType.
protected IdlType createType(QName idlType, String[] name, CorbaType corbaType) throws Exception {
if (idlType.getLocalPart().equals("CORBA.Object")) {
return IdlInterface.create(null, "Object");
}
CorbaType corbaTypeImpl = corbaType;
if (corbaTypeImpl == null) {
corbaTypeImpl = getCorbaType(idlType);
}
if (corbaTypeImpl == null) {
String msgStr = "Type " + idlType.getLocalPart() + " not found.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
IdlScopeBase scope = root;
StringBuilder dotScopedName = new StringBuilder("");
for (int i = 0; i < name.length - 1; ++i) {
dotScopedName.append(name[i]);
// name array.
if ("CORBA".equals(dotScopedName.toString()) && name.length == 2 && i == 0 && name[1].equals("Object")) {
break;
}
IdlDefn idlDef = scope.lookup(name[i]);
if (idlDef == null) {
// Before creating module, check to see if a Corba type
// represent this name aleady exists.
// For example if type is a.b.c and we are about to create
// module b, look to see if a.b
// is an interface that needs to be processed
QName qname = new QName(corbaTypeImpl.getType().getNamespaceURI(), dotScopedName.toString());
// Check to see if CORBAType exists. If so, create type for it
// otherwise
// create module for this scope
CorbaType possibleCorbaType = getCorbaType(qname);
if (possibleCorbaType != null) {
idlDef = findType(qname);
}
if (idlDef == null) {
idlDef = IdlModule.create(scope, name[i]);
scope.addToScope(idlDef);
}
}
dotScopedName.append(".");
scope = (IdlScopeBase) idlDef;
}
IdlType result = null;
String local = name[name.length - 1];
if (corbaTypeImpl instanceof Enum) {
result = createEnum((Enum) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Sequence) {
result = createSequence((Sequence) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Anonsequence) {
result = createAnonSequence((Anonsequence) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Exception) {
result = createIdlException((org.apache.cxf.binding.corba.wsdl.Exception) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Struct) {
result = createStruct((Struct) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Union) {
result = createUnion((Union) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Alias) {
result = createTypedef((Alias) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Array) {
result = createArray((Array) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Anonarray) {
result = createAnonArray((Anonarray) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Fixed) {
result = createFixed((Fixed) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Anonfixed) {
result = createAnonFixed((Anonfixed) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Const) {
result = createConst((Const) corbaTypeImpl, scope, local);
} else {
result = checkAnon(corbaTypeImpl, scope, local);
}
if (result == null && corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Object) {
result = createInterface((org.apache.cxf.binding.corba.wsdl.Object) corbaTypeImpl, scope, local);
}
return result;
}
Aggregations