Search in sources :

Example 11 with Struct

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

the class WSDLToCorbaHelper method processStruct.

private CorbaType processStruct(XmlSchemaComplexType complex, QName defaultName) throws Exception {
    QName name;
    Struct corbaStruct = null;
    QName schematypeName = checkPrefix(complex.getQName());
    if (schematypeName == null) {
        schematypeName = createQNameTargetNamespace(defaultName.getLocalPart());
        if (defaultName.getNamespaceURI().equals("")) {
            schematypeName = checkPrefix(schematypeName);
        } else {
            schematypeName = checkPrefix(defaultName);
        }
        name = checkPrefix(createQNameCorbaNamespace(defaultName.getLocalPart()));
    } else {
        name = checkPrefix(createQNameCorbaNamespace(schematypeName.getLocalPart()));
    }
    corbaStruct = (Struct) recursionMap.get(name);
    if (corbaStruct != null) {
        return corbaStruct;
    }
    corbaStruct = new Struct();
    corbaStruct.setName(name.getLocalPart());
    corbaStruct.setQName(name);
    String repoId = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
    corbaStruct.setRepositoryID(repoId);
    corbaStruct.setType(schematypeName);
    recursionMap.put(name, corbaStruct);
    if (complex.getContentModel() instanceof XmlSchemaSimpleContent) {
        corbaStruct = processSimpleContentStruct((XmlSchemaSimpleContent) complex.getContentModel(), defaultName, corbaStruct, schematypeName);
    } else if (complex.getContentModel() instanceof XmlSchemaComplexContent) {
        corbaStruct = processComplexContentStruct((XmlSchemaComplexContent) complex.getContentModel(), defaultName, corbaStruct, schematypeName);
    }
    // Process attributes at ComplexType level
    if (!complex.getAttributes().isEmpty()) {
        String uri;
        if (schematypeName != null) {
            uri = schematypeName.getNamespaceURI();
        } else {
            uri = defaultName.getNamespaceURI();
        }
        List<MemberType> attlist2 = processAttributesAsMembers(complex.getAttributes(), uri);
        for (int i = 0; i < attlist2.size(); i++) {
            MemberType member = attlist2.get(i);
            corbaStruct.getMember().add(member);
        }
    }
    if (complex.getParticle() != null) {
        List<MemberType> members = processContainerAsMembers(complex.getParticle(), defaultName, schematypeName);
        for (MemberType memberType : members) {
            corbaStruct.getMember().add(memberType);
        }
    }
    recursionMap.remove(name);
    return corbaStruct;
}
Also used : XmlSchemaSimpleContent(org.apache.ws.commons.schema.XmlSchemaSimpleContent) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) QName(javax.xml.namespace.QName) XmlSchemaComplexContent(org.apache.ws.commons.schema.XmlSchemaComplexContent) Struct(org.apache.cxf.binding.corba.wsdl.Struct)

Example 12 with Struct

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

the class WSDLToIDLAction method createType.

