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.user;
21
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
24 import org.w3c.dom.Node;
25
26 import base.ICXmlTags;
27 import base.IXMLSaveable;
28
29 public class NAddress implements IXMLSaveable {
30
31 private int id;
32
33 private String city = "";
34
35 private String nation = "";
36
37 private String street = "";
38
39 private String region = "";
40
41 private String postalCode = "";
42
43 private String description = "";
44
45 /***
46 * @param city
47 * The Address'sCity.
48 * @param nation
49 * The Address's Nation.
50 * @param street
51 * The Address's Street.
52 * @param region
53 * The Address's Region.
54 * @param postalCode
55 * The Address's Postal Code.
56 * @param description
57 * The Address's Description.
58 */
59 protected NAddress(int id, String city, String nation, String street,
60 String region, String postalCode, String description) {
61 super();
62
63 this.id = id;
64 this.city = city;
65 this.nation = nation;
66 this.street = street;
67 this.region = region;
68 this.postalCode = postalCode;
69 this.description = description;
70 }
71
72 public NAddress() {
73
74 }
75
76
77
78
79
80
81 @Override
82 public String toString() {
83 return street + ", " + city + ", " + nation + ", " + region + ", "
84 + postalCode;
85 }
86
87 /***
88 * @return Returns the city.
89 */
90 public String getCity() {
91 return city;
92 }
93
94 /***
95 * @param city
96 * The city to set.
97 */
98 public void setCity(String city) {
99 this.city = city;
100 }
101
102 /***
103 * @return Returns the nation.
104 */
105 public String getNation() {
106 return nation;
107 }
108
109 /***
110 * @param nation
111 * The nation to set.
112 */
113 public void setNation(String nation) {
114 this.nation = nation;
115 }
116
117 /***
118 * @return Returns the postalCode.
119 */
120 public String getPostalCode() {
121 return postalCode;
122 }
123
124 /***
125 * @param postalCode
126 * The postalCode to set.
127 */
128 public void setPostalCode(String postalCode) {
129 this.postalCode = postalCode;
130 }
131
132 /***
133 * @return Returns the region.
134 */
135 public String getRegion() {
136 return region;
137 }
138
139 /***
140 * @param region
141 * The region to set.
142 */
143 public void setRegion(String region) {
144 this.region = region;
145 }
146
147 /***
148 * @return Returns the description.
149 */
150 public String getDescription() {
151 return description;
152 }
153
154 /***
155 * @param description
156 * The description to set.
157 */
158 public void setDescription(String description) {
159 this.description = description;
160 }
161
162 /***
163 * @return Returns the street.
164 */
165 public String getStreet() {
166 return street;
167 }
168
169 /***
170 * @param street
171 * The street to set.
172 */
173 public void setStreet(String street) {
174 this.street = street;
175 }
176
177 /***
178 * @return Returns the id.
179 */
180 public int getId() {
181 return id;
182 }
183
184 /***
185 * @param id
186 * The id to set.
187 */
188 protected void setId(int id) {
189 this.id = id;
190 }
191
192 public Node toXml(Document document) {
193 Element nAddressElement = document
194 .createElement(ICXmlTags.IC_NADDRESS_TAG);
195 nAddressElement.setAttribute(ICXmlTags.IC_NADDRESS_ID_ATTRIBUTE, ""
196 + this.id);
197
198 Element cityElement = document
199 .createElement(ICXmlTags.IC_NADDRESS_CITY_TAG);
200 cityElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.city);
201 nAddressElement.appendChild(cityElement);
202
203 Element nationElement = document
204 .createElement(ICXmlTags.IC_NADDRESS_NATION_TAG);
205 nationElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.nation);
206 nAddressElement.appendChild(nationElement);
207
208 Element streetElement = document
209 .createElement(ICXmlTags.IC_NADDRESS_STREET_TAG);
210 streetElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.street);
211 nAddressElement.appendChild(streetElement);
212
213 Element regionElement = document
214 .createElement(ICXmlTags.IC_NADDRESS_REGION_TAG);
215 regionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.region);
216 nAddressElement.appendChild(regionElement);
217
218 Element postalCodeElement = document
219 .createElement(ICXmlTags.IC_NADDRESS_POSTAL_CODE_TAG);
220 postalCodeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
221 this.postalCode);
222 nAddressElement.appendChild(postalCodeElement);
223
224 Element descriptionElement = document
225 .createElement(ICXmlTags.IC_NADDRESS_DESCRIPTION_TAG);
226 descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
227 this.description);
228 nAddressElement.appendChild(descriptionElement);
229
230 return nAddressElement;
231 }
232
233 public NAddress fromXml(Node node) {
234
235 int id = Integer.parseInt(node.getAttributes().getNamedItem(ICXmlTags.IC_NADDRESS_ID_ATTRIBUTE).getNodeValue());
236
237 String city = "";
238 String nation = "";
239 String street = "";
240 String region = "";
241 String postalCode = "";
242 String description = "";
243
244 for(int i=0;i<node.getChildNodes().getLength(); i++){
245 if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_NADDRESS_CITY_TAG))
246 city = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();
247 if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_NADDRESS_NATION_TAG))
248 nation = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();
249 if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_NADDRESS_STREET_TAG))
250 street = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();
251 if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_NADDRESS_REGION_TAG))
252 region = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();
253 if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_NADDRESS_POSTAL_CODE_TAG))
254 postalCode = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();
255 if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_NADDRESS_DESCRIPTION_TAG))
256 description = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();
257
258 }
259
260 return new NAddress(id, city, nation, street,
261 region, postalCode, description);
262 }
263
264 }