Exemplo n.º 1
0
  /**
   * Loads nested schema type definitions from wsdl.
   *
   * @throws IOException
   * @throws WSDLException
   * @throws TransformerFactoryConfigurationError
   * @throws TransformerException
   * @throws TransformerConfigurationException
   */
  private void loadSchemas()
      throws WSDLException, IOException, TransformerConfigurationException, TransformerException,
          TransformerFactoryConfigurationError {
    Definition definition =
        WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdl.getFile().getAbsolutePath());

    Types types = definition.getTypes();
    List<?> schemaTypes = types.getExtensibilityElements();

    for (Object schemaObject : schemaTypes) {
      if (schemaObject instanceof SchemaImpl) {
        SchemaImpl schema = (SchemaImpl) schemaObject;

        inheritNamespaces(schema, definition);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Source source = new DOMSource(schema.getElement());
        Result result = new StreamResult(bos);

        TransformerFactory.newInstance().newTransformer().transform(source, result);
        Resource schemaResource = new ByteArrayResource(bos.toByteArray());

        schemas.add(schemaResource);

        if (definition
            .getTargetNamespace()
            .equals(schema.getElement().getAttribute("targetNamespace"))) {
          setXsd(schemaResource);
        }
      } else {
        log.warn("Found unsupported schema type implementation " + schemaObject.getClass());
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Adds WSDL level namespaces to schema definition if necessary.
   *
   * @param schema
   * @param wsdl
   */
  @SuppressWarnings("unchecked")
  private void inheritNamespaces(SchemaImpl schema, Definition wsdl) {
    Map<String, String> wsdlNamespaces = wsdl.getNamespaces();

    for (Entry<String, String> nsEntry : wsdlNamespaces.entrySet()) {
      if (StringUtils.hasText(nsEntry.getKey())) {
        if (!schema.getElement().hasAttributeNS(WWW_W3_ORG_2000_XMLNS, nsEntry.getKey())) {
          schema
              .getElement()
              .setAttributeNS(
                  WWW_W3_ORG_2000_XMLNS, "xmlns:" + nsEntry.getKey(), nsEntry.getValue());
        }
      } else { // handle default namespace
        if (!schema.getElement().hasAttribute("xmlns")) {
          schema
              .getElement()
              .setAttributeNS(
                  WWW_W3_ORG_2000_XMLNS, "xmlns" + nsEntry.getKey(), nsEntry.getValue());
        }
      }
    }
  }