KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > Session


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 org.objectweb.jac.aspects.gui.web;
19
20 import java.util.Stack JavaDoc;
21
22 /**
23  * This class defines a session for thin client servers.
24  *
25  * @see Request
26  */

27
28 public class Session implements java.io.Serializable JavaDoc {
29
30    /** The requests stack for this session. */
31    transient protected Stack JavaDoc requests = new Stack JavaDoc();
32
33    /** This session's ID. */
34    protected String JavaDoc sid;
35
36    /**
37     * The constructor for a session with a given ID. */

38  
39    public Session(String JavaDoc sid) {
40       this.sid = sid;
41    }
42
43    /**
44     * Returns the session's ID.
45     *
46     * @return the ID */

47
48    public String JavaDoc getId() {
49       return sid;
50    }
51
52    /**
53     * Returns the stack of the requests for this session.
54     *
55     * <p><code>getRequests().peek()</code> is the request that is
56     * currently treated for this session.
57     *
58     * @return the requests stack */

59
60    public Stack JavaDoc getRequests() {
61       return requests;
62    }
63
64    /**
65     * Returns the number of active requests on the requests stack for
66     * this session.
67     *
68     * @return requests stack count */

69
70    public int getRequestCount() {
71       return requests.size();
72    }
73
74    /**
75     * Creates a new request for this session (pushes it on the
76     * requests stack). The newly created request becomes the current
77     * one of the session.
78     *
79     * @param request the request to push
80     * @see #getCurrentRequest()
81     * @see #endCurrentRequest() */

82
83    public void newRequest(Request request) {
84       getRequests().push(request);
85    }
86
87    /**
88     * Returns the current request of this session (same as
89     * <code>getRequests().peek()</code>).
90     *
91     * @return the current request */

92
93    public Request getCurrentRequest() {
94       return (Request)getRequests().peek();
95    }
96
97    /**
98     * Returns the previous request of this session (ie the one that
99     * was achieved before the current one).
100     *
101     * @return the previous request, null if no previous request is
102     * available */

103
104    public Request getPreviousRequest() {
105       Request prevRequest = null;
106       if (requests.size() > 1) {
107          prevRequest = (Request)requests.get(requests.size()-2);
108       }
109       return prevRequest;
110    }
111
112    /**
113     * Ends the current request (same as
114     * <code>getRequests().pop()</code>).
115     *
116     * @return the request that has just been ended */

117
118    public Request endCurrentRequest() {
119       return (Request)getRequests().pop();
120    }
121
122    /**
123     * Gets a humain-readable string representation of the session.
124     * @return a string */

125
126    public String JavaDoc toString() {
127       return "session " + sid + ", requests stack = " + requests;
128    }
129
130 }
131
Popular Tags