Exemplo n.º 1
0
  /**
   * 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;
  }
Exemplo n.º 2
0
  /**
   * Compiles WSDL file resource to a XmlObject.
   *
   * @return
   * @throws MojoExecutionException
   * @throws IOException
   */
  private XmlObject compileWsdl() throws MojoExecutionException, IOException {
    Resource wsdlFile = new PathMatchingResourcePatternResolver().getResource(pathToWsdl);
    if (!wsdlFile.exists()) {
      throw new MojoExecutionException(
          "Unable to read WSDL - does not exist in " + wsdlFile.getFile().getAbsolutePath());
    }

    if (!wsdlFile.getFile().canRead()) {
      throw new MojoExecutionException("Unable to read WSDL - could not open in read mode");
    }

    try {
      return XmlObject.Factory.parse(
          wsdlFile.getFile(),
          (new XmlOptions()).setLoadLineNumbers().setLoadMessageDigest().setCompileDownloadUrls());
    } catch (XmlException e) {
      for (Object error : e.getErrors()) {
        getLog().error(((XmlError) error).getLine() + "" + error.toString());
      }
      throw new MojoExecutionException("WSDL could not be parsed", e);
    } catch (Exception e) {
      throw new MojoExecutionException("WSDL could not be parsed", e);
    }
  }