Search in sources :

Example 6 with Unionbranch

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

Example 7 with Unionbranch

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

Example 8 with Unionbranch

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

Example 9 with Unionbranch

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);
    }
}
Also used : QName(javax.xml.namespace.QName) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Example 10 with Unionbranch

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);
    }
}
Also used : QName(javax.xml.namespace.QName) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Aggregations

Unionbranch (org.apache.cxf.binding.corba.wsdl.Unionbranch)11 Union (org.apache.cxf.binding.corba.wsdl.Union)6 QName (javax.xml.namespace.QName)5 CaseType (org.apache.cxf.binding.corba.wsdl.CaseType)5 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)2 AST (antlr.collections.AST)1 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 Definition (javax.wsdl.Definition)1 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)1 CorbaEnumHandler (org.apache.cxf.binding.corba.types.CorbaEnumHandler)1 CorbaUnionHandler (org.apache.cxf.binding.corba.types.CorbaUnionHandler)1 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)1 Enum (org.apache.cxf.binding.corba.wsdl.Enum)1 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)1 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)1 TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)1 IdlSequence (org.apache.cxf.tools.corba.common.idltypes.IdlSequence)1 IdlString (org.apache.cxf.tools.corba.common.idltypes.IdlString)1 IdlType (org.apache.cxf.tools.corba.common.idltypes.IdlType)1