Search in sources :

Example 11 with Sequence

use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.

the class CorbaHandlerUtils method initializeSequenceHandler.

public static void initializeSequenceHandler(ORB orb, CorbaObjectHandler obj, CorbaTypeMap typeMap, ServiceInfo serviceInfo, Map<QName, CorbaObjectHandler> seenTypes) {
    QName seqElementType = null;
    long seqBound = 0;
    CorbaType baseType = obj.getType();
    QName elementName;
    if (baseType instanceof Sequence) {
        Sequence seqType = (Sequence) baseType;
        seqElementType = seqType.getElemtype();
        seqBound = seqType.getBound();
        elementName = seqType.getElemname();
    } else {
        Anonsequence seqType = (Anonsequence) baseType;
        seqElementType = seqType.getElemtype();
        seqBound = seqType.getBound();
        elementName = seqType.getElemname();
    }
    if (seqBound == 0) {
        // This is an unbounded sequence.  Store a 'template' object that we can use to create
        // new objects as needed
        CorbaObjectHandler elementObj = null;
        // Check for a recursive type
        if (seenTypes.get(seqElementType) != null) {
            elementObj = seenTypes.get(seqElementType);
            elementObj.setRecursive(true);
            ((CorbaSequenceHandler) obj).hasRecursiveTypeElement(true);
        } else {
            elementObj = initializeObjectHandler(orb, elementName, seqElementType, typeMap, serviceInfo, seenTypes);
        }
        ((CorbaSequenceHandler) obj).setTemplateElement(elementObj);
    }
    for (int i = 0; i < seqBound; ++i) {
        CorbaObjectHandler elementObj = null;
        // Check for a recursive type
        if (seenTypes.get(seqElementType) != null) {
            // Even though this is bounded, if we have a recursive type, we'll still use the
            // template object so that we don't overwrite the value of the element.
            elementObj = seenTypes.get(seqElementType);
            elementObj.setRecursive(true);
            ((CorbaSequenceHandler) obj).hasRecursiveTypeElement(true);
            ((CorbaSequenceHandler) obj).setTemplateElement(elementObj);
        } else {
            elementObj = initializeObjectHandler(orb, elementName, seqElementType, typeMap, serviceInfo, seenTypes);
            ((CorbaSequenceHandler) obj).addElement(elementObj);
        }
    }
}
Also used : CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) QName(javax.xml.namespace.QName) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence)

Example 12 with Sequence

