KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > AgentUnregisterHook


1 /**
2  *
3  */

4 package com.sslexplorer.agent;
5
6 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
7 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import com.sslexplorer.security.SessionInfo;
13
14 public class AgentUnregisterHook implements HttpSessionBindingListener JavaDoc {
15
16     final static String JavaDoc AGENT_UNREGISTER_HOOK = "agentUnregister";
17
18     final static Log log = LogFactory.getLog(AgentUnregisterHook.class);
19
20     private SessionInfo session;
21
22     private AgentUnregisterHook(SessionInfo session) {
23         this.session = session;
24         if (session.getHttpSession().getAttribute(AGENT_UNREGISTER_HOOK) != null) {
25             throw new IllegalStateException JavaDoc(
26                     "May only be one agent unregister hook in any session.");
27         }
28         session.getHttpSession().setAttribute(AGENT_UNREGISTER_HOOK, this);
29     }
30
31     public void valueBound(HttpSessionBindingEvent JavaDoc event) {
32         if (log.isInfoEnabled())
33             log.info("New session agent hook.");
34     }
35
36     public void valueUnbound(HttpSessionBindingEvent JavaDoc event) {
37         if (log.isInfoEnabled())
38             log.info("Session invalidate. Deregistering agent");
39         DefaultAgentManager.getInstance().unregisterAgent(session);
40     }
41
42     public static void register(SessionInfo session) {
43         if(session.getHttpSession() != null && session.getHttpSession().getAttribute(AGENT_UNREGISTER_HOOK) == null) {
44             new AgentUnregisterHook(session);
45         }
46     }
47
48 }
Popular Tags