/**
  * This method is invoked when an attribute is replaced in the ServletContext object
  *
  * @param event Description of the Parameter
  */
 public void attributeReplaced(HttpSessionBindingEvent event) {
   // This event has a handle to the old User object
   ServletContext context = event.getSession().getServletContext();
   // The user has logged in
   if ("User".equals(event.getName())) {
     UserBean thisUser = (UserBean) event.getValue();
     thisUser.setSessionId(event.getSession().getId());
     Tracker tracker =
         ((SystemStatus)
                 ((Hashtable) context.getAttribute("SystemStatus"))
                     .get(thisUser.getConnectionElement().getUrl()))
             .getTracker();
     tracker.remove(event.getSession().getId());
     tracker.add(thisUser.getSessionId(), thisUser);
   }
 }
 /**
  * This method is invoked when an attribute is removed from the ServletContext object
  *
  * @param se Description of the Parameter
  */
 public void attributeRemoved(HttpSessionBindingEvent se) {
   ServletContext context = se.getSession().getServletContext();
   try {
     if (se.getName().equals("User")) {
       UserBean thisUser = (UserBean) se.getValue();
       if (thisUser != null) {
         // Internal SessionManager
         int userId = thisUser.getActualUserId();
         if (userId > -2) {
           // If context reloaded, then SystemStatus is null, but user is valid
           Hashtable systems = (Hashtable) context.getAttribute("SystemStatus");
           if (systems != null) {
             SystemStatus systemStatus =
                 (SystemStatus) systems.get(thisUser.getConnectionElement().getUrl());
             if (systemStatus != null) {
               // Remove the user from the session if it already is there
               SessionManager thisManager = systemStatus.getSessionManager();
               if (thisManager != null) {
                 UserSession thisSession = thisManager.getUserSession(userId);
                 if (thisSession != null && thisSession.getId().equals(thisUser.getSessionId())) {
                   if (System.getProperty("DEBUG") != null) {
                     System.out.println(
                         "ContextSessionListener-> Session for user " + userId + " ended");
                   }
                   thisManager.removeUser(userId);
                   if (System.getProperty("DEBUG") != null) {
                     System.out.println(
                         "ContextSessionListener-> User removed from valid user list");
                   }
                 }
               }
               // Website Tracker
               Tracker tracker = systemStatus.getTracker();
               tracker.remove(thisUser.getSessionId());
             }
           }
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace(System.out);
     System.out.println("ContextSessionListener-> attributeRemoved Error: " + e.toString());
   }
 }