Source code: jac/aspects/gui/web/Session.java
1 /*
2 Copyright (C) 2001-2002 Renaud Pawlak <renaud@aopsys.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 package jac.aspects.gui.web;
19
20 import java.util.Stack;
21 import jac.util.Log;
22
23 /**
24 * This class defines a session for thin client servers.
25 *
26 * @see Request
27 */
28
29 public class Session implements java.io.Serializable {
30
31 /** The requests stack for this session. */
32 transient protected Stack requests = new Stack();
33
34 /** This session's ID. */
35 protected String sid;
36
37 /**
38 * The constructor for a session with a given ID. */
39
40 public Session(String sid) {
41 this.sid = sid;
42 }
43
44 /**
45 * Returns the session's ID.
46 *
47 * @return the ID */
48
49 public String getId() {
50 return sid;
51 }
52
53 /**
54 * Returns the stack of the requests for this session.
55 *
56 * <p><code>getRequests().peek()</code> is the request that is
57 * currently treated for this session.
58 *
59 * @return the requests stack */
60
61 public Stack getRequests() {
62 return requests;
63 }
64
65 /**
66 * Returns the number of active requests on the requests stack for
67 * this session.
68 *
69 * @return requests stack count */
70
71 public int getRequestCount() {
72 return requests.size();
73 }
74
75 /**
76 * Creates a new request for this session (pushes it on the
77 * requests stack). The newly created request becomes the current
78 * one of the session.
79 *
80 * @param request the request to push
81 * @see #getCurrentRequest()
82 * @see #endCurrentRequest() */
83
84 public void newRequest(Request request) {
85 getRequests().push(request);
86 }
87
88 /**
89 * Returns the current request of this session (same as
90 * <code>getRequests().peek()</code>).
91 *
92 * @return the current request */
93
94 public Request getCurrentRequest() {
95 return (Request)getRequests().peek();
96 }
97
98 /**
99 * Returns the previous request of this session (ie the one that
100 * was achieved before the current one).
101 *
102 * @return the previous request, null if no previous request is
103 * available */
104
105 public Request getPreviousRequest() {
106 Request prevRequest = null;
107 if (requests.size() > 1) {
108 prevRequest = (Request)requests.get(requests.size()-2);
109 }
110 return prevRequest;
111 }
112
113 /**
114 * Ends the current request (same as
115 * <code>getRequests().pop()</code>).
116 *
117 * @return the request that has just been ended */
118
119 public Request endCurrentRequest() {
120 return (Request)getRequests().pop();
121 }
122
123 /**
124 * Gets a humain-readable string representation of the session.
125 * @return a string */
126
127 public String toString() {
128 return "session " + sid + ", requests stack = " + requests;
129 }
130
131 }