protected IdlType createType(QName idlType, String[] name, CorbaType corbaType) throws Exception {
    if (idlType.getLocalPart().equals("CORBA.Object")) {
        return IdlInterface.create(null, "Object");
    }
    CorbaType corbaTypeImpl = corbaType;
    if (corbaTypeImpl == null) {
        corbaTypeImpl = getCorbaType(idlType);
    }
    if (corbaTypeImpl == null) {
        String msgStr = "Type " + idlType.getLocalPart() + " not found.";
        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
        throw new Exception(msg.toString());
    }
    IdlScopeBase scope = root;
    StringBuilder dotScopedName = new StringBuilder("");
    for (int i = 0; i < name.length - 1; ++i) {
        dotScopedName.append(name[i]);
        // name array.
        if ("CORBA".equals(dotScopedName.toString()) && name.length == 2 && i == 0 && name[1].equals("Object")) {
            break;
        }
        IdlDefn idlDef = scope.lookup(name[i]);
        if (idlDef == null) {
            // Before creating module, check to see if a Corba type
            // represent this name aleady exists.
            // For example if type is a.b.c and we are about to create
            // module b, look to see if a.b
            // is an interface that needs to be processed
            QName qname = new QName(corbaTypeImpl.getType().getNamespaceURI(), dotScopedName.toString());
            // Check to see if CORBAType exists. If so, create type for it
            // otherwise
            // create module for this scope
            CorbaType possibleCorbaType = getCorbaType(qname);
            if (possibleCorbaType != null) {
                idlDef = findType(qname);
            }
            if (idlDef == null) {
                idlDef = IdlModule.create(scope, name[i]);
                scope.addToScope(idlDef);
            }
        }
        dotScopedName.append(".");
        scope = (IdlScopeBase) idlDef;
    }
    IdlType result = null;
    String local = name[name.length - 1];
    if (corbaTypeImpl instanceof Enum) {
        result = createEnum((Enum) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Sequence) {
        result = createSequence((Sequence) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonsequence) {
        result = createAnonSequence((Anonsequence) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Exception) {
        result = createIdlException((org.apache.cxf.binding.corba.wsdl.Exception) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Struct) {
        result = createStruct((Struct) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Union) {
        result = createUnion((Union) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Alias) {
        result = createTypedef((Alias) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Array) {
        result = createArray((Array) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonarray) {
        result = createAnonArray((Anonarray) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Fixed) {
        result = createFixed((Fixed) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonfixed) {
        result = createAnonFixed((Anonfixed) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Const) {
        result = createConst((Const) corbaTypeImpl, scope, local);
    } else {
        result = checkAnon(corbaTypeImpl, scope, local);
    }
    if (result == null && corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Object) {
        result = createInterface((org.apache.cxf.binding.corba.wsdl.Object) corbaTypeImpl, scope, local);
    }
    return result;
}
Also used : IdlEnum(org.apache.cxf.tools.corba.common.idltypes.IdlEnum) Enum(org.apache.cxf.binding.corba.wsdl.Enum) IdlString(org.apache.cxf.tools.corba.common.idltypes.IdlString) IdlType(org.apache.cxf.tools.corba.common.idltypes.IdlType) Union(org.apache.cxf.binding.corba.wsdl.Union) IdlUnion(org.apache.cxf.tools.corba.common.idltypes.IdlUnion) IdlStruct(org.apache.cxf.tools.corba.common.idltypes.IdlStruct) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Anonarray(org.apache.cxf.binding.corba.wsdl.Anonarray) IdlFixed(org.apache.cxf.tools.corba.common.idltypes.IdlFixed) IdlAnonFixed(org.apache.cxf.tools.corba.common.idltypes.IdlAnonFixed) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed) QName(javax.xml.namespace.QName) IdlDefn(org.apache.cxf.tools.corba.common.idltypes.IdlDefn) Const(org.apache.cxf.binding.corba.wsdl.Const) IdlConst(org.apache.cxf.tools.corba.common.idltypes.IdlConst) IdlScopeBase(org.apache.cxf.tools.corba.common.idltypes.IdlScopeBase) IdlAnonSequence(org.apache.cxf.tools.corba.common.idltypes.IdlAnonSequence) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) IdlSequence(org.apache.cxf.tools.corba.common.idltypes.IdlSequence) IdlException(org.apache.cxf.tools.corba.common.idltypes.IdlException) IdlAnonArray(org.apache.cxf.tools.corba.common.idltypes.IdlAnonArray) Array(org.apache.cxf.binding.corba.wsdl.Array) IdlArray(org.apache.cxf.tools.corba.common.idltypes.IdlArray) Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Alias(org.apache.cxf.binding.corba.wsdl.Alias) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence)

Example 13 with Struct

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

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

the class WSDLToCorbaBindingTypeTest method testAnyType.

@Test
public void testAnyType() throws Exception {
    try {
        String fileName = getClass().getResource("/wsdl/any.wsdl").toString();
        generator.setWsdlFile(fileName);
        generator.addInterfaceName("anyInterface");
        Definition model = generator.generateCORBABinding();
        TypeMappingType mapType = (TypeMappingType) model.getExtensibilityElements().get(0);
        assertEquals(5, mapType.getStructOrExceptionOrUnion().size());
        int strcnt = 0;
        int unioncnt = 0;
        for (CorbaType corbaType : mapType.getStructOrExceptionOrUnion()) {
            if (corbaType instanceof Struct) {
                strcnt++;
            }
            if (corbaType instanceof Union) {
                unioncnt++;
            }
        }
        assertNotNull(mapType);
        assertEquals(3, strcnt);
        assertEquals(2, unioncnt);
        WSDLToIDLAction idlgen = new WSDLToIDLAction();
        idlgen.setBindingName("anyInterfaceCORBABinding");
        idlgen.setOutputFile("any.idl");
        idlgen.generateIDL(model);
        File f = new File("any.idl");
        assertTrue("any.idl should be generated", f.exists());
    } finally {
        new File("any.idl").deleteOnExit();
    }
}
Also used : WSDLToIDLAction(org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Definition(javax.wsdl.Definition) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) File(java.io.File) Union(org.apache.cxf.binding.corba.wsdl.Union) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Test(org.junit.Test)

Example 15 with Struct

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

the class WSDLToCorbaBindingTypeTest method testAnonFixedType.

// tests anonymous strings and fixed types.
@Test
public void testAnonFixedType() throws Exception {
    try {
        String fileName = getClass().getResource("/wsdl/anonfixed.wsdl").toString();
        generator.setWsdlFile(fileName);
        generator.addInterfaceName("X");
        Definition model = generator.generateCORBABinding();
        Document document = writer.getDocument(model);
        Element typemap = getElementNode(document, "corba:typeMapping");
        assertNotNull(typemap);
        assertEquals(1, typemap.getElementsByTagName("corba:anonfixed").getLength());
        assertEquals(1, typemap.getElementsByTagName("corba:anonstring").getLength());
        assertEquals(3, typemap.getElementsByTagName("corba:struct").getLength());
        TypeMappingType mapType = (TypeMappingType) model.getExtensibilityElements().get(0);
        WSDLToIDLAction idlgen = new WSDLToIDLAction();
        idlgen.setBindingName("XCORBABinding");
        idlgen.setOutputFile("atype.idl");
        idlgen.generateIDL(model);
        List<CorbaType> types = mapType.getStructOrExceptionOrUnion();
        for (int i = 0; i < types.size(); i++) {
            CorbaType type = types.get(i);
            if (type instanceof Anonstring) {
                Anonstring str = (Anonstring) type;
                assertEquals("Name is incorrect for Array Type", "X._1_S", str.getName());
                assertEquals("Type is incorrect for AnonString Type", "string", str.getType().getLocalPart());
            } else if (type instanceof Anonfixed) {
                Anonfixed fx = (Anonfixed) type;
                assertEquals("Name is incorrect for Anon Array Type", "X._2_S", fx.getName());
                assertEquals("Type is incorrect for AnonFixed Type", "decimal", fx.getType().getLocalPart());
            } else if (type instanceof Struct) {
                Struct struct = (Struct) type;
                String[] testResult;
                if ("X.op_a".equals(struct.getName())) {
                    testResult = new String[] { "X.op_a", "X.op_a", "p1", "X.S", "p2", "X.S" };
                } else if ("X.op_aResult".equals(struct.getName())) {
                    testResult = new String[] { "X.op_aResult", "X.op_aResult", "return", "X.S", "p2", "X.S" };
                } else {
                    testResult = new String[] { "X.S", "X.S", "str", "X._1_S", "fx", "X._2_S" };
                }
                assertEquals("Name is incorrect for Anon Array Type", testResult[0], struct.getName());
                assertEquals("Type is incorrect for Struct Type", testResult[1], struct.getType().getLocalPart());
                assertEquals("Name for first Struct Member Type is incorrect", testResult[2], struct.getMember().get(0).getName());
                assertEquals("Idltype for first Struct Member Type is incorrect", testResult[3], struct.getMember().get(0).getIdltype().getLocalPart());
                assertEquals("Name for second Struct Member Type is incorrect", testResult[4], struct.getMember().get(1).getName());
                assertEquals("Idltype for second Struct Member Type is incorrect", testResult[5], struct.getMember().get(1).getIdltype().getLocalPart());
            } else {
            // System.err.println("Type: " + i + " " + type.getClass().getName());
            }
        }
        File f = new File("atype.idl");
        assertTrue("atype.idl should be generated", f.exists());
    } finally {
        new File("atype.idl").deleteOnExit();
    }
}
Also used : WSDLToIDLAction(org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) Document(org.w3c.dom.Document) Anonstring(org.apache.cxf.binding.corba.wsdl.Anonstring) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) File(java.io.File) Test(org.junit.Test)

Aggregations

Struct (org.apache.cxf.binding.corba.wsdl.Struct)17 QName (javax.xml.namespace.QName)13 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)9 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)7 Test (org.junit.Test)6 Union (org.apache.cxf.binding.corba.wsdl.Union)4 StructMember (org.omg.CORBA.StructMember)4 TypeCode (org.omg.CORBA.TypeCode)4 File (java.io.File)3 Definition (javax.wsdl.Definition)3 Array (org.apache.cxf.binding.corba.wsdl.Array)3 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)3 TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)3 WSDLToIDLAction (org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction)3 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)2 CorbaStructHandler (org.apache.cxf.binding.corba.types.CorbaStructHandler)2 Alias (org.apache.cxf.binding.corba.wsdl.Alias)2 Anonarray (org.apache.cxf.binding.corba.wsdl.Anonarray)2 Anonfixed (org.apache.cxf.binding.corba.wsdl.Anonfixed)2 Anonsequence (org.apache.cxf.binding.corba.wsdl.Anonsequence)2