class SessionHelpers {

  static SessionConfiguration initConf(final ServletContext context) {
    SessionConfiguration sessionConfiguration = (SessionConfiguration)context.getAttribute(SESSION_CONFIGURATION);
    if (sessionConfiguration == null) {
      sessionConfiguration = new SessionConfiguration();
      context.setAttribute(SESSION_CONFIGURATION, sessionConfiguration);
      WebXmlParser.parseWebXml(sessionConfiguration, context);
      sessionConfiguration.initializeFrom(new SessionConfiguration.AttributeProvider() {
        @Override
        public String getAttribute(String key) {
          return context.getInitParameter(key);
        }

        @Override
        public Object source() {
          return context.getContextPath();
        }
      });
      // If namespace was not available, set namespace to context path of the
      // webapp.
      if (sessionConfiguration.getTrueNamespace() == null) {
        sessionConfiguration.setNamespace(context.getContextPath());
      }
    }
    return sessionConfiguration;
  }

}