| 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.user; | |
| 21 | ||
| 22 | import java.io.UnsupportedEncodingException; | |
| 23 | import java.security.MessageDigest; | |
| 24 | import java.security.NoSuchAlgorithmException; | |
| 25 | import java.util.Date; | |
| 26 | import java.util.HashSet; | |
| 27 | import java.util.Iterator; | |
| 28 | import java.util.Observable; | |
| 29 | ||
| 30 | import org.apache.log4j.Logger; | |
| 31 | import org.w3c.dom.Document; | |
| 32 | import org.w3c.dom.Element; | |
| 33 | import org.w3c.dom.Node; | |
| 34 | ||
| 35 | import base.ICXmlTags; | |
| 36 | import base.IXMLLoadable; | |
| 37 | import base.IXMLSaveable; | |
| 38 | ||
| 39 | 0 | public class User extends Observable implements IXMLSaveable, IXMLLoadable { |
| 40 | ||
| 41 | 0 | private static final transient Logger logger = Logger.getLogger(User.class |
| 42 | 0 | .getName()); |
| 43 | ||
| 44 | private int id; | |
| 45 | ||
| 46 | 0 | private String name = ""; |
| 47 | ||
| 48 | 0 | private String surname = ""; |
| 49 | ||
| 50 | 0 | private base.user.Document document = new base.user.Document();; |
| 51 | ||
| 52 | 0 | private String imagePath = null; |
| 53 | ||
| 54 | 0 | private String credential = UserCredential.USER_CREDENTIAL[0]; |
| 55 | ||
| 56 | 0 | private String nickname = ""; |
| 57 | ||
| 58 | 0 | private String password = ""; |
| 59 | ||
| 60 | 0 | private Date birthday = new Date(); |
| 61 | ||
| 62 | 0 | public Date creationDate = new Date(); |
| 63 | ||
| 64 | 0 | private String gender = UserGender.USER_GENDER[0]; |
| 65 | ||
| 66 | 0 | private HashSet<NAddress> nAddress = new HashSet<NAddress>(); |
| 67 | ||
| 68 | 0 | private HashSet<EAddress> eAddress = new HashSet<EAddress>(); |
| 69 | ||
| 70 | 0 | private HashSet<PhoneNumber> phoneNumber = new HashSet<PhoneNumber>(); |
| 71 | ||
| 72 | 0 | private int currentNAddressId = 0; |
| 73 | ||
| 74 | 0 | private int currentEAddressId = 0; |
| 75 | ||
| 76 | 0 | private int currentPhoneNumberId = 0; |
| 77 | ||
| 78 | /** | |
| 79 | * @param id | |
| 80 | * The user's id. | |
| 81 | * @param name | |
| 82 | * The user's name. | |
| 83 | * @param surname | |
| 84 | * The user's surname. | |
| 85 | * @param gender | |
| 86 | * The user's gender. | |
| 87 | * @param birthday | |
| 88 | * The user's birthday. | |
| 89 | * @param nickname | |
| 90 | * The user's nickname. | |
| 91 | * @param password | |
| 92 | * The user's password. | |
| 93 | * @param credential | |
| 94 | * The user's id. | |
| 95 | * @param document | |
| 96 | * The user's document. | |
| 97 | */ | |
| 98 | 0 | protected User(final int id, String name, String surname, String gender, |
| 99 | Date birthday, String nickname, String password, String credential, | |
| 100 | 0 | base.user.Document document) { |
| 101 | 0 | this.id = id; |
| 102 | 0 | this.name = name; |
| 103 | 0 | this.surname = surname; |
| 104 | 0 | this.gender = gender; |
| 105 | 0 | this.birthday = birthday; |
| 106 | 0 | this.nickname = nickname; |
| 107 | 0 | this.password = password; |
| 108 | 0 | this.credential = credential; |
| 109 | 0 | this.document = document; |
| 110 | 0 | this.currentNAddressId = retrieveMaxNAddressId(); |
| 111 | 0 | this.currentEAddressId = retrieveMaxEAddressId(); |
| 112 | 0 | this.currentPhoneNumberId = retrieveMaxPhoneNumberId(); |
| 113 | 0 | } |
| 114 | ||
| 115 | 0 | protected User(int id) { |
| 116 | 0 | this.id = id; |
| 117 | // TODO Auto-generated constructor stub | |
| 118 | 0 | } |
| 119 | ||
| 120 | /** | |
| 121 | * @return Returns the imagePath. | |
| 122 | */ | |
| 123 | public String getImagePath() { | |
| 124 | 0 | return imagePath; |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * @param imagePath | |
| 129 | * The imagePath to set. | |
| 130 | */ | |
| 131 | public void setImagePath(String imagePath) { | |
| 132 | 0 | this.imagePath = imagePath; |
| 133 | 0 | } |
| 134 | ||
| 135 | /** | |
| 136 | * @return Returns the password. | |
| 137 | */ | |
| 138 | public String getPassword() { | |
| 139 | 0 | return password; |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * @param password | |
| 144 | * The password to set. | |
| 145 | */ | |
| 146 | public void setPassword(String password) { | |
| 147 | 0 | if (!this.getPassword().equals(password)) { |
| 148 | // Assuming that password is modified, we must rebuild it. | |
| 149 | 0 | this.password = buildUserPassword(password); |
| 150 | 0 | } else |
| 151 | 0 | this.password = password; |
| 152 | 0 | } |
| 153 | ||
| 154 | /** | |
| 155 | * @param birthday | |
| 156 | * The birthday to set. | |
| 157 | */ | |
| 158 | public void setBirthday(Date birthday) { | |
| 159 | 0 | this.birthday = birthday; |
| 160 | 0 | } |
| 161 | ||
| 162 | /** | |
| 163 | * @param credential | |
| 164 | * The credential to set. | |
| 165 | */ | |
| 166 | public void setCredential(String credential) { | |
| 167 | 0 | this.credential = credential; |
| 168 | 0 | } |
| 169 | ||
| 170 | /** | |
| 171 | * @param document | |
| 172 | * The document to set. | |
| 173 | */ | |
| 174 | public void setDocument(base.user.Document document) { | |
| 175 | 0 | this.document = document; |
| 176 | 0 | } |
| 177 | ||
| 178 | /** | |
| 179 | * @param name | |
| 180 | * The name to set. | |
| 181 | */ | |
| 182 | public void setName(String name) { | |
| 183 | 0 | this.name = name; |
| 184 | 0 | } |
| 185 | ||
| 186 | /** | |
| 187 | * @param nickname | |
| 188 | * The nickname to set. | |
| 189 | */ | |
| 190 | public void setNickname(String nickname) { | |
| 191 | 0 | this.nickname = nickname; |
| 192 | 0 | } |
| 193 | ||
| 194 | /** | |
| 195 | * @param surname | |
| 196 | * The surname to set. | |
| 197 | */ | |
| 198 | public void setSurname(String surname) { | |
| 199 | 0 | this.surname = surname; |
| 200 | 0 | } |
| 201 | ||
| 202 | /** | |
| 203 | * @return Returns the document. | |
| 204 | */ | |
| 205 | public base.user.Document getDocument() { | |
| 206 | 0 | return document; |
| 207 | } | |
| 208 | ||
| 209 | /** | |
| 210 | * @return Returns the name. | |
| 211 | */ | |
| 212 | public String getName() { | |
| 213 | 0 | return name; |
| 214 | } | |
| 215 | ||
| 216 | /** | |
| 217 | * @return Returns the nickname. | |
| 218 | */ | |
| 219 | public String getNickname() { | |
| 220 | 0 | return nickname; |
| 221 | } | |
| 222 | ||
| 223 | /** | |
| 224 | * @return Returns the surname. | |
| 225 | */ | |
| 226 | public String getSurname() { | |
| 227 | 0 | return surname; |
| 228 | } | |
| 229 | ||
| 230 | /** | |
| 231 | * @return Returns the credential. | |
| 232 | */ | |
| 233 | public String getCredential() { | |
| 234 | 0 | return credential; |
| 235 | } | |
| 236 | ||
| 237 | /* | |
| 238 | * (non-Javadoc) | |
| 239 | * | |
| 240 | * @see java.lang.Object#toString() | |
| 241 | */ | |
| 242 | @Override | |
| 243 | public String toString() { | |
| 244 | 0 | StringBuffer sb = new StringBuffer(); |
| 245 | 0 | sb.append("USER"); |
| 246 | 0 | sb.append("\n"); |
| 247 | 0 | sb.append("id: " + id); |
| 248 | 0 | sb.append("\n"); |
| 249 | 0 | sb.append("name: " + name); |
| 250 | 0 | sb.append("\n"); |
| 251 | 0 | sb.append("surname: " + surname); |
| 252 | 0 | sb.append("\n"); |
| 253 | 0 | sb.append("gender: " + gender); |
| 254 | 0 | sb.append("\n"); |
| 255 | 0 | sb.append("birthday: " + birthday); |
| 256 | 0 | sb.append("\n"); |
| 257 | 0 | sb.append("document: \n" + document); |
| 258 | 0 | sb.append("\n"); |
| 259 | 0 | sb.append("nAddress: \n"); |
| 260 | ||
| 261 | 0 | Iterator iterator = nAddress.iterator(); |
| 262 | 0 | while (iterator.hasNext()) |
| 263 | 0 | sb.append(iterator.next() + "\n"); |
| 264 | 0 | sb.append("eAddress: \n"); |
| 265 | ||
| 266 | 0 | iterator = eAddress.iterator(); |
| 267 | 0 | while (iterator.hasNext()) |
| 268 | 0 | sb.append(iterator.next() + "\n"); |
| 269 | 0 | sb.append("phoneNumber: \n"); |
| 270 | ||
| 271 | 0 | iterator = phoneNumber.iterator(); |
| 272 | 0 | while (iterator.hasNext()) |
| 273 | 0 | sb.append(iterator.next() + "\n"); |
| 274 | ||
| 275 | 0 | sb.append("image: " + imagePath); |
| 276 | 0 | sb.append("\n"); |
| 277 | 0 | sb.append("credential: " + credential); |
| 278 | 0 | sb.append("\n"); |
| 279 | 0 | sb.append("nickname: " + nickname); |
| 280 | 0 | sb.append("\n"); |
| 281 | 0 | sb.append("password: " + password); |
| 282 | 0 | return sb.toString(); |
| 283 | } | |
| 284 | ||
| 285 | /** | |
| 286 | * @return Returns the birthday. | |
| 287 | */ | |
| 288 | public Date getBirthday() { | |
| 289 | 0 | return birthday; |
| 290 | } | |
| 291 | ||
| 292 | /** | |
| 293 | * @return Returns the id. | |
| 294 | */ | |
| 295 | public int getId() { | |
| 296 | 0 | return id; |
| 297 | } | |
| 298 | ||
| 299 | /** | |
| 300 | * @return Returns the gender. | |
| 301 | */ | |
| 302 | public String getGender() { | |
| 303 | 0 | return gender; |
| 304 | } | |
| 305 | ||
| 306 | /** | |
| 307 | * @param gender | |
| 308 | * The gender to set. | |
| 309 | */ | |
| 310 | public void setGender(String gender) { | |
| 311 | 0 | this.gender = gender; |
| 312 | 0 | } |
| 313 | ||
| 314 | /** | |
| 315 | * @return Returns the creationDate. | |
| 316 | */ | |
| 317 | public Date getCreationDate() { | |
| 318 | 0 | return creationDate; |
| 319 | } | |
| 320 | ||
| 321 | /** | |
| 322 | * @param password | |
| 323 | * The User's password. | |
| 324 | * @return Returns an MD5 digest of the user's password. | |
| 325 | */ | |
| 326 | public static String buildUserPassword(String password) { | |
| 327 | 0 | String result = ""; |
| 328 | MessageDigest md; | |
| 329 | try { | |
| 330 | 0 | md = MessageDigest.getInstance("MD5"); |
| 331 | 0 | md.update(password.getBytes("UTF8")); |
| 332 | 0 | byte[] hash = md.digest(); |
| 333 | 0 | for (int i = 0; i < hash.length; i++) { |
| 334 | 0 | int hexValue = hash[i] & 0xFF; |
| 335 | 0 | if (hexValue < 16) { |
| 336 | 0 | result = result + "0"; |
| 337 | } | |
| 338 | 0 | result = result + Integer.toString(hexValue, 16); |
| 339 | } | |
| 340 | 0 | logger.debug("Users'password MD5 Digest: " + result); |
| 341 | 0 | } catch (NoSuchAlgorithmException ex) { |
| 342 | // TODO Auto-generated catch block | |
| 343 | 0 | logger.error(ex.getMessage()); |
| 344 | 0 | ex.printStackTrace(); |
| 345 | 0 | } catch (UnsupportedEncodingException ex) { |
| 346 | 0 | logger.error(ex.getMessage()); |
| 347 | 0 | ex.printStackTrace(); |
| 348 | 0 | } |
| 349 | 0 | return result; |
| 350 | } | |
| 351 | ||
| 352 | /** | |
| 353 | * @return Returns the eAddress. | |
| 354 | */ | |
| 355 | public EAddress[] getEAddress() { | |
| 356 | 0 | if (eAddress == null) { |
| 357 | 0 | eAddress = new HashSet<EAddress>(); |
| 358 | } | |
| 359 | 0 | return eAddress.toArray(new EAddress[0]); |
| 360 | } | |
| 361 | ||
| 362 | /** | |
| 363 | * @return Returns the nAddress. | |
| 364 | */ | |
| 365 | public NAddress[] getNAddress() { | |
| 366 | 0 | if (nAddress == null) { |
| 367 | 0 | nAddress = new HashSet<NAddress>(); |
| 368 | } | |
| 369 | 0 | return nAddress.toArray(new NAddress[0]); |
| 370 | } | |
| 371 | ||
| 372 | /** | |
| 373 | * @return Returns the phoneNumber. | |
| 374 | */ | |
| 375 | public PhoneNumber[] getPhoneNumber() { | |
| 376 | 0 | if (phoneNumber == null) { |
| 377 | 0 | phoneNumber = new HashSet<PhoneNumber>(); |
| 378 | } | |
| 379 | 0 | return phoneNumber.toArray(new PhoneNumber[0]); |
| 380 | } | |
| 381 | ||
| 382 | public void addEAddress(EAddress eAddress) { | |
| 383 | 0 | eAddress.setId(getNextEAddressId()); |
| 384 | 0 | this.eAddress.add(eAddress); |
| 385 | 0 | } |
| 386 | ||
| 387 | public void addNAddress(NAddress nAddress) { | |
| 388 | 0 | nAddress.setId(getNextNAddressId()); |
| 389 | 0 | this.nAddress.add(nAddress); |
| 390 | 0 | } |
| 391 | ||
| 392 | public void addPhoneNumber(PhoneNumber phoneNumber) { | |
| 393 | 0 | phoneNumber.setId(getNextPhoneNumberId()); |
| 394 | 0 | this.phoneNumber.add(phoneNumber); |
| 395 | 0 | } |
| 396 | ||
| 397 | private int getNextNAddressId() { | |
| 398 | 0 | return ++currentNAddressId; |
| 399 | } | |
| 400 | ||
| 401 | private int getNextEAddressId() { | |
| 402 | 0 | return ++currentEAddressId; |
| 403 | } | |
| 404 | ||
| 405 | private int getNextPhoneNumberId() { | |
| 406 | 0 | return ++currentPhoneNumberId; |
| 407 | } | |
| 408 | ||
| 409 | private int retrieveMaxNAddressId() { | |
| 410 | 0 | int max = -1; // This is an invalid value... |
| 411 | 0 | NAddress[] address = getNAddress(); |
| 412 | 0 | for (int i = 0; i < address.length; i++) |
| 413 | 0 | if (address[i].getId() > max) |
| 414 | 0 | max = address[i].getId(); |
| 415 | 0 | return max; |
| 416 | } | |
| 417 | ||
| 418 | private int retrieveMaxEAddressId() { | |
| 419 | 0 | int max = -1; // This is an invalid value... |
| 420 | 0 | EAddress[] address = getEAddress(); |
| 421 | 0 | for (int i = 0; i < address.length; i++) |
| 422 | 0 | if (address[i].getId() > max) |
| 423 | 0 | max = address[i].getId(); |
| 424 | 0 | return max; |
| 425 | } | |
| 426 | ||
| 427 | private int retrieveMaxPhoneNumberId() { | |
| 428 | 0 | int max = -1; // This is an invalid value... |
| 429 | 0 | PhoneNumber[] phoneNumber = getPhoneNumber(); |
| 430 | 0 | for (int i = 0; i < phoneNumber.length; i++) |
| 431 | 0 | if (phoneNumber[i].getId() > max) |
| 432 | 0 | max = phoneNumber[i].getId(); |
| 433 | 0 | return max; |
| 434 | } | |
| 435 | ||
| 436 | public NAddress newNAddress(String city, String nation, String street, | |
| 437 | String region, String postalCode, String description) { | |
| 438 | 0 | return new NAddress(0, city, nation, street, region, postalCode, |
| 439 | 0 | description); |
| 440 | } | |
| 441 | ||
| 442 | public EAddress newEAddress(String eAddress) { | |
| 443 | 0 | return new EAddress(0, eAddress); |
| 444 | } | |
| 445 | ||
| 446 | public PhoneNumber newPhoneNumber(String areaCode, String exchange, | |
| 447 | String number, String description) { | |
| 448 | 0 | return new PhoneNumber(0, areaCode, exchange, number, description); |
| 449 | } | |
| 450 | ||
| 451 | /** | |
| 452 | * @param addressId | |
| 453 | * The id associated to the NAddress | |
| 454 | * @return The NAddress whose id is addressId, null if such nAddressId is | |
| 455 | * not contained in the user's nAddress set. | |
| 456 | * | |
| 457 | */ | |
| 458 | public NAddress getNAddressById(int addressId) { | |
| 459 | 0 | NAddress[] address = getNAddress(); |
| 460 | 0 | for (int i = 0; i < address.length; i++) |
| 461 | 0 | if (address[i].getId() == addressId) |
| 462 | 0 | return address[i]; |
| 463 | 0 | return null; |
| 464 | } | |
| 465 | ||
| 466 | /** | |
| 467 | * @param addressId | |
| 468 | * The id associated to an EAddress. | |
| 469 | * @return The EAddress whose id is addressId, null if such eAddressId is | |
| 470 | * not contained in the user's eAddress set. | |
| 471 | */ | |
| 472 | public EAddress getEAddressById(int addressId) { | |
| 473 | 0 | EAddress[] address = getEAddress(); |
| 474 | 0 | for (int i = 0; i < address.length; i++) |
| 475 | 0 | if (address[i].getId() == addressId) |
| 476 | 0 | return address[i]; |
| 477 | 0 | return null; |
| 478 | } | |
| 479 | ||
| 480 | /** | |
| 481 | * @param phoneNumberId | |
| 482 | * The id associated to a PhoneNumber. | |
| 483 | * @return The PhoneNumber whose id is phoneNumberId, null if such | |
| 484 | * phoneNumberId is not contained in the user's phoneNumber set. | |
| 485 | */ | |
| 486 | public PhoneNumber getPhoneNumberById(int phoneNumberId) { | |
| 487 | 0 | PhoneNumber[] phoneNumber = getPhoneNumber(); |
| 488 | 0 | for (int i = 0; i < phoneNumber.length; i++) |
| 489 | 0 | if (phoneNumber[i].getId() == phoneNumberId) |
| 490 | 0 | return phoneNumber[i]; |
| 491 | 0 | return null; |
| 492 | } | |
| 493 | ||
| 494 | /** | |
| 495 | * @param nAddress | |
| 496 | * Deletes the nAddress form the user's nAddress set. | |
| 497 | */ | |
| 498 | public void deleteNAddress(NAddress nAddress) { | |
| 499 | 0 | this.nAddress.remove(nAddress); |
| 500 | 0 | } |
| 501 | ||
| 502 | /** | |
| 503 | * @param eAddress | |
| 504 | * Deletes the eAddress from the user's eAddress set. | |
| 505 | */ | |
| 506 | public void deleteEAddress(EAddress eAddress) { | |
| 507 | 0 | this.eAddress.remove(eAddress); |
| 508 | ||
| 509 | 0 | } |
| 510 | ||
| 511 | /** | |
| 512 | * @param phoneNumber | |
| 513 | * Deletes the phoneNumber from the user's phoneNumber set. | |
| 514 | */ | |
| 515 | public void deletePhoneNumber(PhoneNumber phoneNumber) { | |
| 516 | 0 | this.phoneNumber.remove(phoneNumber); |
| 517 | ||
| 518 | 0 | } |
| 519 | ||
| 520 | public Node toXml(Document document) { | |
| 521 | 0 | Element userElement = document.createElement(ICXmlTags.IC_USER_TAG); |
| 522 | 0 | userElement.setAttribute(ICXmlTags.IC_USER_ID_ATTRIBUTE, "" + this.id); |
| 523 | 0 | userElement.setAttribute( |
| 524 | 0 | ICXmlTags.IC_USER_CURRENT_NADDRESS_ID_ATTRIBUTE, "" |
| 525 | 0 | + this.currentNAddressId); |
| 526 | 0 | userElement.setAttribute( |
| 527 | 0 | ICXmlTags.IC_USER_CURRENT_EADDRESS_ID_ATTRIBUTE, "" |
| 528 | 0 | + this.currentEAddressId); |
| 529 | 0 | userElement.setAttribute( |
| 530 | 0 | ICXmlTags.IC_USER_CURRENT_PHONE_NUMBER_ID_ATTRIBUTE, "" |
| 531 | 0 | + this.currentPhoneNumberId); |
| 532 | ||
| 533 | 0 | Element nameElement = document |
| 534 | 0 | .createElement(ICXmlTags.IC_USER_NAME_TAG); |
| 535 | 0 | nameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.name); |
| 536 | 0 | userElement.appendChild(nameElement); |
| 537 | ||
| 538 | 0 | Element surnameElement = document |
| 539 | 0 | .createElement(ICXmlTags.IC_USER_SURNAME_TAG); |
| 540 | 0 | surnameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.surname); |
| 541 | 0 | userElement.appendChild(surnameElement); |
| 542 | ||
| 543 | 0 | Element genderElement = document |
| 544 | 0 | .createElement(ICXmlTags.IC_USER_GENDER_TAG); |
| 545 | 0 | genderElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.gender); |
| 546 | 0 | userElement.appendChild(genderElement); |
| 547 | ||
| 548 | 0 | Element credentialElement = document |
| 549 | 0 | .createElement(ICXmlTags.IC_USER_CREDENTIAL_TAG); |
| 550 | 0 | credentialElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 551 | 0 | this.credential); |
| 552 | 0 | userElement.appendChild(credentialElement); |
| 553 | ||
| 554 | 0 | Element nicknameElement = document |
| 555 | 0 | .createElement(ICXmlTags.IC_USER_NICKNAME_TAG); |
| 556 | 0 | nicknameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 557 | 0 | this.nickname); |
| 558 | 0 | userElement.appendChild(nicknameElement); |
| 559 | ||
| 560 | 0 | Element passwordElement = document |
| 561 | 0 | .createElement(ICXmlTags.IC_USER_PASSWORD_TAG); |
| 562 | 0 | passwordElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 563 | 0 | this.password); |
| 564 | 0 | userElement.appendChild(passwordElement); |
| 565 | 0 | |
| 566 | 0 | Element imagePathElement = document |
| 567 | 0 | .createElement(ICXmlTags.IC_USER_IMAGE_PATH_TAG); |
| 568 | 0 | imagePathElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 569 | 0 | this.imagePath); |
| 570 | 0 | userElement.appendChild(imagePathElement); |
| 571 | 0 | |
| 572 | 0 | Element birthdayElement = document |
| 573 | 0 | .createElement(ICXmlTags.IC_USER_BIRTHDAY_TAG); |
| 574 | 0 | birthdayElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 575 | 0 | this.birthday.toString()); |
| 576 | 0 | birthdayElement.setAttribute(ICXmlTags.IC_LONG_VALUE_ATTRIBUTE, "" |
| 577 | 0 | + this.birthday.getTime()); |
| 578 | 0 | userElement.appendChild(birthdayElement); |
| 579 | 0 | |
| 580 | 0 | Element creationDateElement = document |
| 581 | 0 | .createElement(ICXmlTags.IC_USER_CREATION_DATE_TAG); |
| 582 | 0 | creationDateElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 583 | 0 | this.creationDate.toString()); |
| 584 | 0 | creationDateElement.setAttribute(ICXmlTags.IC_LONG_VALUE_ATTRIBUTE, "" |
| 585 | 0 | + this.creationDate.getTime()); |
| 586 | ||
| 587 | 0 | userElement.appendChild(creationDateElement); |
| 588 | 0 | |
| 589 | 0 | userElement.appendChild(this.document.toXml(document)); |
| 590 | 0 | |
| 591 | 0 | Element nAddressElement = document |
| 592 | 0 | .createElement(ICXmlTags.IC_USER_NADDRESS_LIST_TAG); |
| 593 | 0 | Iterator iterator = this.nAddress.iterator(); |
| 594 | 0 | while (iterator.hasNext()) |
| 595 | 0 | nAddressElement.appendChild(((IXMLSaveable) iterator.next()) |
| 596 | 0 | .toXml(document)); |
| 597 | 0 | userElement.appendChild(nAddressElement); |
| 598 | 0 | |
| 599 | 0 | Element eAddressElement = document |
| 600 | 0 | .createElement(ICXmlTags.IC_USER_EADDRESS_LIST_TAG); |
| 601 | 0 | iterator = this.eAddress.iterator(); |
| 602 | 0 | while (iterator.hasNext()) |
| 603 | 0 | eAddressElement.appendChild(((IXMLSaveable) iterator.next()) |
| 604 | 0 | .toXml(document)); |
| 605 | 0 | userElement.appendChild(eAddressElement); |
| 606 | 0 | |
| 607 | 0 | Element phoneNumberElement = document |
| 608 | 0 | .createElement(ICXmlTags.IC_USER_PHONE_NUMBER_LIST_TAG); |
| 609 | 0 | iterator = this.phoneNumber.iterator(); |
| 610 | 0 | while (iterator.hasNext()) |
| 611 | 0 | phoneNumberElement.appendChild(((IXMLSaveable) iterator.next()) |
| 612 | 0 | .toXml(document)); |
| 613 | 0 | userElement.appendChild(phoneNumberElement); |
| 614 | ||
| 615 | 0 | return userElement; |
| 616 | 0 | } |
| 617 | ||
| 618 | 0 | public Object fromXml(Document document) { |
| 619 | 0 | |
| 620 | 0 | Node userNode = document.getElementsByTagName(ICXmlTags.IC_USER_TAG) |
| 621 | 0 | .item(0); |
| 622 | ||
| 623 | 0 | int id = Integer.parseInt(userNode.getAttributes().getNamedItem( |
| 624 | 0 | ICXmlTags.IC_USER_ID_ATTRIBUTE).getNodeValue()); |
| 625 | 0 | int currentNAddressId = Integer.parseInt(userNode.getAttributes() |
| 626 | 0 | .getNamedItem(ICXmlTags.IC_USER_CURRENT_NADDRESS_ID_ATTRIBUTE) |
| 627 | 0 | .getNodeValue()); |
| 628 | 0 | int currentEAddressId = Integer.parseInt(userNode.getAttributes() |
| 629 | 0 | .getNamedItem(ICXmlTags.IC_USER_CURRENT_EADDRESS_ID_ATTRIBUTE) |
| 630 | 0 | .getNodeValue()); |
| 631 | 0 | int currentPhoneNumberId = Integer.parseInt(userNode.getAttributes() |
| 632 | 0 | .getNamedItem( |
| 633 | 0 | ICXmlTags.IC_USER_CURRENT_PHONE_NUMBER_ID_ATTRIBUTE) |
| 634 | 0 | .getNodeValue()); |
| 635 | 0 | |
| 636 | 0 | String name = ""; |
| 637 | 0 | String surname = ""; |
| 638 | 0 | String gender = ""; |
| 639 | 0 | String credential = ""; |
| 640 | 0 | Date birthday = null; |
| 641 | 0 | Date creationDate = null; |
| 642 | 0 | String nickname = ""; |
| 643 | 0 | String password = ""; |
| 644 | 0 | base.user.Document userDocument = null; |
| 645 | 0 | String imagePath = ""; |
| 646 | 0 | NAddress[] nAddress = null; |
| 647 | 0 | EAddress[] eAddress = null; |
| 648 | 0 | PhoneNumber[] phoneNumber = null; |
| 649 | 0 | |
| 650 | 0 | for (int i = 0; i < userNode.getChildNodes().getLength(); i++) { |
| 651 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 652 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_NAME_TAG)) |
| 653 | 0 | name = userNode.getChildNodes().item(i).getAttributes() |
| 654 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 655 | 0 | .getNodeValue(); |
| 656 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 657 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_SURNAME_TAG)) |
| 658 | 0 | surname = userNode.getChildNodes().item(i).getAttributes() |
| 659 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 660 | 0 | .getNodeValue(); |
| 661 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 662 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_GENDER_TAG)) |
| 663 | 0 | gender = userNode.getChildNodes().item(i).getAttributes() |
| 664 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 665 | 0 | .getNodeValue(); |
| 666 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 667 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_CREDENTIAL_TAG)) |
| 668 | 0 | credential = userNode.getChildNodes().item(i).getAttributes() |
| 669 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 670 | 0 | .getNodeValue(); |
| 671 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 672 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_NICKNAME_TAG)) |
| 673 | 0 | nickname = userNode.getChildNodes().item(i).getAttributes() |
| 674 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 675 | 0 | .getNodeValue(); |
| 676 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 677 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_PASSWORD_TAG)) |
| 678 | 0 | password = userNode.getChildNodes().item(i).getAttributes() |
| 679 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 680 | 0 | .getNodeValue(); |
| 681 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 682 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_IMAGE_PATH_TAG)) |
| 683 | 0 | imagePath = userNode.getChildNodes().item(i).getAttributes() |
| 684 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
| 685 | 0 | .getNodeValue(); |
| 686 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 687 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_BIRTHDAY_TAG)) |
| 688 | 0 | birthday = new Date(Long.parseLong(userNode.getChildNodes() |
| 689 | 0 | .item(i).getAttributes().getNamedItem( |
| 690 | 0 | ICXmlTags.IC_LONG_VALUE_ATTRIBUTE) |
| 691 | 0 | .getNodeValue())); |
| 692 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 693 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_CREATION_DATE_TAG)) |
| 694 | 0 | creationDate = new Date(Long.parseLong(userNode.getChildNodes() |
| 695 | 0 | .item(i).getAttributes().getNamedItem( |
| 696 | 0 | ICXmlTags.IC_LONG_VALUE_ATTRIBUTE) |
| 697 | 0 | .getNodeValue())); |
| 698 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 699 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_NADDRESS_LIST_TAG)) { |
| 700 | 0 | nAddress = new NAddress[userNode.getChildNodes().item(i) |
| 701 | 0 | .getChildNodes().getLength()]; |
| 702 | 0 | for (int k = 0; k < userNode.getChildNodes().item(i) |
| 703 | 0 | .getChildNodes().getLength(); k++) { |
| 704 | 0 | nAddress[k] = new NAddress().fromXml(userNode |
| 705 | 0 | .getChildNodes().item(i).getChildNodes().item(i)); |
| 706 | } | |
| 707 | } | |
| 708 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 709 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_EADDRESS_LIST_TAG)) { |
| 710 | 0 | eAddress = new EAddress[userNode.getChildNodes().item(i) |
| 711 | 0 | .getChildNodes().getLength()]; |
| 712 | 0 | for (int k = 0; k < userNode.getChildNodes().item(i) |
| 713 | 0 | .getChildNodes().getLength(); k++) { |
| 714 | 0 | eAddress[k] = new EAddress().fromXml(userNode |
| 715 | 0 | .getChildNodes().item(i).getChildNodes().item(i)); |
| 716 | } | |
| 717 | } | |
| 718 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 719 | 0 | .equalsIgnoreCase(ICXmlTags.IC_USER_PHONE_NUMBER_LIST_TAG)) { |
| 720 | 0 | phoneNumber = new PhoneNumber[userNode.getChildNodes().item(i) |
| 721 | 0 | .getChildNodes().getLength()]; |
| 722 | 0 | for (int k = 0; k < userNode.getChildNodes().item(i) |
| 723 | 0 | .getChildNodes().getLength(); k++) { |
| 724 | 0 | phoneNumber[k] = new PhoneNumber().fromXml(userNode |
| 725 | 0 | .getChildNodes().item(i).getChildNodes().item(i)); |
| 726 | } | |
| 727 | } | |
| 728 | 0 | if (userNode.getChildNodes().item(i).getNodeName() |
| 729 | 0 | .equalsIgnoreCase(ICXmlTags.IC_DOCUMENT_TAG)) { |
| 730 | 0 | userDocument = new base.user.Document().fromXml(userNode |
| 731 | 0 | .getChildNodes().item(i)); |
| 732 | } | |
| 733 | } | |
| 734 | ||
| 735 | 0 | User result = new User(id); |
| 736 | 0 | result.currentEAddressId = currentEAddressId; |
| 737 | 0 | result.currentNAddressId = currentNAddressId; |
| 738 | 0 | result.currentPhoneNumberId = currentPhoneNumberId; |
| 739 | 0 | result.creationDate = creationDate; |
| 740 | 0 | result.name = name; |
| 741 | 0 | result.surname = surname; |
| 742 | 0 | result.gender = gender; |
| 743 | 0 | result.birthday = birthday; |
| 744 | 0 | result.nickname = nickname; |
| 745 | 0 | result.password = password; |
| 746 | 0 | result.credential = credential; |
| 747 | 0 | result.document = userDocument; |
| 748 | 0 | result.imagePath = imagePath; |
| 749 | ||
| 750 | 0 | return result; |
| 751 | } | |
| 752 | ||
| 753 | /** | |
| 754 | * @param id | |
| 755 | * The id to set. | |
| 756 | */ | |
| 757 | protected void setId(int id) { | |
| 758 | 0 | this.id = id; |
| 759 | 0 | } |
| 760 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |