Search in sources :

Example 11 with TypeMappingType

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

Example 12 with TypeMappingType

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

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

the class WSDLToCorbaBindingTypeTest method testAnonType.

// tests anonymous arrays and sequences
@Test
public void testAnonType() throws Exception {
    try {
        String fileName = getClass().getResource("/wsdl/atype.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(3, typemap.getElementsByTagName("corba:anonsequence").getLength());
        assertEquals(2, typemap.getElementsByTagName("corba:anonarray").getLength());
        assertEquals(1, typemap.getElementsByTagName("corba:array").getLength());
        assertEquals(2, typemap.getElementsByTagName("corba:struct").getLength());
        TypeMappingType mapType = (TypeMappingType) model.getExtensibilityElements().get(0);
        Map<String, CorbaType> tmap = new HashMap<>();
        for (CorbaType type : mapType.getStructOrExceptionOrUnion()) {
            tmap.put(type.getName(), type);
        }
        WSDLToIDLAction idlgen = new WSDLToIDLAction();
        idlgen.setBindingName("XCORBABinding");
        idlgen.setOutputFile("atype.idl");
        idlgen.generateIDL(model);
        Array arr = (Array) tmap.get("X.A");
        assertNotNull(arr);
        assertEquals("ElementType is incorrect for Array Type", "X._5_A", arr.getElemtype().getLocalPart());
        Anonarray arr2 = (Anonarray) tmap.get("X._5_A");
        assertNotNull(arr2);
        assertEquals("ElementType is incorrect for Anon Array Type", "X._4_A", arr2.getElemtype().getLocalPart());
        Anonarray arr3 = (Anonarray) tmap.get("X._4_A");
        assertNotNull(arr3);
        assertEquals("ElementType is incorrect for Anon Array Type", "X._1_A", arr3.getElemtype().getLocalPart());
        Anonsequence seq = (Anonsequence) tmap.get("X._1_A");
        assertNotNull(seq);
        assertEquals("ElementType is incorrect for Anon Sequence Type", "X._2_A", seq.getElemtype().getLocalPart());
        Anonsequence seq2 = (Anonsequence) tmap.get("X._2_A");
        assertNotNull(seq2);
        assertEquals("ElementType is incorrect for Anon Sequence Type", "X._3_A", seq2.getElemtype().getLocalPart());
        Anonsequence seq3 = (Anonsequence) tmap.get("X._3_A");
        assertNotNull(seq3);
        assertEquals("ElementType is incorrect for Anon Sequence Type", "long", seq3.getElemtype().getLocalPart());
        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) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) Document(org.w3c.dom.Document) Array(org.apache.cxf.binding.corba.wsdl.Array) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Anonarray(org.apache.cxf.binding.corba.wsdl.Anonarray) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence) File(java.io.File) Test(org.junit.Test)

Example 14 with TypeMappingType

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

the class ScopedNameVisitor method findSchemaTypeInGlobalScope.

private static boolean findSchemaTypeInGlobalScope(Scope scope, Definition defn, XmlSchema currentSchema, AST node, WSDLASTVisitor wsdlVisitor, VisitorTypeHolder holder) {
    XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
    TypeMappingType typeMap = wsdlVisitor.getTypeMap();
    ModuleToNSMapper mapper = wsdlVisitor.getModuleToNSMapper();
    WSDLSchemaManager manager = wsdlVisitor.getManager();
    Scope scopedName = new Scope(scope, node);
    String name = node.toString();
    if (isFullyScopedName(node)) {
        scopedName = getFullyScopedName(new Scope(), node);
        name = scopedName.toString();
    }
    boolean result = findNonSchemaType(name, wsdlVisitor, holder);
    if (!result) {
        XmlSchema xmlSchema = currentSchema;
        QName qname = null;
        String tns = mapper.map(scopedName.getParent());
        if (tns != null) {
            xmlSchema = manager.getXmlSchema(tns);
            if (xmlSchema != null) {
                qname = new QName(xmlSchema.getTargetNamespace(), scopedName.tail());
            }
        } else {
            qname = new QName(xmlSchema.getTargetNamespace(), name);
        }
        XmlSchemaType stype = null;
        if (qname != null) {
            // Exceptions are treated as a special case as above
            if (exceptionMode) {
                qname = new QName(xmlSchema.getTargetNamespace(), qname.getLocalPart() + "Type");
            }
            stype = xmlSchema.getTypeByName(qname);
            if (stype == null) {
                stype = schemas.getTypeByQName(qname);
            }
        }
        if (stype != null) {
            result = true;
            if (holder != null) {
                holder.setSchemaType(stype);
                holder.setCorbaType(getCorbaSchemaType(xmlSchema, typeMap, stype, scopedName));
                // add a xmlschema import
                if (!currentSchema.getTargetNamespace().equals(xmlSchema.getTargetNamespace())) {
                    String importFile = wsdlVisitor.getOutputDir() + System.getProperty("file.separator") + scopedName.getParent().toString("_");
                    manager.addXmlSchemaImport(currentSchema, xmlSchema, importFile);
                }
            }
        }
    }
    return result;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection)

Example 15 with TypeMappingType

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

the class CorbaUtils method createCorbaTypeMap.

public static CorbaTypeMap createCorbaTypeMap(List<TypeMappingType> tmTypes) {
    CorbaTypeMap map = null;
    if (tmTypes != null) {
        // Currently, only one type map
        TypeMappingType tmType = tmTypes.get(0);
        map = new CorbaTypeMap(tmType.getTargetNamespace());
        List<CorbaType> types = tmType.getStructOrExceptionOrUnion();
        LOG.fine("Found " + types.size() + " types defined in the typemap");
        for (Iterator<CorbaType> it = types.iterator(); it.hasNext(); ) {
            CorbaType corbaType = it.next();
            String name = corbaType.getName();
            // There can be some instances where a prefix is added to the name by the tool
            // (e.g. Object Reference Names).  Since the name is read as a string, this
            // prefix is added to the types name.  Remove this as it is not needed.
            int pos = name.lastIndexOf(':');
            if (pos != -1) {
                name = name.substring(pos + 1);
                corbaType.setName(name);
            }
            map.addType(name, corbaType);
            LOG.fine("Adding type " + name);
        }
    }
    return map;
}
Also used : CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType)

Aggregations

TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)15 Definition (javax.wsdl.Definition)8 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)8 Test (org.junit.Test)8 QName (javax.xml.namespace.QName)7 File (java.io.File)6 WSDLToIDLAction (org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction)6 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)4 Struct (org.apache.cxf.binding.corba.wsdl.Struct)3 Union (org.apache.cxf.binding.corba.wsdl.Union)3 XmlSchema (org.apache.ws.commons.schema.XmlSchema)3 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)3 HashMap (java.util.HashMap)2 Binding (javax.wsdl.Binding)2 BindingOperation (javax.wsdl.BindingOperation)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 CorbaTypeMap (org.apache.cxf.binding.corba.CorbaTypeMap)2 Alias (org.apache.cxf.binding.corba.wsdl.Alias)2