class SessionHelpers {

  static SessionTracking getTracking(ServletContext servletContext, SessionConfiguration sessionConfiguration) {
    String[] sessionTracking = sessionConfiguration.getSessionTracking();
    try {
      SessionTracking first = null;
      if (sessionTracking == null || sessionTracking.length == 0) {
        first = SessionPropagation.DEFAULT.get();
        first.configure(sessionConfiguration);
      } else {
        SessionTracking prevInstance = null;
        for (String t : sessionTracking) {
          SessionTracking instance = trackingFromEnum(t);
          if (instance == null) {
            instance = (SessionTracking)newInstance(servletContext, t);
          }
          if (first == null) {
            first = instance;
          }
          if (prevInstance != null) {
            prevInstance.nextSessionTracking(instance);
          }
          prevInstance = instance;
          instance.configure(sessionConfiguration);
        }
      }
      return first;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
      throw new IllegalArgumentException("Unable to load or instantiate SessionTracking class " + sessionTracking, e);
    }
  }

}