Search in sources :

Example 1 with CorbaSequenceHandler

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

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

the class CorbaObjectReader method readSequence.

// CHECKSTYLE:ON
public void readSequence(CorbaObjectHandler obj) throws CorbaBindingException {
    if (obj instanceof CorbaOctetSequenceHandler) {
        int length = stream.read_ulong();
        byte[] value = new byte[length];
        stream.read_octet_array(value, 0, length);
        ((CorbaOctetSequenceHandler) obj).setValue(value);
    } else {
        CorbaSequenceHandler sequenceObj = (CorbaSequenceHandler) obj;
        List<CorbaObjectHandler> seqElements = sequenceObj.getElements();
        int length = stream.read_ulong();
        List<CorbaObjectHandler> elements = new ArrayList<>(length);
        // object that is in the input stream.
        if (sequenceObj.getTemplateElement() != null) {
            sequenceObj.clear();
            CorbaObjectHandler template = sequenceObj.getTemplateElement();
            for (int i = 0; i < length; ++i) {
                CorbaObjectHandler seqElement;
                if (i < seqElements.size()) {
                    seqElement = seqElements.get(i);
                } else {
                    seqElement = initializeCorbaObjectHandler(template);
                }
                read(seqElement);
                elements.add(seqElement);
            }
            sequenceObj.setElements(elements);
        } else {
            // We have a bounded sequence and the object should already be pre-built
            for (int i = 0; i < length; ++i) {
                read(seqElements.get(i));
            }
            sequenceObj.setElements(seqElements.subList(0, length));
        }
    }
}
Also used : CorbaOctetSequenceHandler(org.apache.cxf.binding.corba.types.CorbaOctetSequenceHandler) CorbaSequenceHandler(org.apache.cxf.binding.corba.types.CorbaSequenceHandler) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) ArrayList(java.util.ArrayList)

Example 3 with CorbaSequenceHandler

use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler 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)

Example 4 with CorbaSequenceHandler

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

the class CorbaObjectWriter method writeSequence.

public void writeSequence(CorbaObjectHandler obj) throws CorbaBindingException {
    if (obj instanceof CorbaOctetSequenceHandler) {
        byte[] value = ((CorbaOctetSequenceHandler) obj).getValue();
        stream.write_ulong(value.length);
        stream.write_octet_array(value, 0, value.length);
    } else {
        CorbaSequenceHandler seqHandler = (CorbaSequenceHandler) obj;
        List<CorbaObjectHandler> seqElements = seqHandler.getElements();
        int length = seqElements.size();
        stream.write_ulong(length);
        for (int i = 0; i < length; ++i) {
            this.write(seqElements.get(i));
        }
    }
}
Also used : CorbaOctetSequenceHandler(org.apache.cxf.binding.corba.types.CorbaOctetSequenceHandler) CorbaSequenceHandler(org.apache.cxf.binding.corba.types.CorbaSequenceHandler) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler)

Example 5 with CorbaSequenceHandler

use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler 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) {
        assertTrue(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue().equals(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)

Aggregations

CorbaSequenceHandler (org.apache.cxf.binding.corba.types.CorbaSequenceHandler)5 QName (javax.xml.namespace.QName)3 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)3 ArrayList (java.util.ArrayList)2 CorbaOctetSequenceHandler (org.apache.cxf.binding.corba.types.CorbaOctetSequenceHandler)2 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)2 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)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 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 CorbaStructHandler (org.apache.cxf.binding.corba.types.CorbaStructHandler)1 CorbaUnionHandler (org.apache.cxf.binding.corba.types.CorbaUnionHandler)1