Exemple #1
0
  public ToolBelt(String configFile) throws FitsConfigurationException {
    XMLConfiguration config = null;
    try {
      config = new XMLConfiguration(configFile);
    } catch (ConfigurationException e) {
      throw new FitsConfigurationException("Error reading " + configFile, e);
    }

    // Collect the tools-used elements
    List<ToolsUsedItem> toolsUsedList = processToolsUsed(config);

    tools = new ArrayList<Tool>();

    // get number of tools
    int size = config.getList("tools.tool[@class]").size();
    // for each tools get the class path and any excluded extensions
    for (int i = 0; i < size; i++) {
      String tClass = config.getString("tools.tool(" + i + ")[@class]");
      @SuppressWarnings("unchecked")
      List<String> excludes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@exclude-exts]");
      @SuppressWarnings("unchecked")
      List<String> includes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@include-exts]");
      Tool t = null;
      try {
        @SuppressWarnings("rawtypes")
        Class c = Class.forName(tClass);
        t = (Tool) c.newInstance();
      } catch (Exception e) {
        // Can't use this tool, but continue anyway.
        // throw new FitsConfigurationException("Error initializing "+tClass,e);
        logger.error(
            "Thread "
                + Thread.currentThread().getId()
                + " error initializing "
                + tClass
                + ": "
                + e.getClass().getName()
                + "  Message: "
                + e.getMessage());
        continue;
      }
      if (t != null) {
        t.setName(bareClassName(tClass));
        for (String ext : excludes) {
          t.addExcludedExtension(ext);
        }
        for (String ext : includes) {
          t.addIncludedExtension(ext);
        }
        // Modify included and excluded extensions by tools-used
        t.applyToolsUsed(toolsUsedList);
        tools.add(t);
      }
    }
  }