Search in sources :

Example 11 with TypeCode

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

the class CorbaObjectReaderTest method testReadStruct.

@Test
public void testReadStruct() {
    OutputStream oStream = orb.create_output_stream();
    // create the following struct
    // struct TestStruct {
    // long member1;
    // string member2;
    // boolean member3;
    // }
    int member1 = 12345;
    String member2 = "54321";
    boolean member3 = true;
    oStream.write_long(member1);
    oStream.write_string(member2);
    oStream.write_boolean(member3);
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    QName structIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "struct", CorbaConstants.NP_WSDL_CORBA);
    QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    QName boolIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "boolean", CorbaConstants.NP_WSDL_CORBA);
    Struct structType = new Struct();
    structType.setName("TestStruct");
    MemberType m1 = new MemberType();
    m1.setIdltype(longIdlType);
    m1.setName("member1");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("member2");
    MemberType m3 = new MemberType();
    m3.setIdltype(boolIdlType);
    m3.setName("member3");
    structType.getMember().add(m1);
    structType.getMember().add(m2);
    structType.getMember().add(m3);
    // build the object holder
    StructMember[] structMembers = new StructMember[3];
    structMembers[0] = new StructMember("member1", orb.get_primitive_tc(TCKind.tk_long), null);
    structMembers[1] = new StructMember("member2", orb.get_primitive_tc(TCKind.tk_string), null);
    structMembers[2] = new StructMember("member3", orb.get_primitive_tc(TCKind.tk_boolean), null);
    TypeCode structTC = orb.create_struct_tc("IDL:org.apache.cxf.TestStruct/1.0", "TestStruct", structMembers);
    CorbaStructHandler obj = new CorbaStructHandler(new QName("TestStruct"), structIdlType, structTC, structType);
    obj.addMember(new CorbaPrimitiveHandler(new QName("member1"), longIdlType, structMembers[0].type, null));
    obj.addMember(new CorbaPrimitiveHandler(new QName("member2"), stringIdlType, structMembers[1].type, null));
    obj.addMember(new CorbaPrimitiveHandler(new QName("member3"), boolIdlType, structMembers[2].type, null));
    reader.readStruct(obj);
    List<CorbaObjectHandler> nestedObjs = obj.getMembers();
    assertTrue(new Integer(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()).intValue() == member1);
    assertTrue(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue().equals(member2));
    assertTrue(Boolean.valueOf(((CorbaPrimitiveHandler) nestedObjs.get(2)).getDataFromValue()).booleanValue() == member3);
}
Also used : TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaStructHandler(org.apache.cxf.binding.corba.types.CorbaStructHandler) StructMember(org.omg.CORBA.StructMember) Struct(org.apache.cxf.binding.corba.wsdl.Struct) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) BigInteger(java.math.BigInteger) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Test(org.junit.Test)

Example 12 with TypeCode

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

the class CorbaObjectWriterTest method testWriteArray.

@Test
public void testWriteArray() {
    int[] data = { 1, 1, 2, 3, 5, 8, 13, 21 };
    // create an array of longs
    QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
    QName arrayIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "array", CorbaConstants.NP_WSDL_CORBA);
    Array arrayType = new Array();
    arrayType.setBound(data.length);
    arrayType.setElemtype(longIdlType);
    // name and respoitory ID of the array are not needed for this test
    // build the object holder for an array.
    TypeCode arrayTC = orb.create_array_tc(data.length, orb.get_primitive_tc(TCKind.tk_long));
    CorbaArrayHandler obj = new CorbaArrayHandler(new QName("Array"), arrayIdlType, arrayTC, arrayType);
    for (int i = 0; i < data.length; ++i) {
        CorbaPrimitiveHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), longIdlType, orb.get_primitive_tc(TCKind.tk_long), null);
        nestedObj.setValueFromData(Integer.toString(data[i]));
        obj.addElement(nestedObj);
    }
    OutputStream oStream = orb.create_output_stream();
    CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
    writer.writeArray(obj);
    InputStream iStream = oStream.create_input_stream();
    for (int i = 0; i < data.length; ++i) {
        int val = iStream.read_long();
        assertTrue(val == data[i]);
    }
}
Also used : Array(org.apache.cxf.binding.corba.wsdl.Array) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaArrayHandler(org.apache.cxf.binding.corba.types.CorbaArrayHandler) Test(org.junit.Test)

Example 13 with TypeCode

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

the class CorbaObjectWriterTest method testWriteSequence.

@Test
public void testWriteSequence() {
    String[] data = { "one", "one", "two", "three", "five", "eight", "thirteen", "twenty-one" };
    // 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);
        nestedObj.setValueFromData(data[i]);
        obj.addElement(nestedObj);
    }
    OutputStream oStream = orb.create_output_stream();
    CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
    writer.writeSequence(obj);
    InputStream iStream = oStream.create_input_stream();
    int length = iStream.read_long();
    for (int i = 0; i < length; ++i) {
        String val = iStream.read_string();
        assertTrue(val.equals(data[i]));
    }
}
Also used : CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) InputStream(org.omg.CORBA.portable.InputStream) CorbaSequenceHandler(org.apache.cxf.binding.corba.types.CorbaSequenceHandler) OutputStream(org.omg.CORBA.portable.OutputStream) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) Test(org.junit.Test)

