private javax.wsdl.Message findMessage(QName qn, Definition def, List<Definition> done) {
   javax.wsdl.Message msg = def.getMessage(qn);
   if (msg == null) {
     if (done.contains(def)) {
       return null;
     }
     done.add(def);
     Collection<List<Import>> ilist = CastUtils.cast(def.getImports().values());
     for (List<Import> list : ilist) {
       for (Import i : list) {
         if (qn.getNamespaceURI().equals(i.getDefinition().getTargetNamespace())) {
           return i.getDefinition().getMessage(qn);
         }
       }
     }
     for (List<Import> list : ilist) {
       for (Import i : list) {
         msg = findMessage(qn, i.getDefinition(), done);
         if (msg != null) {
           return msg;
         }
       }
     }
   }
   return msg;
 }
示例#2
0
 private void parseImports(Definition def) {
   for (Import impt : getImports(def)) {
     if (!importedDefinitions.contains(impt.getDefinition())) {
       importedDefinitions.add(impt.getDefinition());
       parseImports(impt.getDefinition());
     }
   }
 }
示例#3
0
  protected void updateDefinition(
      Definition def,
      Map<String, Definition> done,
      Map<String, SchemaReference> doneSchemas,
      String base,
      EndpointInfo ei) {
    OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);

    Collection<List<?>> imports = CastUtils.cast((Collection<?>) def.getImports().values());
    for (List<?> lst : imports) {
      List<Import> impLst = CastUtils.cast(lst);
      for (Import imp : impLst) {

        String start = imp.getLocationURI();
        String decodedStart = null;
        // Always use the URL decoded version to ensure that we have a
        // canonical representation of the import URL for lookup.
        try {
          decodedStart = URLDecoder.decode(start, "utf-8");
        } catch (UnsupportedEncodingException e) {
          throw new WSDLQueryException(
              new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e);
        }

        String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);

        if (resolvedSchemaLocation == null) {
          try {
            // check to see if it's already in a URL format.  If so, leave it.
            new URL(start);
          } catch (MalformedURLException e) {
            if (done.put(decodedStart, imp.getDefinition()) == null) {
              updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
            }
          }
        } else {
          if (done.put(decodedStart, imp.getDefinition()) == null) {
            done.put(resolvedSchemaLocation, imp.getDefinition());
            updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
          }
        }
      }
    }

    /* This doesn't actually work.   Setting setSchemaLocationURI on the import
     * for some reason doesn't actually result in the new URI being written
     * */
    Types types = def.getTypes();
    if (types != null) {
      for (ExtensibilityElement el :
          CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class)) {
        if (el instanceof Schema) {
          Schema see = (Schema) el;
          updateSchemaImports(see, doneSchemas, base);
        }
      }
    }
  }
  /*
   * Analyze the wsdl document at the given URI, and traverse any relative files that
   * it imports. Can optionally pass in a parsed Definition if one's available so
   * we don't have to parse the wsdl again (otherwise just pass in null).
   */
  private void analyzeWSDL(URI uri, Definition definition)
      throws MalformedURLException, IOException, WSDLException, WWWAuthenticationException {

    uri = uri.normalize();

    // already seen this wsdl, skip
    if (xmlObjectInfos.containsKey(uri.toString())) return;

    // need to parse the wsdl ourselves
    if (definition == null) definition = parser.getWSDLDefinitionVerbose(uri.toString());

    // save a reference to the starting wsdl
    if (this.definition == null) this.definition = definition;

    IPath path = new Path(uri.getPath());

    // a target filename was given, so we need to modify the path with the new name
    if (definition == this.definition && targetFilename != null)
      path = path.removeLastSegments(1).append(targetFilename);

    XMLObjectInfo info = new XMLObjectInfo(path, definition);
    xmlObjectInfos.put(uri.toString(), info);
    updatePathPrefix(info);

    // now look at wsdl imports

    for (Iterator it = definition.getImports().values().iterator(); it.hasNext(); ) {

      List list = (List) it.next();

      for (Iterator listIt = list.iterator(); listIt.hasNext(); ) {

        Import wsdlImport = (Import) listIt.next();
        String wsdlImportLocation = wsdlImport.getLocationURI();

        // analyze any relative imports we find
        if (wsdlImportLocation != null && isRelative(wsdlImportLocation)) {

          // bad form, importing xsd with wsdl:import, but need to handle
          if (wsdlImportLocation.toLowerCase().endsWith(XSD))
            analyzeXSD(uri.resolve(uriCreate(wsdlImportLocation)));
          else analyzeWSDL(uri.resolve(uriCreate(wsdlImportLocation)), null);
        }
      }
    }

    // now look at xsd imports

    Types types = definition.getTypes();

    // there's no wsdl:types, we're done
    if (types == null) return;

    for (Iterator it = types.getExtensibilityElements().iterator(); it.hasNext(); ) {

      ExtensibilityElement extElement = (ExtensibilityElement) it.next();
      Element element;

      // we'll try to parse any UnknownExtensibilityElements and
      // XSDSchemaExtensibilityElements into an XSD schema

      if (extElement instanceof UnknownExtensibilityElement)
        element = ((UnknownExtensibilityElement) extElement).getElement();
      else if (extElement instanceof XSDSchemaExtensibilityElement)
        element = ((XSDSchemaExtensibilityElement) extElement).getElement();
      else if (extElement instanceof Schema) element = ((Schema) extElement).getElement();
      else continue;

      try {
        XSDSchema xsdSchema = XSDSchemaImpl.createSchema(element);

        // analyze the inlined schema at the current uri
        analyzeXSD(uri, xsdSchema);
      } catch (Exception t) {
        // ignore any extensibility elements that cannot be parsed into a
        // XSDSchema instance
      }
    }
  }