Line | Hits | Source |
---|---|---|
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.network; | |
21 | ||
22 | import java.net.InetAddress; | |
23 | import java.net.UnknownHostException; | |
24 | ||
25 | import org.w3c.dom.Document; | |
26 | import org.w3c.dom.Element; | |
27 | import org.w3c.dom.Node; | |
28 | ||
29 | import base.ICXmlTags; | |
30 | import base.IXMLSaveable; | |
31 | ||
32 | public class Workstation implements IXMLSaveable { | |
33 | ||
34 | private final int id; | |
35 | ||
36 | 0 | private String name = ""; |
37 | ||
38 | 0 | private String location = ""; |
39 | ||
40 | 0 | private String description = ""; |
41 | ||
42 | 0 | private String type = WorkstationType.WORKSTATION_TYPE[0]; |
43 | ||
44 | private InetAddress address; | |
45 | ||
46 | 0 | private int port = -1; |
47 | ||
48 | 0 | private boolean inUse = false; |
49 | ||
50 | // private final String role; | |
51 | ||
52 | 0 | protected Workstation(final int id) { |
53 | 0 | this.id = id; |
54 | // this.role = role; | |
55 | try { | |
56 | 0 | this.address = InetAddress.getLocalHost(); |
57 | 0 | this.port = 9000; |
58 | 0 | } catch (UnknownHostException e) { |
59 | // TODO Auto-generated catch block | |
60 | 0 | e.printStackTrace(); |
61 | 0 | } |
62 | 0 | } |
63 | ||
64 | 0 | protected Workstation(final int id, String name, String type, |
65 | 0 | String description, InetAddress address, boolean inUse) { |
66 | 0 | this.id = id; |
67 | 0 | this.name = name; |
68 | 0 | this.type = type; |
69 | 0 | this.description = description; |
70 | 0 | this.address = address; |
71 | 0 | this.port = 9000; |
72 | 0 | this.inUse = inUse; |
73 | 0 | } |
74 | ||
75 | 0 | protected Workstation(final int id, String name, String type, |
76 | 0 | String description, InetAddress address, int port, boolean inUse) { |
77 | 0 | this.id = id; |
78 | 0 | this.name = name; |
79 | 0 | this.type = type; |
80 | 0 | this.description = description; |
81 | 0 | this.address = address; |
82 | 0 | this.port = port; |
83 | 0 | this.inUse = inUse; |
84 | 0 | } |
85 | ||
86 | /** | |
87 | * @return Returns the address. | |
88 | */ | |
89 | public InetAddress getAddress() { | |
90 | 0 | return address; |
91 | } | |
92 | ||
93 | /** | |
94 | * @param address | |
95 | * The address to set. | |
96 | */ | |
97 | public void setAddress(InetAddress address) { | |
98 | 0 | this.address = address; |
99 | 0 | } |
100 | ||
101 | /** | |
102 | * @return Returns the description. | |
103 | */ | |
104 | public String getDescription() { | |
105 | 0 | return description; |
106 | } | |
107 | ||
108 | /** | |
109 | * @param description | |
110 | * The description to set. | |
111 | */ | |
112 | public void setDescription(String description) { | |
113 | 0 | this.description = description; |
114 | 0 | } |
115 | ||
116 | /** | |
117 | * @return Returns the inUse. | |
118 | */ | |
119 | public boolean isInUse() { | |
120 | 0 | return inUse; |
121 | } | |
122 | ||
123 | /** | |
124 | * @param inUse | |
125 | * The inUse to set. | |
126 | */ | |
127 | public void setInUse(boolean inUse) { | |
128 | 0 | this.inUse = inUse; |
129 | 0 | } |
130 | ||
131 | /** | |
132 | * @return Returns the name. | |
133 | */ | |
134 | public String getName() { | |
135 | 0 | return name; |
136 | } | |
137 | ||
138 | /** | |
139 | * @param name | |
140 | * The name to set. | |
141 | */ | |
142 | public void setName(String name) { | |
143 | 0 | this.name = name; |
144 | 0 | } |
145 | ||
146 | /** | |
147 | * @return Returns the type. | |
148 | */ | |
149 | public String getType() { | |
150 | 0 | return type; |
151 | } | |
152 | ||
153 | /** | |
154 | * @param type | |
155 | * The type to set. | |
156 | */ | |
157 | public void setType(String type) { | |
158 | 0 | this.type = type; |
159 | 0 | } |
160 | ||
161 | /* | |
162 | * (non-Javadoc) | |
163 | * | |
164 | * @see java.lang.Object#toString() | |
165 | */ | |
166 | @Override | |
167 | public String toString() { | |
168 | 0 | StringBuffer sb = new StringBuffer(); |
169 | 0 | sb.append("WORKSTATION"); |
170 | 0 | sb.append("\n"); |
171 | 0 | sb.append("id: " + id); |
172 | 0 | sb.append("\n"); |
173 | 0 | sb.append("name: " + name); |
174 | 0 | sb.append("\n"); |
175 | 0 | sb.append("description: " + description); |
176 | 0 | sb.append("\n"); |
177 | 0 | sb.append("type: " + type); |
178 | 0 | sb.append("\n"); |
179 | 0 | sb.append("address: " + address); |
180 | 0 | sb.append("\n"); |
181 | 0 | sb.append("port: " + port); |
182 | 0 | sb.append("\n"); |
183 | 0 | sb.append("in use: " + inUse); |
184 | 0 | return sb.toString(); |
185 | } | |
186 | ||
187 | /** | |
188 | * @return Returns the id. | |
189 | */ | |
190 | public int getId() { | |
191 | 0 | return id; |
192 | } | |
193 | ||
194 | /** | |
195 | * @return Returns true if this workstation is a server, false otherwise. | |
196 | */ | |
197 | public boolean isServer() { | |
198 | 0 | return this.id == 0; // Dummy...we can also access the |
199 | // InternetCafeManager | |
200 | } | |
201 | ||
202 | /** | |
203 | * @return Returns the port. | |
204 | */ | |
205 | public int getPort() { | |
206 | 0 | return port; |
207 | } | |
208 | ||
209 | /** | |
210 | * @param port | |
211 | * The port to set. | |
212 | */ | |
213 | public void setPort(int port) { | |
214 | 0 | this.port = port; |
215 | 0 | } |
216 | ||
217 | /** | |
218 | * @return Returns the location. | |
219 | */ | |
220 | public String getLocation() { | |
221 | 0 | return location; |
222 | } | |
223 | ||
224 | /** | |
225 | * @param location | |
226 | * The location to set. | |
227 | */ | |
228 | public void setLocation(String location) { | |
229 | 0 | this.location = location; |
230 | 0 | } |
231 | ||
232 | /* | |
233 | * (non-Javadoc) | |
234 | * | |
235 | * @see test.base.IXMLSaveable#toXml(org.w3c.dom.Document) | |
236 | */ | |
237 | public Node toXml(Document document) { | |
238 | 0 | Element workstationElement = document |
239 | 0 | .createElement(ICXmlTags.IC_WORKSTATION_TAG); |
240 | 0 | workstationElement.setAttribute(ICXmlTags.IC_WORKSTATION_ID_ATTRIBUTE, |
241 | 0 | "" + this.id); |
242 | 0 | workstationElement.setAttribute( |
243 | 0 | ICXmlTags.IC_WORKSTATION_IN_USE_ATTRIBUTE, "" + this.inUse); |
244 | ||
245 | 0 | Element nameElement = document |
246 | 0 | .createElement(ICXmlTags.IC_WORKSTATION_NAME_TAG); |
247 | 0 | nameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.name); |
248 | 0 | workstationElement.appendChild(nameElement); |
249 | ||
250 | 0 | Element typeElement = document |
251 | 0 | .createElement(ICXmlTags.IC_WORKSTATION_TYPE_TAG); |
252 | 0 | typeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.type); |
253 | 0 | workstationElement.appendChild(typeElement); |
254 | // FIXME | |
255 | 0 | workstationElement |
256 | 0 | .appendChild(document |
257 | 0 | .createComment("We must find a way to retrieve the machine's MAC address...")); |
258 | 0 | Element addressElement = document |
259 | 0 | .createElement(ICXmlTags.IC_WORKSTATION_ADDRESS_TAG); |
260 | 0 | addressElement.setAttribute(ICXmlTags.IC_WORKSTATION_ADDRESS_ATTRIBUTE, |
261 | 0 | this.address.getHostAddress()); |
262 | 0 | addressElement.setAttribute(ICXmlTags.IC_WORKSTATION_PORT_ATTRIBUTE, "" |
263 | 0 | + this.port); |
264 | 0 | workstationElement.appendChild(addressElement); |
265 | ||
266 | 0 | Element locationElement = document |
267 | 0 | .createElement(ICXmlTags.IC_WORKSTATION_LOCATION_TAG); |
268 | 0 | locationElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
269 | 0 | this.location); |
270 | 0 | workstationElement.appendChild(locationElement); |
271 | ||
272 | 0 | Element descriptionElement = document |
273 | 0 | .createElement(ICXmlTags.IC_WORKSTATION_DESCRIPTION_TAG); |
274 | 0 | descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
275 | 0 | this.description); |
276 | 0 | workstationElement.appendChild(descriptionElement); |
277 | ||
278 | 0 | return workstationElement; |
279 | } | |
280 | ||
281 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |