Search in sources :

Example 1 with SchemaImport

use of javax.wsdl.extensions.schema.SchemaImport in project components by Talend.

the class JAXBConfigGen method processSchema.

private void processSchema(javax.wsdl.extensions.schema.Schema schema, Collection<String> namespaceList) throws Exception {
    for (Iterator itImp = schema.getImports().values().iterator(); itImp.hasNext(); ) {
        Collection imps = (Collection) itImp.next();
        for (Iterator itSi = imps.iterator(); itSi.hasNext(); ) {
            SchemaImport imp = (SchemaImport) itSi.next();
            String namespaceUri = imp.getNamespaceURI();
            namespaceList.add(namespaceUri);
            processSchema(imp.getReferencedSchema(), namespaceList);
        }
    }
}
Also used : SchemaImport(javax.wsdl.extensions.schema.SchemaImport) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 2 with SchemaImport

use of javax.wsdl.extensions.schema.SchemaImport in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method initModels.

/**
 * Initiallize SOAP to REST Operations
 *
 * @return true if extracting operations was successful
 */
private boolean initModels() throws APIMgtWSDLException {
    wsdlDefinition = getWSDLDefinition();
    boolean canProcess = true;
    targetNamespace = wsdlDefinition.getTargetNamespace();
    Types types = wsdlDefinition.getTypes();
    if (types != null) {
        typeList = types.getExtensibilityElements();
    }
    if (typeList != null) {
        for (Object ext : typeList) {
            if (ext instanceof Schema) {
                Schema schema = (Schema) ext;
                Map importedSchemas = schema.getImports();
                Element schemaElement = schema.getElement();
                NodeList schemaNodes = schemaElement.getChildNodes();
                schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaNodes));
                // gets types from imported schemas from the parent wsdl. Nested schemas will not be imported.
                if (importedSchemas != null) {
                    for (Object importedSchemaObj : importedSchemas.keySet()) {
                        String schemaUrl = (String) importedSchemaObj;
                        if (importedSchemas.get(schemaUrl) != null) {
                            Vector vector = (Vector) importedSchemas.get(schemaUrl);
                            for (Object schemaVector : vector) {
                                if (schemaVector instanceof SchemaImport) {
                                    Schema referencedSchema = ((SchemaImport) schemaVector).getReferencedSchema();
                                    if (referencedSchema != null && referencedSchema.getElement() != null) {
                                        if (referencedSchema.getElement().hasChildNodes()) {
                                            schemaNodeList.addAll(SOAPOperationBindingUtils.list(referencedSchema.getElement().getChildNodes()));
                                        } else {
                                            log.warn("The referenced schema : " + schemaUrl + " doesn't have any defined types");
                                        }
                                    } else {
                                        boolean isInlineSchema = false;
                                        for (Object aSchema : typeList) {
                                            if (schemaUrl.equalsIgnoreCase(((Schema) aSchema).getElement().getAttribute(TARGET_NAMESPACE_ATTRIBUTE))) {
                                                isInlineSchema = true;
                                                break;
                                            }
                                        }
                                        if (isInlineSchema) {
                                            log.debug(schemaUrl + " is already defined inline. Hence continue.");
                                        } else {
                                            log.warn("Cannot access referenced schema for the schema defined at: " + schemaUrl);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    log.info("No any imported schemas found in the given wsdl.");
                }
                List schemaIncludes = schema.getIncludes();
                for (Iterator iter = schemaIncludes.iterator(); iter.hasNext(); ) {
                    SchemaReference schemaInclude = (SchemaReference) iter.next();
                    Schema schemaImp = schemaInclude.getReferencedSchema();
                    String schemaLoc = schemaInclude.getSchemaLocationURI();
                    if (schemaImp != null && schemaImp.getElement() != null) {
                        if (schemaImp.getElement().hasChildNodes()) {
                            schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaImp.getElement().getChildNodes()));
                        } else {
                            log.warn("The referenced schema : " + schemaLoc + " doesn't have any defined types");
                        }
                    }
                }
                if (log.isDebugEnabled()) {
                    Gson gson = new GsonBuilder().setExclusionStrategies(new SwaggerFieldsExcludeStrategy()).create();
                    log.debug("swagger definition model map from the wsdl: " + gson.toJson(parameterModelMap));
                }
                if (schemaNodeList == null) {
                    log.warn("No schemas found in the type element for target namespace:" + schema.getDocumentBaseURI());
                }
            }
        }
        if (schemaNodeList != null) {
            for (Node node : schemaNodeList) {
                WSDLParamDefinition wsdlParamDefinition = new WSDLParamDefinition();
                ModelImpl model = new ModelImpl();
                Property currentProperty = null;
                try {
                    traverseTypeElement(node, null, model, currentProperty);
                } catch (APIManagementException e) {
                    throw new APIMgtWSDLException(e);
                }
                if (StringUtils.isNotBlank(model.getName())) {
                    parameterModelMap.put(model.getName(), model);
                }
                if (wsdlParamDefinition.getDefinitionName() != null) {
                    wsdlParamDefinitions.add(wsdlParamDefinition);
                }
            }
        } else {
            log.info("No schema is defined in the wsdl document");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
    }
    return canProcess;
}
Also used : Types(javax.wsdl.Types) SwaggerFieldsExcludeStrategy(org.wso2.carbon.apimgt.impl.wsdl.util.SwaggerFieldsExcludeStrategy) WSDLParamDefinition(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLParamDefinition) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) GsonBuilder(com.google.gson.GsonBuilder) Schema(javax.wsdl.extensions.schema.Schema) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Gson(com.google.gson.Gson) SchemaReference(javax.wsdl.extensions.schema.SchemaReference) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) Vector(java.util.Vector) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty)

