Search in sources :

Example 6 with CaseType

use of org.apache.cxf.binding.corba.wsdl.CaseType 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()) {
        final String discLabel;
        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 7 with CaseType

use of org.apache.cxf.binding.corba.wsdl.CaseType in project cxf by apache.

the class CorbaUtils method getUnionTypeCode.

public static TypeCode getUnionTypeCode(ORB orb, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
    Union unionType = (Union) obj;
    if (seenTypes.contains(new QName(unionType.getName()))) {
        return orb.create_recursive_tc(unionType.getRepositoryID());
    }
    seenTypes.push(new QName(unionType.getName()));
    TypeCode discTC = getTypeCode(orb, unionType.getDiscriminator(), typeMap, seenTypes);
    Map<String, UnionMember> members = new LinkedHashMap<>();
    List<Unionbranch> branches = unionType.getUnionbranch();
    for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
        Unionbranch branch = branchIter.next();
        List<CaseType> cases = branch.getCase();
        for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
            CaseType cs = caseIter.next();
            if (!members.containsKey(cs.getLabel())) {
                UnionMember member = new UnionMember();
                member.name = branch.getName();
                member.type = getTypeCode(orb, branch.getIdltype(), typeMap, seenTypes);
                member.label = orb.create_any();
                // * enum
                switch(discTC.kind().value()) {
                    case TCKind._tk_short:
                        member.label.insert_short(Short.parseShort(cs.getLabel()));
                        break;
                    case TCKind._tk_ushort:
                        member.label.insert_ushort(Short.parseShort(cs.getLabel()));
                        break;
                    case TCKind._tk_long:
                        member.label.insert_long(Integer.parseInt(cs.getLabel()));
                        break;
                    case TCKind._tk_ulong:
                        member.label.insert_ulong(Integer.parseInt(cs.getLabel()));
                        break;
                    case TCKind._tk_longlong:
                        member.label.insert_longlong(Long.parseLong(cs.getLabel()));
                        break;
                    case TCKind._tk_ulonglong:
                        member.label.insert_ulonglong(Long.parseLong(cs.getLabel()));
                        break;
                    case TCKind._tk_char:
                        member.label.insert_char(cs.getLabel().charAt(0));
                        break;
                    case TCKind._tk_boolean:
                        member.label.insert_boolean(Boolean.parseBoolean(cs.getLabel()));
                        break;
                    case TCKind._tk_enum:
                        org.omg.CORBA.portable.OutputStream out = member.label.create_output_stream();
                        Enum enumVal = (Enum) getCorbaType(unionType.getDiscriminator(), typeMap);
                        List<Enumerator> enumerators = enumVal.getEnumerator();
                        for (int i = 0; i < enumerators.size(); ++i) {
                            Enumerator e = enumerators.get(i);
                            if (e.getValue().equals(cs.getLabel())) {
                                out.write_long(i);
                            }
                        }
                        member.label.read_value(out.create_input_stream(), discTC);
                        break;
                    default:
                        throw new CorbaBindingException("Unsupported discriminator type");
                }
                // Some orbs are strict on how the case labels are stored for
                // each member.  So we can't
                // simply insert the labels as strings
                members.put(cs.getLabel(), member);
            }
        }
    }
    seenTypes.pop();
    return orb.create_union_tc(unionType.getRepositoryID(), getTypeCodeName(unionType.getName()), discTC, members.values().toArray(new UnionMember[members.size()]));
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Union(org.apache.cxf.binding.corba.wsdl.Union) UnionMember(org.omg.CORBA.UnionMember) LinkedHashMap(java.util.LinkedHashMap) CaseType(org.apache.cxf.binding.corba.wsdl.CaseType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Aggregations

CaseType (org.apache.cxf.binding.corba.wsdl.CaseType)7 Unionbranch (org.apache.cxf.binding.corba.wsdl.Unionbranch)5 Union (org.apache.cxf.binding.corba.wsdl.Union)3 QName (javax.xml.namespace.QName)2 AST (antlr.collections.AST)1 LinkedHashMap (java.util.LinkedHashMap)1 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)1 CorbaEnumHandler (org.apache.cxf.binding.corba.types.CorbaEnumHandler)1 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)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 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 IdlUnion (org.apache.cxf.tools.corba.common.idltypes.IdlUnion)1 IdlUnionBranch (org.apache.cxf.tools.corba.common.idltypes.IdlUnionBranch)1 TypeCode (org.omg.CORBA.TypeCode)1 UnionMember (org.omg.CORBA.UnionMember)1