Search in sources :

Example 56 with TypeCode

use of org.omg.CORBA.TypeCode 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 ("CORBA.Object".equals(objType.getName())) {
                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 57 with TypeCode

use of org.omg.CORBA.TypeCode in project cxf by apache.

the class CorbaServerConduitTest method testBuildRequestResultArgumentReturn.

@Test
public void testBuildRequestResultArgumentReturn() {
    CorbaStreamable[] arguments = new CorbaStreamable[1];
    QName objName = new QName("object");
    QName objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
    TypeCode objTypeCode = orb.get_primitive_tc(TCKind.tk_short);
    CorbaPrimitiveHandler obj = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
    CorbaStreamable arg = new CorbaStreamableImpl(obj, objName);
    arguments[0] = arg;
    arguments[0].setMode(org.omg.CORBA.ARG_OUT.value);
    NVList nvlist = orb.create_list(2);
    Any value = orb.create_any();
    value.insert_Streamable(arguments[0]);
    nvlist.add_value(arguments[0].getName(), value, arguments[0].getMode());
    CorbaServerConduit conduit = setupCorbaServerConduit(false);
    CorbaMessage msg = control.createMock(CorbaMessage.class);
    Exchange exchange = control.createMock(Exchange.class);
    ServerRequest request = control.createMock(ServerRequest.class);
    EasyMock.expect(exchange.getBus()).andReturn(bus);
    EasyMock.expect(msg.getExchange()).andReturn(exchange);
    EasyMock.expect(exchange.get(ServerRequest.class)).andReturn(request);
    EasyMock.expect(exchange.isOneWay()).andReturn(false);
    EasyMock.expect(msg.getExchange()).andReturn(exchange);
    Message message = new MessageImpl();
    CorbaMessage corbaMessage = new CorbaMessage(message);
    corbaMessage.setList(nvlist);
    EasyMock.expect(exchange.getInMessage()).andReturn(corbaMessage);
    EasyMock.expect(msg.getStreamableException()).andReturn(null);
    EasyMock.expect(msg.getStreamableArguments()).andReturn(arguments);
    EasyMock.expect(msg.getStreamableReturn()).andReturn(arg);
    control.replay();
    conduit.buildRequestResult(msg);
    control.verify();
}
Also used : CorbaStreamableImpl(org.apache.cxf.binding.corba.runtime.CorbaStreamableImpl) Message(org.apache.cxf.message.Message) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Any(org.omg.CORBA.Any) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) Exchange(org.apache.cxf.message.Exchange) NVList(org.omg.CORBA.NVList) ServerRequest(org.omg.CORBA.ServerRequest) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 58 with TypeCode

use of org.omg.CORBA.TypeCode in project cxf by apache.

the class CorbaObjectReaderTest method testReadFixed.

@Test
public void testReadFixed() {
    if (System.getProperty("java.vendor").contains("IBM")) {
        // to the stream.
        return;
    }
    OutputStream oStream = orb.create_output_stream();
    // create the following fixed
    // fixed<5,2>
    oStream.write_fixed(new java.math.BigDecimal("12345.67").movePointRight(2));
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    Fixed fixedType = new Fixed();
    fixedType.setDigits(5);
    fixedType.setScale(2);
    // These values don't matter to the outcome of the test but are needed during construction
    QName fixedName = new QName("TestFixed");
    QName fixedIdlType = new QName("corbatm:TestFixed");
    TypeCode fixedTC = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
    CorbaFixedHandler obj = new CorbaFixedHandler(fixedName, fixedIdlType, fixedTC, fixedType);
    reader.readFixed(obj);
    assertEquals(obj.getValue(), new java.math.BigDecimal("12345.67"));
}
Also used : TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) CorbaFixedHandler(org.apache.cxf.binding.corba.types.CorbaFixedHandler) OutputStream(org.omg.CORBA.portable.OutputStream) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed) Test(org.junit.Test)

Example 59 with TypeCode

use of org.omg.CORBA.TypeCode in project cxf by apache.

the class CorbaObjectReaderTest method testReadSequence.

@Test
public void testReadSequence() {
    String[] data = { "one", "one", "two", "three", "five", "eight", "thirteen", "twenty-one" };
    OutputStream oStream = orb.create_output_stream();
    oStream.write_long(data.length);
    for (int i = 0; i < data.length; ++i) {
        oStream.write_string(data[i]);
    }
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    // create an sequence of strings
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    QName seqIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "sequence", CorbaConstants.NP_WSDL_CORBA);
    Sequence seqType = new Sequence();
    seqType.setBound(data.length);
    seqType.setElemtype(stringIdlType);
    // name and respoitory ID of the sequence are not needed for this test
    // build the object holder for a sequence.
    TypeCode seqTC = orb.create_sequence_tc(data.length, orb.get_primitive_tc(TCKind.tk_string));
    CorbaSequenceHandler obj = new CorbaSequenceHandler(new QName("Seq"), seqIdlType, seqTC, seqType);
    for (int i = 0; i < data.length; ++i) {
        CorbaPrimitiveHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), stringIdlType, orb.get_primitive_tc(TCKind.tk_string), null);
        obj.addElement(nestedObj);
    }
    reader.readSequence(obj);
    int length = obj.getElements().size();
    for (int i = 0; i < length; ++i) {
        assertEquals(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue(), data[i]);
    }
}
Also used : CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaSequenceHandler(org.apache.cxf.binding.corba.types.CorbaSequenceHandler) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) Test(org.junit.Test)

Example 60 with TypeCode

use of org.omg.CORBA.TypeCode 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);
    assertEquals(obj.getValue(), 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

TypeCode (org.omg.CORBA.TypeCode)70 QName (javax.xml.namespace.QName)49 Test (org.junit.Test)44 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)18 InputStream (org.omg.CORBA.portable.InputStream)15 OutputStream (org.omg.CORBA.portable.OutputStream)14 StructMember (org.omg.CORBA.StructMember)9 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)6 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)6 Any (org.omg.CORBA.Any)6 NVList (org.omg.CORBA.NVList)6 CorbaStreamable (org.apache.cxf.binding.corba.CorbaStreamable)5 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)4 Array (org.apache.cxf.binding.corba.wsdl.Array)4 Enum (org.apache.cxf.binding.corba.wsdl.Enum)4 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)4 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)4 Struct (org.apache.cxf.binding.corba.wsdl.Struct)4 Exchange (org.apache.cxf.message.Exchange)4 IOException (java.io.IOException)3