Search in sources :

Example 1 with Union

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);
        }
    }
}
Also used : CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) CorbaUnionHandler(org.apache.cxf.binding.corba.types.CorbaUnionHandler) Union(org.apache.cxf.binding.corba.wsdl.Union) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Example 2 with Union

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;
}
Also used : Union(org.apache.cxf.binding.corba.wsdl.Union)

Example 3 with Union

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();
    }
}
Also used : WSDLToIDLAction(org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) Document(org.w3c.dom.Document) File(java.io.File) Union(org.apache.cxf.binding.corba.wsdl.Union) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch) Test(org.junit.Test)

Example 4 with Union

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;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) Union(org.apache.cxf.binding.corba.wsdl.Union) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 5 with Union

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;
}
Also used : MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) ArrayList(java.util.ArrayList) Union(org.apache.cxf.binding.corba.wsdl.Union)

Aggregations

Union (org.apache.cxf.binding.corba.wsdl.Union)16 QName (javax.xml.namespace.QName)8 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)6 Unionbranch (org.apache.cxf.binding.corba.wsdl.Unionbranch)6 Enum (org.apache.cxf.binding.corba.wsdl.Enum)4 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)4 Struct (org.apache.cxf.binding.corba.wsdl.Struct)4 File (java.io.File)3 Definition (javax.wsdl.Definition)3 CaseType (org.apache.cxf.binding.corba.wsdl.CaseType)3 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)3 TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)3 WSDLToIDLAction (org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)2 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)2 Alias (org.apache.cxf.binding.corba.wsdl.Alias)2 Array (org.apache.cxf.binding.corba.wsdl.Array)2 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)2