1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 package base.session;
21
22 import java.util.Date;
23
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27
28 import base.ICXmlTags;
29 import base.IXMLSaveable;
30 import base.network.Workstation;
31 import base.service.Service;
32 import base.user.User;
33
34 public class Session implements IXMLSaveable {
35
36 private final int id;
37
38 private User user;
39
40 private Workstation workstation;
41
42 private String description;
43
44 private Date startTime;
45
46 private Date endTime = null;
47
48 private Service service;
49
50 /***
51 * @param id
52 * The session's id.
53 * @param user
54 * The session's user.
55 * @param workstation
56 * The session's envolved workstation.
57 * @param description
58 * The session's description.
59 * @param startTime
60 * The session's start time.
61 * @param endTime
62 * The session's end time.
63 */
64 protected Session(final int id, User user, Workstation workstation,
65 String description, Date startTime, Date endTime, Service service) {
66 this.id = id;
67 this.user = user;
68 this.workstation = workstation;
69 this.description = description;
70 this.startTime = startTime;
71 this.endTime = endTime;
72 this.service = service;
73 }
74
75 /***
76 * @return Returns the description.
77 */
78 public String getDescription() {
79 return description;
80 }
81
82 /***
83 * @param description
84 * The description to set.
85 */
86 public void setDescription(String description) {
87 this.description = description;
88 }
89
90 /***
91 * @return Returns the endTime.
92 */
93 public Date getEndTime() {
94 return endTime;
95 }
96
97 /***
98 * @param endTime
99 * The endTime to set.
100 */
101 public void setEndTime(Date endTime) {
102 this.endTime = endTime;
103 }
104
105 /***
106 * @return Returns the startTime.
107 */
108 public Date getStartTime() {
109 return startTime;
110 }
111
112 /***
113 * @param startTime
114 * The startTime to set.
115 */
116 public void setStartTime(Date startTime) {
117 this.startTime = startTime;
118 }
119
120 /***
121 * @return Returns the user.
122 */
123 public User getUser() {
124 return user;
125 }
126
127 /***
128 * @return Returns the workstation.
129 */
130 public Workstation getWorkstation() {
131 return workstation;
132 }
133
134
135
136
137
138
139 @Override
140 public String toString() {
141 StringBuffer sb = new StringBuffer();
142 sb.append("SESSION");
143 sb.append("\n");
144 sb.append("id: " + id);
145 sb.append("\n");
146 sb.append("user: \n" + user);
147 sb.append("\n");
148 sb.append("workstation: \n" + workstation);
149 sb.append("\n");
150 sb.append("description: " + description);
151 sb.append("\n");
152 sb.append("startTime: " + startTime);
153 sb.append("\n");
154 sb.append("endTime: " + endTime);
155 return sb.toString();
156 }
157
158 /***
159 * @return Returns the id.
160 */
161 public int getId() {
162 return id;
163 }
164
165 /***
166 * @return Returns the service.
167 */
168 public Service getService() {
169 return service;
170 }
171
172 /***
173 * This method will be used in future releases and will be used to
174 * estabilish if the user associated to the session has logged out from the
175 * client workstation.
176 *
177 * @return Returns true if the endTime is not null, false otherwise.
178 */
179 public boolean isFinished() {
180 return endTime != null;
181 }
182
183
184
185
186
187
188 public Node toXml(Document document) {
189 Element sessionElement = document
190 .createElement(ICXmlTags.IC_SESSION_TAG);
191 sessionElement.setAttribute(ICXmlTags.IC_SESSION_ID_ATTRIBUTE, ""
192 + this.id);
193 sessionElement.setAttribute(ICXmlTags.IC_SESSION_START_TIME_ATTRIBUTE,
194 this.startTime.toString());
195 sessionElement.setAttribute(ICXmlTags.IC_SESSION_END_TIME_ATTRIBUTE,
196 this.endTime.toString());
197
198 sessionElement.appendChild(this.user.toXml(document));
199 sessionElement.appendChild(this.workstation.toXml(document));
200 sessionElement.appendChild(this.service.toXml(document));
201
202 Element descriptionElement = document
203 .createElement(ICXmlTags.IC_SESSION_DESCRIPTION_TAG);
204 descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
205 this.description);
206 sessionElement.appendChild(descriptionElement);
207
208 return sessionElement;
209 }
210 }