use of org.apache.cxf.binding.corba.wsdl.Sequence 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 (objType.getName().equals("CORBA.Object")) {
                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 13 with Sequence

use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.

the class WSDLToCorbaBindingTest method assertMixedArraysMappingEasyTypes.

/**
 * @param typeMap
 */
private void assertMixedArraysMappingEasyTypes(CorbaTypeMap typeMap) {
    Sequence p1 = (Sequence) typeMap.getType("p1-unwrapped-sequenceArray");
    assertEquals(new QName("", "p1-unwrapped-sequence"), p1.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p1.getElemtype());
    Sequence p1q = (Sequence) typeMap.getType("p1-unwrapped-sequence-qArray");
    assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "p1-unwrapped-sequence-q"), p1q.getElemname());
    assertFalse(p1.isWrapped());
    Sequence p2 = (Sequence) typeMap.getType("UnboundedArray");
    assertEquals(new QName("", "item"), p2.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p2.getElemtype());
    assertTrue(p2.isWrapped());
    Array p3 = (Array) typeMap.getType("p3-unwrapped-arrayArray");
    assertEquals(new QName("", "p3-unwrapped-array"), p3.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p3.getElemtype());
    Array p3q = (Array) typeMap.getType("p3-unwrapped-array-qArray");
    assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "p3-unwrapped-array-q"), p3q.getElemname());
    assertFalse(p3.isWrapped());
    Array p4 = (Array) typeMap.getType("FixedArray");
    assertEquals(new QName("", "item"), p4.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p4.getElemtype());
    assertTrue(p4.isWrapped());
    Sequence p5 = (Sequence) typeMap.getType("p5-anonymous-unwrapped-sequenceArray");
    assertEquals(new QName("", "p5-anonymous-unwrapped-sequence"), p5.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p5.getElemtype());
    Sequence p5q = (Sequence) typeMap.getType("p5-anonymous-unwrapped-sequence-qArray");
    assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "p5-anonymous-unwrapped-sequence-q"), p5q.getElemname());
    assertFalse(p5.isWrapped());
    Anonsequence p6 = (Anonsequence) typeMap.getType("MixedArrayType.p6-anonymous-wrapped-sequenceType");
    assertEquals(new QName("", "item"), p6.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p6.getElemtype());
    assertFalse(p6.isQualified());
    assertTrue(p6.isWrapped());
    Anonsequence p6q = (Anonsequence) typeMap.getType("MixedArrayType.p6-anonymous-wrapped-sequence-qType");
    assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "item"), p6q.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p6q.getElemtype());
    assertTrue(p6q.isQualified());
    assertTrue(p6q.isWrapped());
    Array p7 = (Array) typeMap.getType("p7-anonymous-unwrapped-arrayArray");
    assertEquals(new QName("", "p7-anonymous-unwrapped-array"), p7.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p7.getElemtype());
    assertFalse(p7.isQualified());
    assertFalse(p7.isWrapped());
    Array p7q = (Array) typeMap.getType("p7-anonymous-unwrapped-array-qArray");
    assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "p7-anonymous-unwrapped-array-q"), p7q.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p7q.getElemtype());
    assertTrue(p7q.isQualified());
    assertFalse(p7q.isWrapped());
    Anonarray p8 = (Anonarray) typeMap.getType("MixedArrayType.p8-anonymous-wrapped-arrayType");
    assertEquals(new QName("", "item"), p8.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p8.getElemtype());
    assertFalse(p8.isQualified());
    assertTrue(p8.isWrapped());
    Anonarray p8q = (Anonarray) typeMap.getType("MixedArrayType.p8-anonymous-wrapped-array-qType");
    assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "item"), p8q.getElemname());
    assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p8q.getElemtype());
    assertTrue(p8q.isQualified());
    assertTrue(p8q.isWrapped());
}
Also used : Array(org.apache.cxf.binding.corba.wsdl.Array) QName(javax.xml.namespace.QName) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) Anonarray(org.apache.cxf.binding.corba.wsdl.Anonarray) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence)

Example 14 with Sequence

use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.

the class WSDLToCorbaBindingTest method checkSequenceType.

private void checkSequenceType(BindingOperation bindingOperation, Map<String, CorbaType> mapType) {
    for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
        if (extElement.getElementType().getLocalPart().equals("operation")) {
            OperationType corbaOpType = (OperationType) extElement;
            assertEquals(corbaOpType.getName(), "op_h");
            assertEquals(3, corbaOpType.getParam().size());
            assertEquals("Y.H", corbaOpType.getParam().get(0).getIdltype().getLocalPart());
            assertEquals("Y.H", corbaOpType.getReturn().getIdltype().getLocalPart());
            Sequence seq = (Sequence) mapType.get(corbaOpType.getReturn().getIdltype().getLocalPart());
            assertEquals("ElementType is incorrect for Sequence Type", "fixed_1", seq.getElemtype().getLocalPart());
        }
    }
}
Also used : OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 15 with Sequence

use of org.apache.cxf.binding.corba.wsdl.Sequence 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

Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)15 QName (javax.xml.namespace.QName)12 Anonsequence (org.apache.cxf.binding.corba.wsdl.Anonsequence)7 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)6 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)5 Alias (org.apache.cxf.binding.corba.wsdl.Alias)4 TypeCode (org.omg.CORBA.TypeCode)4 Array (org.apache.cxf.binding.corba.wsdl.Array)3 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)3 Struct (org.apache.cxf.binding.corba.wsdl.Struct)3 Test (org.junit.Test)3 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)2 CorbaSequenceHandler (org.apache.cxf.binding.corba.types.CorbaSequenceHandler)2 Anonarray (org.apache.cxf.binding.corba.wsdl.Anonarray)2 Enum (org.apache.cxf.binding.corba.wsdl.Enum)2 Union (org.apache.cxf.binding.corba.wsdl.Union)2 List (java.util.List)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)1 Anonfixed (org.apache.cxf.binding.corba.wsdl.Anonfixed)1