Search in sources :

Example 6 with SchemaImport

use of javax.wsdl.extensions.schema.SchemaImport in project cxf by apache.

the class SchemaUtil method addSchema.

private void addSchema(String docBaseURI, Schema schema) {
    // String docBaseURI = schema.getDocumentBaseURI();
    Element schemaEle = schema.getElement();
    if (schemaList.get(docBaseURI) == null) {
        schemaList.put(docBaseURI, schemaEle);
    } else if (schemaList.get(docBaseURI) != null && schemaList.containsValue(schemaEle)) {
    // do nothing
    } else {
        String tns = schema.getDocumentBaseURI() + "#" + schema.getElement().getAttribute("targetNamespace");
        if (schemaList.get(tns) == null) {
            schemaList.put(tns, schema.getElement());
        }
    }
    Map<String, List<?>> imports = CastUtils.cast(schema.getImports());
    if (imports != null && !imports.isEmpty()) {
        for (Map.Entry<String, List<?>> entry : imports.entrySet()) {
            String importNamespace = entry.getKey();
            List<SchemaImport> schemaImports = CastUtils.cast(entry.getValue());
            for (SchemaImport schemaImport : schemaImports) {
                Schema tempImport = schemaImport.getReferencedSchema();
                String key = schemaImport.getSchemaLocationURI();
                if (importNamespace == null && tempImport != null) {
                    importNamespace = tempImport.getDocumentBaseURI();
                }
                if (tempImport != null && !catalogResolved.containsKey(key)) {
                    key = tempImport.getDocumentBaseURI();
                }
                if (tempImport != null && !isSchemaParsed(key, importNamespace) && !schemaList.containsValue(tempImport.getElement())) {
                    addSchema(key, tempImport);
                }
            }
        }
    }
}
Also used : SchemaImport(javax.wsdl.extensions.schema.SchemaImport) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema) ArrayList(java.util.ArrayList) List(java.util.List) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with SchemaImport

use of javax.wsdl.extensions.schema.SchemaImport in project cxf by apache.

the class ServiceWSDLBuilder method buildTypes.

protected void buildTypes(final Collection<SchemaInfo> schemas, final Map<String, SchemaInfo> imports, final Definition def) {
    Types types = def.createTypes();
    for (SchemaInfo schemaInfo : schemas) {
        Schema schemaImpl = getSchemaImplementation(def);
        schemaImpl.setRequired(true);
        schemaImpl.setElementType(WSDLConstants.QNAME_SCHEMA);
        schemaImpl.setElement(schemaInfo.getElement());
        for (XmlSchemaExternal ext : schemaInfo.getSchema().getExternals()) {
            if (ext.getSchema() == null) {
                continue;
            }
            if (ext instanceof XmlSchemaImport) {
                SchemaImport imp = schemaImpl.createImport();
                imp.setNamespaceURI(((XmlSchemaImport) ext).getNamespace());
                imp.setSchemaLocationURI(((XmlSchemaImport) ext).getSchemaLocation());
                Schema schemaImpl2 = getSchemaImplementation(def);
                schemaImpl2.setRequired(true);
                schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
                schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
                try {
                    schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
                } catch (XmlSchemaSerializerException e) {
                // ignore
                }
                imp.setReferencedSchema(schemaImpl2);
                schemaImpl.addImport(imp);
            } else if (ext instanceof XmlSchemaInclude) {
                SchemaReference imp = schemaImpl.createInclude();
                imp.setSchemaLocationURI(((XmlSchemaInclude) ext).getSchemaLocation());
                Schema schemaImpl2 = getSchemaImplementation(def);
                schemaImpl2.setRequired(true);
                schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
                schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
                try {
                    schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
                } catch (XmlSchemaSerializerException e) {
                // ignore
                }
                imp.setReferencedSchema(schemaImpl2);
                schemaImpl.addInclude(imp);
            } else if (ext instanceof XmlSchemaRedefine) {
                SchemaReference imp = schemaImpl.createRedefine();
                imp.setSchemaLocationURI(((XmlSchemaRedefine) ext).getSchemaLocation());
                Schema schemaImpl2 = getSchemaImplementation(def);
                schemaImpl2.setRequired(true);
                schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
                schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
                try {
                    schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
                } catch (XmlSchemaSerializerException e) {
                // ignore
                }
                imp.setReferencedSchema(schemaImpl2);
                schemaImpl.addRedefine(imp);
            }
        }
        types.addExtensibilityElement(schemaImpl);
    }
    def.setTypes(types);
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) Types(javax.wsdl.Types) XmlSchemaRedefine(org.apache.ws.commons.schema.XmlSchemaRedefine) XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) Schema(javax.wsdl.extensions.schema.Schema) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) XmlSchemaInclude(org.apache.ws.commons.schema.XmlSchemaInclude) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 8 with SchemaImport

use of javax.wsdl.extensions.schema.SchemaImport in project cxf by apache.

the class ServiceWSDLBuilderTest method testXsdImportMultipleSchemas.

@Test
public void testXsdImportMultipleSchemas() throws Exception {
    setupWSDL(WSDL_XSD_IMPORT_PATH, true);
    Types types = newDef.getTypes();
    assertNotNull(types);
    Collection<ExtensibilityElement> schemas = CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class);
    assertEquals(1, schemas.size());
    Schema schema = (Schema) schemas.iterator().next();
    assertEquals(1, schema.getImports().values().size());
    SchemaImport serviceTypesSchemaImport = getImport(schema.getImports(), "http://apache.org/hello_world_soap_http/servicetypes");
    Schema serviceTypesSchema = serviceTypesSchemaImport.getReferencedSchema();
    assertEquals(1, serviceTypesSchema.getImports().values().size());
    SchemaImport typesSchemaImport = getImport(serviceTypesSchema.getImports(), "http://apache.org/hello_world_soap_http/types");
    Schema typesSchema = typesSchemaImport.getReferencedSchema();
    Document doc = typesSchema.getElement().getOwnerDocument();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(outputStream, "utf-8");
    StaxUtils.writeNode(doc, writer, true);
    writer.close();
    // this is a test to make sure any embedded namespaces are properly included
    String savedSchema = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
    assertTrue(savedSchema.contains("http://www.w3.org/2005/05/xmlmime"));
    SchemaImport types2SchemaImport = getImport(typesSchema.getImports(), "http://apache.org/hello_world_soap_http/types2");
    Schema types2Schema = types2SchemaImport.getReferencedSchema();
    assertNotNull(types2Schema);
}
Also used : Types(javax.wsdl.Types) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Test(org.junit.Test)

Aggregations

SchemaImport (javax.wsdl.extensions.schema.SchemaImport)8 Schema (javax.wsdl.extensions.schema.Schema)5 Types (javax.wsdl.Types)4 XmlSchema (org.apache.ws.commons.schema.XmlSchema)4 XmlSchemaImport (org.apache.ws.commons.schema.XmlSchemaImport)4 List (java.util.List)2 SchemaReference (javax.wsdl.extensions.schema.SchemaReference)2 QName (javax.xml.namespace.QName)2 XmlSchemaExternal (org.apache.ws.commons.schema.XmlSchemaExternal)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)1