Search in sources :

Example 11 with Union

use of org.apache.cxf.binding.corba.wsdl.Union 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 12 with Union

use of org.apache.cxf.binding.corba.wsdl.Union 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 13 with Union

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

the class CorbaUtils method getComplexTypeCode.

public static TypeCode getComplexTypeCode(ORB orb, QName type, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
    TypeCode tc = getAnonTypeCode(orb, type, obj, typeMap, seenTypes);
    if (tc == null) {
        if (obj instanceof Alias) {
            Alias aliasType = (Alias) obj;
            tc = orb.create_alias_tc(aliasType.getRepositoryID(), getTypeCodeName(aliasType.getName()), getTypeCode(orb, aliasType.getBasetype(), typeMap, seenTypes));
        } else if (obj instanceof Array) {
            Array arrayType = (Array) obj;
            tc = orb.create_array_tc((int) arrayType.getBound(), getTypeCode(orb, arrayType.getElemtype(), typeMap, seenTypes));
        } else if (obj instanceof Enum) {
            Enum enumType = (Enum) obj;
            String name = enumType.getName();
            List<Enumerator> enums = enumType.getEnumerator();
            String[] members = new String[enums.size()];
            for (int i = 0; i < members.length; ++i) {
                members[i] = enums.get(i).getValue();
            }
            name = getTypeCodeName(name);
            tc = orb.create_enum_tc(enumType.getRepositoryID(), name, members);
        } else if (obj instanceof Exception) {
            Exception exceptType = (Exception) obj;
            List<MemberType> list = exceptType.getMember();
            StructMember[] members = new StructMember[list.size()];
            for (int i = 0; i < members.length; ++i) {
                MemberType member = list.get(i);
                members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
            }
            String name = getTypeCodeName(exceptType.getName());
            tc = orb.create_exception_tc(exceptType.getRepositoryID(), name, members);
        } else if (obj instanceof Fixed) {
            Fixed fixedType = (Fixed) obj;
            tc = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
        } else if (obj instanceof org.apache.cxf.binding.corba.wsdl.Object) {
            org.apache.cxf.binding.corba.wsdl.Object objType = (org.apache.cxf.binding.corba.wsdl.Object) obj;
            if (objType.getName().equals("CORBA.Object")) {
                tc = orb.create_interface_tc(objType.getRepositoryID(), "Object");
            } else {
                tc = orb.create_interface_tc(objType.getRepositoryID(), getTypeCodeName(objType.getName()));
            }
        } else if (obj instanceof Sequence) {
            Sequence seqType = (Sequence) obj;
            tc = orb.create_sequence_tc((int) seqType.getBound(), getTypeCode(orb, seqType.getElemtype(), typeMap, seenTypes));
        } else if (obj instanceof Struct) {
            Struct structType = (Struct) obj;
            if (seenTypes.contains(new QName(structType.getName()))) {
                tc = orb.create_recursive_tc(structType.getRepositoryID());
            } else {
                seenTypes.push(new QName(structType.getName()));
                List<MemberType> list = structType.getMember();
                StructMember[] members = new StructMember[list.size()];
                for (int i = 0; i < members.length; ++i) {
                    MemberType member = list.get(i);
                    members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
                }
                String name = getTypeCodeName(structType.getName());
                tc = orb.create_struct_tc(structType.getRepositoryID(), name, members);
                seenTypes.pop();
            }
        } else if (obj instanceof Union) {
            tc = getUnionTypeCode(orb, obj, typeMap, seenTypes);
        }
    }
    return tc;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) Union(org.apache.cxf.binding.corba.wsdl.Union) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) NVList(org.omg.CORBA.NVList) List(java.util.List) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) StructMember(org.omg.CORBA.StructMember) Exception(org.apache.cxf.binding.corba.wsdl.Exception) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) Array(org.apache.cxf.binding.corba.wsdl.Array) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Alias(org.apache.cxf.binding.corba.wsdl.Alias)

Example 14 with Union

use of org.apache.cxf.binding.corba.wsdl.Union 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<String, UnionMember>();
    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)

Example 15 with Union

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

the class WSDLToCorbaBindingTypeTest method testAnyType.

@Test
public void testAnyType() throws Exception {
    try {
        String fileName = getClass().getResource("/wsdl/any.wsdl").toString();
        generator.setWsdlFile(fileName);
        generator.addInterfaceName("anyInterface");
        Definition model = generator.generateCORBABinding();
        TypeMappingType mapType = (TypeMappingType) model.getExtensibilityElements().get(0);
        assertEquals(5, mapType.getStructOrExceptionOrUnion().size());
        int strcnt = 0;
        int unioncnt = 0;
        for (CorbaType corbaType : mapType.getStructOrExceptionOrUnion()) {
            if (corbaType instanceof Struct) {
                strcnt++;
            }
            if (corbaType instanceof Union) {
                unioncnt++;
            }
        }
        assertNotNull(mapType);
        assertEquals(3, strcnt);
        assertEquals(2, unioncnt);
        WSDLToIDLAction idlgen = new WSDLToIDLAction();
        idlgen.setBindingName("anyInterfaceCORBABinding");
        idlgen.setOutputFile("any.idl");
        idlgen.generateIDL(model);
        File f = new File("any.idl");
        assertTrue("any.idl should be generated", f.exists());
    } finally {
        new File("any.idl").deleteOnExit();
    }
}
Also used : WSDLToIDLAction(org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Definition(javax.wsdl.Definition) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) File(java.io.File) Union(org.apache.cxf.binding.corba.wsdl.Union) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Test(org.junit.Test)

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