class Catalogs {

  @VisibleForTesting
  static Optional<Catalog> loadCatalog(Configuration conf) {
    String catalogLoaderClass = conf.get(InputFormatConfig.CATALOG_LOADER_CLASS);

    if (catalogLoaderClass != null) {
      CatalogLoader loader = (CatalogLoader) DynConstructors.builder(CatalogLoader.class)
              .impl(catalogLoaderClass)
              .build()
              .newInstance();
      return Optional.of(loader.load(conf));
    }

    String catalogName = conf.get(InputFormatConfig.CATALOG);

    if (catalogName != null) {
      switch (catalogName.toLowerCase()) {
        case HADOOP:
          String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION);

          if (warehouseLocation != null) {
            return Optional.of(new HadoopCatalog(conf, warehouseLocation));
          }

          return Optional.of(new HadoopCatalog(conf));
        case HIVE:
          return Optional.of(HiveCatalogs.loadCatalog(conf));
        default:
          throw new NoSuchNamespaceException("Catalog " + catalogName + " is not supported.");
      }
    }

    return Optional.empty();
  }

  private  Catalogs();

}