Search in sources :

Example 11 with Enum

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

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

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

the class CorbaObjectReaderTest method testReadEnum.

@Test
public void testReadEnum() {
    OutputStream oStream = orb.create_output_stream();
    // create the following enum
    // enum { RED, GREEN, BLUE };
    oStream.write_long(1);
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    String[] enums = { "RED", "GREEN", "BLUE" };
    Enum enumType = new Enum();
    Enumerator enumRed = new Enumerator();
    enumRed.setValue(enums[0]);
    Enumerator enumGreen = new Enumerator();
    enumGreen.setValue(enums[1]);
    Enumerator enumBlue = new Enumerator();
    enumBlue.setValue(enums[2]);
    enumType.getEnumerator().add(enumRed);
    enumType.getEnumerator().add(enumGreen);
    enumType.getEnumerator().add(enumBlue);
    // These values don't matter to the outcome of the test but are needed during construction
    QName enumName = new QName("TestEnum");
    QName enumIdlType = new QName("corbatm:TestEnum");
    TypeCode enumTC = orb.create_enum_tc("IDL:TestEnum:1.0", enumName.getLocalPart(), enums);
    CorbaEnumHandler obj = new CorbaEnumHandler(enumName, enumIdlType, enumTC, enumType);
    reader.readEnum(obj);
    assertTrue(obj.getValue().equals(enums[1]));
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaEnumHandler(org.apache.cxf.binding.corba.types.CorbaEnumHandler) Test(org.junit.Test)

Aggregations

Enum (org.apache.cxf.binding.corba.wsdl.Enum)13 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)12 QName (javax.xml.namespace.QName)7 Union (org.apache.cxf.binding.corba.wsdl.Union)4 TypeCode (org.omg.CORBA.TypeCode)4 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)3 CorbaEnumHandler (org.apache.cxf.binding.corba.types.CorbaEnumHandler)2 Alias (org.apache.cxf.binding.corba.wsdl.Alias)2 Array (org.apache.cxf.binding.corba.wsdl.Array)2 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)2 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)2 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)2 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)2 Struct (org.apache.cxf.binding.corba.wsdl.Struct)2 XmlSchemaEnumerationFacet (org.apache.ws.commons.schema.XmlSchemaEnumerationFacet)2 AST (antlr.collections.AST)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Anonarray (org.apache.cxf.binding.corba.wsdl.Anonarray)1