Search in sources :

Example 1 with CorbaArrayHandler

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

the class CorbaObjectReaderTest method testReadArray.

// need to add tests for arrays, sequences, struct, exceptions
@Test
public void testReadArray() {
    int[] data = { 1, 1, 2, 3, 5, 8, 13, 21 };
    OutputStream oStream = orb.create_output_stream();
    oStream.write_long_array(data, 0, data.length);
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    // 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) {
        CorbaObjectHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), longIdlType, orb.get_primitive_tc(TCKind.tk_long), null);
        obj.addElement(nestedObj);
    }
    reader.readArray(obj);
    int length = obj.getElements().size();
    for (int i = 0; i < length; ++i) {
        assertTrue(new Long(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue()).intValue() == 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) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) CorbaArrayHandler(org.apache.cxf.binding.corba.types.CorbaArrayHandler) Test(org.junit.Test)

Example 2 with CorbaArrayHandler

use of org.apache.cxf.binding.corba.types.CorbaArrayHandler 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 3 with CorbaArrayHandler

use of org.apache.cxf.binding.corba.types.CorbaArrayHandler 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();
    CorbaObjectHandler handler = null;
    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)

Aggregations

QName (javax.xml.namespace.QName)3 CorbaArrayHandler (org.apache.cxf.binding.corba.types.CorbaArrayHandler)3 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)2 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)2 Array (org.apache.cxf.binding.corba.wsdl.Array)2 Test (org.junit.Test)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 CorbaSequenceHandler (org.apache.cxf.binding.corba.types.CorbaSequenceHandler)1 CorbaStructHandler (org.apache.cxf.binding.corba.types.CorbaStructHandler)1 CorbaUnionHandler (org.apache.cxf.binding.corba.types.CorbaUnionHandler)1