package wenrgise.ejb.common.utility;

import java.rmi.RemoteException;
import java.util.logging.Logger;
import javax.ejb.RemoveException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;
import wenrgise.ejb.common.session.UserSession;

public class EnrgiseSessionListener implements HttpSessionActivationListener {
  static final Logger log = Logger.getLogger("wenrgise.common.Utility.EnrgiseSessionListener");
  
  public void sessionDidActivate(HttpSessionEvent sessionEvent) {}
  
  public void sessionWillPassivate(HttpSessionEvent sessionEvent) {
    try {
      HttpSession oS = sessionEvent.getSession();
      UserSession oUser = (UserSession)oS.getAttribute(ParamUtil.getSessionBeanName());
      if (oUser != null)
        oUser.remove(); 
    } catch (RemoteException oExc) {
      log.severe(String.valueOf("The reason ").concat(String.valueOf(oExc.getMessage())));
    } catch (RemoveException oEx) {
      log.severe(String.valueOf("The reason ").concat(String.valueOf(oEx.getMessage())));
    } 
  }
}
