package com.udapsoft.waf.system.session;

import java.io.Serializable;
import java.util.HashMap;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import kr.co.hsnc.j2ee.waf.controller.web.EventMapping;
import kr.co.hsnc.j2ee.waf.controller.web.util.WebKeys;
import kr.co.hsnc.j2ee.waf.event.Event;


public class SignOnNotifier implements Serializable, HttpSessionAttributeListener {

	private static final long serialVersionUID = -4296859568175624957L;

	public void attributeAdded(HttpSessionBindingEvent se) {
        processEvent(se);
	}

	public void attributeRemoved(HttpSessionBindingEvent se) {
	}
	
	public void attributeReplaced(HttpSessionBindingEvent se) {
        processEvent(se);
	}

    private void processEvent(HttpSessionBindingEvent se) {
        HttpSession session = se.getSession();
        String name = se.getName();
    }

    /**
     * The EventMapping object contains information that will match
     * a event class name to an EJBActionClass.
     * @param context
     * @param eventClass
     * @return
     */
    private EventMapping getEventMapping(ServletContext context, Event eventClass) {
        HashMap eventMappings = (HashMap)context.getAttribute(WebKeys.EVENT_MAPPINGS);
        String eventClassName = eventClass.getClass().getName();
        if( (eventMappings != null) && eventMappings.containsKey(eventClassName) ) {
            return (EventMapping)eventMappings.get(eventClassName);
        }
        else {
            return null;
        }
    }
}
