Ejemplo 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());
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void afterPropertiesSet() throws ParserConfigurationException, IOException, SAXException {
    Assert.notNull(wsdl, "wsdl file resource is required");
    Assert.isTrue(wsdl.exists(), "wsdl file resource '" + wsdl + " does not exist");

    try {
      loadSchemas();
    } catch (WSDLException e) {
      throw new BeanCreationException("Failed to load schema types from WSDL file", e);
    } catch (TransformerException e) {
      throw new BeanCreationException("Failed to load schema types from WSDL file", e);
    } catch (TransformerFactoryConfigurationError e) {
      throw new BeanCreationException("Failed to load schema types from WSDL file", e);
    }

    Assert.isTrue(!schemas.isEmpty(), "no schema types found in wsdl file resource");

    super.afterPropertiesSet();
  }
Ejemplo n.º 3
0
 @Override
 public XmlValidator createValidator() throws IOException {
   return XmlValidatorFactory.createValidator(
       schemas.toArray(new Resource[] {}), W3C_XML_SCHEMA_NS_URI);
 }