class LogSearchConfigFactory {

  public static LogSearchConfigServer createLogSearchConfigServer(Map<String, String> properties,
      Class<? extends LogSearchConfigServer> defaultClass, boolean init) throws Exception {
    try {
      LogSearchConfigServer logSearchConfig = null;
      String configClassName = properties.get("logsearch.config.server.class");
      if (configClassName != null && !"".equals(configClassName.trim())) {
        Class<?> clazz = Class.forName(configClassName);
        if (LogSearchConfigServer.class.isAssignableFrom(clazz)) {
          logSearchConfig = (LogSearchConfigServer) clazz.newInstance();
        } else {
          throw new IllegalArgumentException("Class " + configClassName + " does not implement the interface " +
              LogSearchConfigServer.class.getName());
        }
      } else {
        logSearchConfig = defaultClass.newInstance();
      }
      if (init) {
        logSearchConfig.init(properties);
      }
      return logSearchConfig;
    } catch (Exception e) {
      LOG.error("Could not initialize logsearch config.", e);
      throw e;
    }
  }

}