/**
   * Returns a processor handling XQuery queries. Suitable processor is found by matching return
   * type and handled extension.
   */
  private Processor<ModuleNode> getXQueryProcessor() {
    for (final Processor p : Lookup.getDefault().lookupAll(Processor.class)) {
      if (p.getResultType().equals(ModuleNode.class) && p.getExtension().equals("xq")) {
        return p;
      }
    }

    return null;
  }
  /**
   * Returns the map (folder - (extension - processor) ) of all processors installed in this
   * NetBeans which process IG.
   */
  @SuppressWarnings("unchecked")
  private Map<FolderType, Map<String, Processor<Element>>> getRegisteredProcessors() {
    final Map<FolderType, Map<String, Processor<Element>>> ret =
        new HashMap<FolderType, Map<String, Processor<Element>>>();

    for (final FolderType ft : FolderType.values()) {
      ret.put(ft, new HashMap<String, Processor<Element>>());
    }

    for (final Processor p : Lookup.getDefault().lookupAll(Processor.class)) {
      if (p.getResultType().equals(Element.class)) {
        if (p.processUndefined()) {
          ret.get(p.getFolder()).put("*", p);
        }
        ret.get(p.getFolder()).put(p.getExtension(), p);
      }
    }

    return ret;
  }
  /**
   * Processes files with XQuery queries by supplying them to the specified processor. Result is a
   * list of respective syntax trees.
   */
  private List<ModuleNode> processXQueries(
      final Collection<File> files, final Processor<ModuleNode> xqueryProcessor)
      throws InterruptedException {
    if (BaseUtils.isEmpty(files) || xqueryProcessor == null) {
      return new ArrayList<ModuleNode>(0);
    }

    final List<ModuleNode> ret = new ArrayList<ModuleNode>();

    for (final File f : files) {
      if (Thread.interrupted()) {
        throw new InterruptedException();
      }
      try {
        if (FileUtils.getExtension(f.getAbsolutePath()).equals(xqueryProcessor.getExtension())) {
          /* TODO rio Interface of input processor requires List as a return type
           * but our XQuery processor returns only one syntax tree per file. So
           * it is at index 0. An empty list indicates parsing error.
           */
          final List<ModuleNode> syntaxTree = xqueryProcessor.process(new FileInputStream(f));
          if (syntaxTree.size() > 0) {
            assert (syntaxTree.size() == 1);
            ret.add(syntaxTree.get(0));
          } else {
            LOG.error(
                "Error in XQuery file "
                    + f.getAbsolutePath()
                    + ". Try to strip it of empty lines and comments."); // TODO rio Fix weird
                                                                         // parsing errors.
          }
        }
      } catch (final FileNotFoundException e) {
        throw new RuntimeException("File not found: " + f.getAbsolutePath(), e);
      }
    }

    return ret;
  }