Example #1
0
  public FWSDL(File wsdlFile) throws MalformedURLException, Exception {
    log.info("Reading WSDL definition from " + wsdlFile);

    Definition wsdlDef = new WSDLReaderImpl().readWSDL(wsdlFile.getAbsolutePath());
    Map<?, ?> wsdlNamespaces = wsdlDef.getNamespaces();

    if (wsdlDef.getTypes() != null) {
      List<?> exEls = wsdlDef.getTypes().getExtensibilityElements();
      for (int i = 0; i < exEls.size(); i++) {
        Object a = exEls.get(i);

        /* Ignore Types != an XML Schema */
        if (javax.wsdl.extensions.schema.Schema.class.isAssignableFrom(a.getClass())) {
          javax.wsdl.extensions.schema.Schema containedSchema =
              (javax.wsdl.extensions.schema.Schema) a;

          log.debug("Found XMLSchema in WSDL: " + containedSchema);

          /* This is the root node of the XML Schema tree */
          Element schemaElement = containedSchema.getElement();

          /*
           * Go through all parent namespace declarations and copy
           * them into the tree of the XMLSchema.
           * (probably a little hacky)
           */
          for (Object key : wsdlNamespaces.keySet()) {
            String nsShort = (String) key;
            String nsLong = (String) wsdlNamespaces.get(key);

            if (schemaElement.getAttribute("xmlns:" + nsShort).length() == 0) {
              schemaElement.setAttribute("xmlns:" + nsShort, nsLong);
            }
          }

          /* Fall back on global defininiton */
          if (schemaElement.getAttribute("targetNamespace").length() == 0) {
            schemaElement.setAttribute("targetNamespace", wsdlDef.getTargetNamespace());
          }

          /*
           * TODO: more things to take care of when cutting out the
           * schema?
           */
          Schema schemaDocument = SchemaDocument.Factory.parse(schemaElement).getSchema();
          log.debug("Adding schema to FSchema: " + schemaDocument);
          schema.addSchema(schemaDocument, wsdlFile.toURI());
        }

        // log.debug("Ignoring unknown ExtensibilityElement in WSDL (type: " + a.getClass() + ") -->
        // " + a);
      }
    }
  }