class SessionHelpers {

  static SessionRepository repository(ServletContext servletContext, SessionConfiguration conf) {
    String repositoryFactoryId = conf.getRepositoryFactory();
    if (repositoryFactoryId == null) {
      repositoryFactoryId = DEFAULT_REPOSITORY_FACTORY;
    }
    @SuppressWarnings("unchecked")
    Map<String, String> providers = (Map<String, String>)servletContext.getAttribute(Attributes.PROVIDERS);
    String repositoryFactory;
    if (providers != null && providers.containsKey(repositoryFactoryId)) {
      repositoryFactory = providers.get(repositoryFactoryId);
    } else {
      repositoryFactory = repositoryFactoryId;
    }
    try {
      return repositoryOrDefault(repositoryFactory, servletContext, conf);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
      throw new IllegalArgumentException("Unable to load or instantiate SessionRepositoryFactory. Id="
          + repositoryFactoryId + ", Implementation=" + repositoryFactory, e);
    }
  }

}