Search in sources :

Example 1 with XmlSchemaImport

use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.

the class XmlSchemaUtils method addImportIfNeeded.

/**
 * Assist in managing the required <import namespace='uri'> for imports of peer schemas.
 * @param schema
 * @param namespaceUri
 */
public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) {
    // no need to import nothing or the XSD schema, or the schema we are fixing.
    if ("".equals(namespaceUri) || Constants.URI_2001_SCHEMA_XSD.equals(namespaceUri) || schema.getTargetNamespace().equals(namespaceUri)) {
        return;
    }
    List<XmlSchemaExternal> externals = schema.getExternals();
    for (XmlSchemaExternal what : externals) {
        if (what instanceof XmlSchemaImport) {
            XmlSchemaImport imp = (XmlSchemaImport) what;
            // already there.
            if (namespaceUri.equals(imp.getNamespace())) {
                return;
            }
        }
    }
    XmlSchemaImport imp = new XmlSchemaImport(schema);
    imp.setNamespace(namespaceUri);
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Example 2 with XmlSchemaImport

use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.

the class WSDLSchemaManager method attachSchemaToWSDL.

public void attachSchemaToWSDL(Definition definition, XmlSchema schema, boolean isSchemaGenerated) throws Exception {
    Types types = definition.getTypes();
    if (types == null) {
        types = definition.createTypes();
        definition.setTypes(types);
    }
    Schema wsdlSchema = (Schema) definition.getExtensionRegistry().createExtension(Types.class, new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));
    // See if a NamespaceMap has already been added to the schema (this can be the case with object
    // references. If so, simply add the XSD URI to the map. Otherwise, create a new one.
    NamespaceMap nsMap = null;
    try {
        nsMap = (NamespaceMap) schema.getNamespaceContext();
    } catch (ClassCastException ex) {
    // Consume. This will mean that the context has not been set.
    }
    if (nsMap == null) {
        nsMap = new NamespaceMap();
        nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
        schema.setNamespaceContext(nsMap);
    } else {
        nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
    }
    if (isSchemaGenerated) {
        nsMap.add("tns", schema.getTargetNamespace());
    }
    org.w3c.dom.Element el = schema.getAllSchemas()[0].getDocumentElement();
    wsdlSchema.setElement(el);
    for (XmlSchemaExternal ext : schema.getExternals()) {
        if (ext instanceof XmlSchemaImport) {
            XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) ext;
            SchemaImport schemaimport = wsdlSchema.createImport();
            schemaimport.setNamespaceURI(xmlSchemaImport.getNamespace());
            if (xmlSchemaImport.getSchemaLocation() != null && !ignoreImports) {
                schemaimport.setSchemaLocationURI(xmlSchemaImport.getSchemaLocation());
            }
            wsdlSchema.addImport(schemaimport);
        }
    }
    types.addExtensibilityElement(wsdlSchema);
}
Also used : Types(javax.wsdl.Types) XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) QName(javax.xml.namespace.QName) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Example 3 with XmlSchemaImport

use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.

the class WSDLToCorbaHelper method findTypeInSchema.

private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
    XmlSchemaType schemaType = null;
    if (xmlSchema.getElementByName(typeName) != null) {
        XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
        schemaType = schemaElement.getSchemaType();
    } else if (xmlSchema.getTypeByName(typeName) != null) {
        schemaType = xmlSchema.getTypeByName(typeName);
    }
    if (schemaType != null) {
        return schemaType;
    }
    for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
        if (!(extSchema instanceof XmlSchemaImport)) {
            schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
            if (schemaType != null) {
                return schemaType;
            }
        }
    }
    return null;
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 4 with XmlSchemaImport

use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.

the class WSDLSchemaManager method addXmlSchemaImport.

public void addXmlSchemaImport(XmlSchema rootSchema, XmlSchema schema, File file) {
    // Make sure we haven't already imported the schema.
    String importNamespace = schema.getTargetNamespace();
    boolean included = false;
    for (XmlSchemaExternal ext : rootSchema.getExternals()) {
        if (ext instanceof XmlSchemaImport) {
            XmlSchemaImport imp = (XmlSchemaImport) ext;
            if (imp.getNamespace().equals(importNamespace)) {
                included = true;
                break;
            }
        }
    }
    if (!included) {
        XmlSchemaImport importSchema = new XmlSchemaImport(rootSchema);
        if (!ignoreImports) {
            importSchema.setSchemaLocation(file.toURI().toString());
        }
        importSchema.setNamespace(schema.getTargetNamespace());
    }
    if (!importedSchemas.containsKey(file)) {
        importedSchemas.put(file, schema);
    }
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Example 5 with XmlSchemaImport

use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.

the class WSDLParameter method findElement.

// Will check if the schema includes other schemas.
private static XmlSchemaElement findElement(XmlSchema xmlSchema, QName elName) {
    XmlSchemaElement schemaElement = null;
    schemaElement = xmlSchema.getElementByName(elName);
    if (schemaElement == null) {
        String prefix = definition.getPrefix(elName.getNamespaceURI());
        QName name = new QName(elName.getNamespaceURI(), prefix + ":" + elName.getLocalPart(), prefix);
        schemaElement = xmlSchema.getElementByName(name);
    }
    if (schemaElement != null) {
        return schemaElement;
    }
    for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
        if (!(ext instanceof XmlSchemaImport)) {
            schemaElement = findElement(ext.getSchema(), elName);
            if (schemaElement != null) {
                return schemaElement;
            }
        }
    }
    return schemaElement;
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Aggregations

XmlSchemaImport (org.apache.ws.commons.schema.XmlSchemaImport)10 XmlSchemaExternal (org.apache.ws.commons.schema.XmlSchemaExternal)9 XmlSchema (org.apache.ws.commons.schema.XmlSchema)3 Types (javax.wsdl.Types)2 Schema (javax.wsdl.extensions.schema.Schema)2 SchemaImport (javax.wsdl.extensions.schema.SchemaImport)2 QName (javax.xml.namespace.QName)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)2 NamespaceMap (org.apache.ws.commons.schema.utils.NamespaceMap)2 SchemaReference (javax.wsdl.extensions.schema.SchemaReference)1 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)1 XmlSchemaInclude (org.apache.ws.commons.schema.XmlSchemaInclude)1 XmlSchemaRedefine (org.apache.ws.commons.schema.XmlSchemaRedefine)1 XmlSchemaSerializerException (org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException)1