Search in sources :

Example 1 with CorbaStructHandler

use of org.apache.cxf.binding.corba.types.CorbaStructHandler in project cxf by apache.

the class CorbaObjectReader method initializeCorbaObjectHandler.

private CorbaObjectHandler initializeCorbaObjectHandler(CorbaObjectHandler template) {
    Constructor<?> templateConstructor = template.getClass().getDeclaredConstructors()[0];
    Object[] params = new Object[4];
    // of a sequence and needs to have the name "item" in order
    if (template.isRecursive()) {
        // Revisit: Is this always the case?
        params[0] = new QName("item");
    } else {
        params[0] = template.getName();
    }
    params[1] = template.getIdlType();
    params[2] = template.getTypeCode();
    params[3] = template.getType();
    final CorbaObjectHandler handler;
    try {
        handler = (CorbaObjectHandler) templateConstructor.newInstance(params);
        // the template object.
        if (template instanceof CorbaAnyHandler) {
            ((CorbaAnyHandler) handler).setTypeMap(((CorbaAnyHandler) template).getTypeMap());
        }
    } catch (java.lang.Exception ex) {
        throw new CorbaBindingException("Unable to instantiate sequence element", ex);
    }
    if (template instanceof CorbaSequenceHandler) {
        CorbaSequenceHandler templateSeq = (CorbaSequenceHandler) template;
        ((CorbaSequenceHandler) handler).setTemplateElement(templateSeq.getTemplateElement());
    } else if (template instanceof CorbaStructHandler) {
        CorbaStructHandler templateStruct = (CorbaStructHandler) template;
        CorbaStructHandler struct = (CorbaStructHandler) handler;
        struct.setRecursive(template.isRecursive());
        List<CorbaObjectHandler> members = templateStruct.getMembers();
        for (int i = 0; i < members.size(); i++) {
            CorbaObjectHandler member = initializeCorbaObjectHandler(members.get(i));
            struct.addMember(member);
        }
    } else if (template instanceof CorbaArrayHandler) {
        CorbaArrayHandler templateArray = (CorbaArrayHandler) template;
        CorbaArrayHandler array = (CorbaArrayHandler) handler;
        List<CorbaObjectHandler> elements = templateArray.getElements();
        for (int i = 0; i < elements.size(); i++) {
            CorbaObjectHandler element = initializeCorbaObjectHandler(elements.get(i));
            array.addElement(element);
        }
    } else if (template instanceof CorbaUnionHandler) {
        CorbaUnionHandler templateUnion = (CorbaUnionHandler) template;
        CorbaUnionHandler union = (CorbaUnionHandler) handler;
        union.setRecursive(template.isRecursive());
        union.setDiscriminator(initializeCorbaObjectHandler(templateUnion.getDiscriminator()));
        List<CorbaObjectHandler> cases = templateUnion.getCases();
        for (int i = 0; i < cases.size(); i++) {
            union.addCase(initializeCorbaObjectHandler(cases.get(i)));
        }
    }
    return handler;
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) QName(javax.xml.namespace.QName) CorbaSequenceHandler(org.apache.cxf.binding.corba.types.CorbaSequenceHandler) CorbaStructHandler(org.apache.cxf.binding.corba.types.CorbaStructHandler) CorbaUnionHandler(org.apache.cxf.binding.corba.types.CorbaUnionHandler) CorbaArrayHandler(org.apache.cxf.binding.corba.types.CorbaArrayHandler) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) ArrayList(java.util.ArrayList) List(java.util.List) CorbaAnyHandler(org.apache.cxf.binding.corba.types.CorbaAnyHandler)

Example 2 with CorbaStructHandler

use of org.apache.cxf.binding.corba.types.CorbaStructHandler 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(Integer.parseInt(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()) == member1);
    assertEquals(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue(), member2);
    assertTrue(Boolean.parseBoolean(((CorbaPrimitiveHandler) nestedObjs.get(2)).getDataFromValue()) == 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) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Test(org.junit.Test)

Example 3 with CorbaStructHandler

use of org.apache.cxf.binding.corba.types.CorbaStructHandler 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();
    assertEquals(readMember2, 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

QName (javax.xml.namespace.QName)3 CorbaStructHandler (org.apache.cxf.binding.corba.types.CorbaStructHandler)3 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)2 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)2 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)2 Struct (org.apache.cxf.binding.corba.wsdl.Struct)2 Test (org.junit.Test)2 StructMember (org.omg.CORBA.StructMember)2 TypeCode (org.omg.CORBA.TypeCode)2 InputStream (org.omg.CORBA.portable.InputStream)2 OutputStream (org.omg.CORBA.portable.OutputStream)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)1 CorbaAnyHandler (org.apache.cxf.binding.corba.types.CorbaAnyHandler)1 CorbaArrayHandler (org.apache.cxf.binding.corba.types.CorbaArrayHandler)1 CorbaSequenceHandler (org.apache.cxf.binding.corba.types.CorbaSequenceHandler)1 CorbaUnionHandler (org.apache.cxf.binding.corba.types.CorbaUnionHandler)1