Example 14 with TypeCode

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

the class CorbaObjectWriterTest method testWriteObject.

@Test
public void testWriteObject() throws IOException {
    URL refUrl = getClass().getResource("/references/account.ref");
    String oRef = IOUtils.toString(refUrl.openStream()).trim();
    org.omg.CORBA.Object objRef = orb.string_to_object(oRef);
    assertNotNull(objRef);
    // create a test object
    org.apache.cxf.binding.corba.wsdl.Object objectType = new org.apache.cxf.binding.corba.wsdl.Object();
    objectType.setRepositoryID("IDL:Account:1.0");
    objectType.setBinding(new QName("AccountCORBABinding"));
    QName objectName = new QName("TestObject");
    QName objectIdlType = new QName("corbaatm:TestObject");
    TypeCode objectTC = orb.create_interface_tc("IDL:Account:1.0", "TestObject");
    CorbaObjectReferenceHandler obj = new CorbaObjectReferenceHandler(objectName, objectIdlType, objectTC, objectType);
    obj.setReference(objRef);
    OutputStream oStream = orb.create_output_stream();
    CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
    writer.writeObjectReference(obj);
    InputStream iStream = oStream.create_input_stream();
    org.omg.CORBA.Object resultObj = iStream.read_Object();
    assertTrue(resultObj._is_equivalent(obj.getReference()));
}
Also used : TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) URL(java.net.URL) CorbaObjectReferenceHandler(org.apache.cxf.binding.corba.types.CorbaObjectReferenceHandler) Test(org.junit.Test)

Example 15 with TypeCode

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

the class CorbaObjectWriterTest method testWriteStruct.

@Test
public void testWriteStruct() {
    // create the following struct
    // struct TestStruct {
    // long member1;
    // string member2;
    // boolean member3;
    // }
    int member1 = 12345;
    String member2 = "54321";
    boolean member3 = true;
    QName structIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "struct", CorbaConstants.NP_WSDL_CORBA);
    QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    QName boolIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "boolean", CorbaConstants.NP_WSDL_CORBA);
    Struct structType = new Struct();
    structType.setName("TestStruct");
    MemberType m1 = new MemberType();
    m1.setIdltype(longIdlType);
    m1.setName("member1");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("member2");
    MemberType m3 = new MemberType();
    m3.setIdltype(boolIdlType);
    m3.setName("member3");
    structType.getMember().add(m1);
    structType.getMember().add(m2);
    structType.getMember().add(m3);
    // build the object holder
    StructMember[] structMembers = new StructMember[3];
    structMembers[0] = new StructMember("member1", orb.get_primitive_tc(TCKind.tk_long), null);
    structMembers[1] = new StructMember("member2", orb.get_primitive_tc(TCKind.tk_string), null);
    structMembers[2] = new StructMember("member3", orb.get_primitive_tc(TCKind.tk_boolean), null);
    TypeCode structTC = orb.create_struct_tc("IDL:org.apache.cxf.TestStruct/1.0", "TestStruct", structMembers);
    CorbaStructHandler obj = new CorbaStructHandler(new QName("TestStruct"), structIdlType, structTC, structType);
    CorbaPrimitiveHandler memberObj1 = new CorbaPrimitiveHandler(new QName("member1"), longIdlType, structMembers[0].type, null);
    CorbaPrimitiveHandler memberObj2 = new CorbaPrimitiveHandler(new QName("member2"), stringIdlType, structMembers[1].type, null);
    CorbaPrimitiveHandler memberObj3 = new CorbaPrimitiveHandler(new QName("member3"), boolIdlType, structMembers[2].type, null);
    memberObj1.setValueFromData(Integer.toString(member1));
    memberObj2.setValueFromData(member2);
    memberObj3.setValueFromData(Boolean.toString(member3));
    obj.addMember(memberObj1);
    obj.addMember(memberObj2);
    obj.addMember(memberObj3);
    OutputStream oStream = orb.create_output_stream();
    CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
    writer.writeStruct(obj);
    InputStream iStream = oStream.create_input_stream();
    int readMember1 = iStream.read_long();
    assertTrue(readMember1 == member1);
    String readMember2 = iStream.read_string();
    assertTrue(readMember2.equals(member2));
    boolean readMember3 = iStream.read_boolean();
    assertTrue(readMember3 == member3);
}
Also used : TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) InputStream(org.omg.CORBA.portable.InputStream) CorbaStructHandler(org.apache.cxf.binding.corba.types.CorbaStructHandler) OutputStream(org.omg.CORBA.portable.OutputStream) StructMember(org.omg.CORBA.StructMember) Struct(org.apache.cxf.binding.corba.wsdl.Struct) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Test(org.junit.Test)

Aggregations

TypeCode (org.omg.CORBA.TypeCode)69 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 IOException (java.io.IOException)3 Alias (org.apache.cxf.binding.corba.wsdl.Alias)3