FileDocCategorySizeDatePackage
UserCounter.javaAPI DocExample1413Thu Jul 01 20:34:50 BST 2004com.oreilly.strutsckbk.ch07

UserCounter

public class UserCounter extends Object implements HttpSessionAttributeListener

Fields Summary
Constructors Summary
Methods Summary
private voidadjustUserCounter(javax.servlet.ServletContext ctx, boolean userAdded)

        Integer counterObj = (Integer) ctx.getAttribute("numUsers");
        int counter = (counterObj == null ? 0 : counterObj.intValue());
        if (userAdded) {
          counter++;
        }
        else {
            if (counter > 0) counter--;
        }
        ctx.setAttribute("numUsers", new Integer(counter));
    
public voidattributeAdded(javax.servlet.http.HttpSessionBindingEvent event)

        if (attributeIsUser(event)) 
            adjustUserCounter(event.getSession().getServletContext(), true);
    
private booleanattributeIsUser(javax.servlet.http.HttpSessionBindingEvent event)

        String name = event.getName();
        Object value = event.getValue();
        return "user".equals(name) && 
               value instanceof com.oreilly.strutsckbk.ch07.User;
    
public voidattributeRemoved(javax.servlet.http.HttpSessionBindingEvent event)

        if (attributeIsUser(event)) 
            adjustUserCounter(event.getSession().getServletContext(), false);        
    
public voidattributeReplaced(javax.servlet.http.HttpSessionBindingEvent event)