Example 3 with SchemaImport

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

the class ServiceWSDLBuilder method addSchemaImport.

private void addSchemaImport(Schema schema, SchemaInfo schemaInfo, Schema referencedSchema) {
    SchemaImport imp = schema.createImport();
    imp.setId(schemaInfo.getSystemId());
    imp.setNamespaceURI(schemaInfo.getNamespaceURI());
    imp.setSchemaLocationURI(referencedSchema.getDocumentBaseURI());
    imp.setReferencedSchema(referencedSchema);
    schema.addImport(imp);
}
Also used : XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) SchemaImport(javax.wsdl.extensions.schema.SchemaImport)

Example 4 with SchemaImport

use of javax.wsdl.extensions.schema.SchemaImport 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 5 with SchemaImport

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

the class WSDLSchemaManager method addWSDLSchemaImport.

private void addWSDLSchemaImport(Schema wsdlSchema, String tns, File file) {
    if (!wsdlSchema.getImports().containsKey(tns)) {
        SchemaImport schemaimport = wsdlSchema.createImport();
        schemaimport.setNamespaceURI(tns);
        if (file != null && !ignoreImports) {
            schemaimport.setSchemaLocationURI(file.toURI().toString());
        }
        wsdlSchema.addImport(schemaimport);
    }
}
Also used : XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) SchemaImport(javax.wsdl.extensions.schema.SchemaImport)

Aggregations

SchemaImport (javax.wsdl.extensions.schema.SchemaImport)10 Schema (javax.wsdl.extensions.schema.Schema)6 Types (javax.wsdl.Types)5 XmlSchema (org.apache.ws.commons.schema.XmlSchema)4 XmlSchemaImport (org.apache.ws.commons.schema.XmlSchemaImport)4 List (java.util.List)3 SchemaReference (javax.wsdl.extensions.schema.SchemaReference)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 XmlSchemaExternal (org.apache.ws.commons.schema.XmlSchemaExternal)2 Element (org.w3c.dom.Element)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ModelImpl (io.swagger.models.ModelImpl)1 ArrayProperty (io.swagger.models.properties.ArrayProperty)1 BooleanProperty (io.swagger.models.properties.BooleanProperty)1 DateProperty (io.swagger.models.properties.DateProperty)1