Search in sources :

Example 6 with XmlSchemaExternal

use of org.apache.ws.commons.schema.XmlSchemaExternal 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)

Example 7 with XmlSchemaExternal

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

the class WSDLParameter method findSchemaType.

// This willl search the current schemas and any included
// schemas for the schema type.
private static XmlSchemaType findSchemaType(XmlSchema xmlSchema, QName typeName) {
    XmlSchemaType schemaType = xmlSchema.getTypeByName(typeName);
    if (schemaType == null) {
        for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
            if (ext instanceof XmlSchemaImport) {
                XmlSchemaImport xmlImport = (XmlSchemaImport) ext;
                if (xmlImport.getNamespace().equals(typeName.getNamespaceURI())) {
                    XmlSchema importSchema = xmlImport.getSchema();
                    schemaType = importSchema.getTypeByName(typeName);
                } else {
                    schemaType = findSchemaType(ext.getSchema(), typeName);
                    if (schemaType != null) {
                        return schemaType;
                    }
                }
            }
        }
        if (schemaType != null) {
            return schemaType;
        }
    }
    return schemaType;
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 8 with XmlSchemaExternal

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

the class ObjectReferenceVisitor method addWSAddressingImport.

private void addWSAddressingImport(XmlSchema s) {
    boolean alreadyImported = false;
    for (XmlSchemaExternal ext : s.getExternals()) {
        if (ext instanceof XmlSchemaImport) {
            XmlSchemaImport schemaImport = (XmlSchemaImport) ext;
            if (schemaImport.getNamespace().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
                alreadyImported = true;
                break;
            }
        }
    }
    if (!alreadyImported) {
        // We need to add an import statement to include the WS addressing types
        XmlSchemaImport wsaImport = new XmlSchemaImport(s);
        wsaImport.setNamespace(ReferenceConstants.WSADDRESSING_NAMESPACE);
        wsaImport.setSchemaLocation(ReferenceConstants.WSADDRESSING_LOCATION);
    }
    // Add the addressing namespace to the WSDLs list of namespaces.
    definition.addNamespace(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE);
    try {
        // This is used to get the correct prefix in the schema section of
        // the wsdl.  If we don't have this, then this namespace gets an
        // arbitrary prefix (e.g. ns5 instead of wsa).
        NamespaceMap nsMap = (NamespaceMap) s.getNamespaceContext();
        if (nsMap == null) {
            nsMap = new NamespaceMap();
            nsMap.add(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE);
            s.setNamespaceContext(nsMap);
        } else {
            nsMap.add(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE);
        }
    } catch (ClassCastException ex) {
    // Consume the exception.  It is still OK with the default prefix,
    // just not as clear.
    }
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Example 9 with XmlSchemaExternal

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

the class ParamDeferredAction method execute.

public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
    if (param != null) {
        param.setIdltype(ctype.getQName());
    }
    if (element != null) {
        element.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
        if (manager == null) {
            return;
        }
        // Now we need to make sure we are importing any types we need
        XmlSchema importedSchema = null;
        if (stype.getQName().getNamespaceURI().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
            boolean alreadyImported = false;
            for (XmlSchemaExternal ext : schema.getExternals()) {
                if (ext instanceof XmlSchemaImport) {
                    XmlSchemaImport schemaImport = (XmlSchemaImport) ext;
                    if (schemaImport.getNamespace().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
                        alreadyImported = true;
                        break;
                    }
                }
            }
            if (!alreadyImported) {
                // We need to add an import statement to include the WS addressing types
                XmlSchemaImport wsaImport = new XmlSchemaImport(schema);
                wsaImport.setNamespace(ReferenceConstants.WSADDRESSING_NAMESPACE);
                wsaImport.setSchemaLocation(ReferenceConstants.WSADDRESSING_LOCATION);
            }
        } else if (!stype.getQName().getNamespaceURI().equals(schema.getTargetNamespace())) {
            importedSchema = manager.getXmlSchema(mapper.map(typeScope));
            manager.addXmlSchemaImport(schema, importedSchema, typeScope.toString("_"));
        }
    }
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Example 10 with XmlSchemaExternal

use of org.apache.ws.commons.schema.XmlSchemaExternal 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)

Aggregations

XmlSchemaExternal (org.apache.ws.commons.schema.XmlSchemaExternal)10 XmlSchemaImport (org.apache.ws.commons.schema.XmlSchemaImport)9 XmlSchema (org.apache.ws.commons.schema.XmlSchema)4 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 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)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 TreeMap (java.util.TreeMap)1 SchemaReference (javax.wsdl.extensions.schema.SchemaReference)1 XMLStreamException (javax.xml.stream.XMLStreamException)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 XMLValidationSchema (org.codehaus.stax2.validation.XMLValidationSchema)1