1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.filters.validator;
24
25 import java.io.Serializable;
26 import java.util.HashMap;
27 import java.util.LinkedList;
28 import java.util.Map;
29
30 import javax.servlet.http.HttpSessionBindingEvent;
31 import javax.servlet.http.HttpSessionBindingListener;
32
33 /**
34 * Object used to store request history.<br>
35 * Part of experimental extended validator filter. Work in progress.
36 *
37 * @author Jose M. Palomar
38 * @version $Revision: 132 $
39 * @todo finish extended validator architecture.
40 */
41 public final class HistorySession implements HttpSessionBindingListener, Serializable {
42
43
44 /**
45 * Requests queue.
46 */
47 private LinkedList requestsQueue;
48
49 /**
50 * Requests map.
51 */
52 private Map requestsMap;
53
54 /**
55 * History size.
56 */
57 private int historySize;
58
59
60 /**
61 * Creates a new <code>HistorySession</code>.
62 *
63 * @param historySize int history size.
64 */
65 public HistorySession(int historySize) {
66 this.historySize = historySize;
67 this.requestsQueue = new LinkedList();
68 this.requestsMap = new HashMap();
69 }
70
71
72 /**
73 * Adds a request to requests history.
74 *
75 * @param request HistoricRequest historic request.
76 */
77 public void add(HistoricRequest request) {
78
79 requestsQueue.addFirst(request);
80 requestsMap.put(request.getTicket(), request);
81
82 if (requestsQueue.size() >= historySize) {
83 HistoricRequest removed = (HistoricRequest) requestsQueue.removeLast();
84 requestsMap.remove(removed.getTicket());
85 }
86
87 }
88
89 /**
90 * Finds a historic request in history.
91 *
92 * @param ticket String request's ticket.
93 * @return HistoricRequest found historic request or <code>null</code>.
94 */
95 public HistoricRequest find(String ticket) {
96 return (HistoricRequest) requestsMap.get(ticket);
97 }
98
99 /**
100 * Notifies the object that it is being bound to a session and identifies the
101 * session. This method do nothing.
102 *
103 * @param httpSessionBindingEvent HttpSessionBindingEvent the event that
104 * identifies the session.
105 * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
106 */
107 public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {
108 }
109
110 /**
111 * Notifies the object that it is being unbound from a session and identifies the
112 * session.
113 *
114 * @param httpSessionBindingEvent HttpSessionBindingEvent the event that
115 * identifies the session.
116 * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
117 */
118 public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
119 }
120
121 }