/**
   * Finds nested XML schema definition and compiles it to a schema type system instance.
   *
   * @param wsdl
   * @return
   * @throws MojoExecutionException
   */
  private SchemaTypeSystem compileXsd(XmlObject wsdl) throws MojoExecutionException {
    // extract namespaces defined on wsdl-level:
    String[] namespacesWsdl = extractNamespacesOnWsdlLevel(wsdl);

    // calc the namespace-prefix of the schema-tag, default ""
    String schemaNsPrefix = extractSchemaNamespacePrefix(wsdl);

    // extract each schema-element and add missing namespaces defined on wsdl-level
    String[] schemas = getNestedSchemas(wsdl, namespacesWsdl, schemaNsPrefix);

    XmlObject[] xsd = new XmlObject[schemas.length];
    try {
      for (int i = 0; i < schemas.length; i++) {
        xsd[i] =
            XmlObject.Factory.parse(
                schemas[i],
                (new XmlOptions())
                    .setLoadLineNumbers()
                    .setLoadMessageDigest()
                    .setCompileDownloadUrls());
      }
    } catch (Exception e) {
      throw new MojoExecutionException("Failed to parse XSD schema", e);
    }

    SchemaTypeSystem schemaTypeSystem = null;
    try {
      schemaTypeSystem =
          XmlBeans.compileXsd(xsd, XmlBeans.getContextTypeLoader(), new XmlOptions());
    } catch (XmlException e) {
      for (Object error : e.getErrors()) {
        getLog().error("Line " + ((XmlError) error).getLine() + ": " + error.toString());
      }
      throw new MojoExecutionException("Failed to compile XSD schema", e);
    } catch (Exception e) {
      throw new MojoExecutionException("Failed to compile XSD schema", e);
    }
    return schemaTypeSystem;
  }