1 package org.columba.addressbook.model; 19 20 import java.util.Date ; 21 import java.util.Iterator ; 22 import java.util.Vector ; 23 24 import javax.swing.ImageIcon ; 25 26 import org.columba.addressbook.facade.IContactItem; 27 import org.columba.addressbook.parser.ParserUtil; 28 import org.columba.core.base.UUIDGenerator; 29 import org.columba.core.logging.Logging; 30 import org.columba.ristretto.message.Address; 31 import org.columba.ristretto.parser.ParserException; 32 33 38 public class ContactModel implements IContactModel { 39 40 private String id; 41 42 private String organisation; 43 44 private String department; 45 46 private String office; 47 48 private String title; 49 50 private String profession; 51 52 private String manager; 53 54 private String sortString; 55 56 private String familyName; 57 58 private String givenName; 59 60 private String additionalNames; 61 62 private String nickName; 63 64 private String namePrefix; 65 66 private String nameSuffix; 67 68 private String fullName; 69 70 private String formattedName; 71 72 private String homePage; 73 74 private String weblog; 75 76 private String calendar; 77 78 private String freeBusy; 79 80 private Date birthday; 81 82 private ImageIcon photo; 83 84 private String category; 85 86 private Vector emailAddressVector = new Vector (); 87 88 private String preferredPhone; 89 90 private Vector phoneVector = new Vector (); 91 92 private Vector instantMessagingVector = new Vector (); 93 94 private Vector addressVector = new Vector (); 95 96 private String note; 97 98 public ContactModel(IContactItem contactItem) { 99 if (contactItem == null || contactItem.getEmailAddress() == null || contactItem.getEmailAddress().length() == 0) 100 throw new IllegalArgumentException ( 101 "address == null or empty String"); 102 103 Address adr; 104 105 String fn = contactItem.getName() != null ? contactItem.getName() : contactItem.getEmailAddress(); 106 setFormattedName(fn); 107 108 setSortString(fn); 110 addEmail(new EmailModel(contactItem.getEmailAddress(), EmailModel.TYPE_WORK)); 111 112 String [] result = ParserUtil.tryBreakName(fn); 113 setGivenName(contactItem.getFirstName()); 114 setFamilyName(contactItem.getLastName()); 115 116 } 117 118 public ContactModel() { 119 this.id = new UUIDGenerator().newUUID(); 120 } 121 122 public ContactModel(String id) { 123 if (id == null) 124 throw new IllegalArgumentException ("id == null"); 125 126 this.id = id; 127 } 128 129 public String getId() { 130 return id; 131 } 132 133 136 public String getAdditionalNames() { 137 return additionalNames; 138 } 139 140 143 public String getDepartment() { 144 return department; 145 } 146 147 150 public String getPreferredEmail() { 151 Iterator it = getEmailIterator(); 152 153 IEmailModel model = (IEmailModel) it.next(); 155 156 if (model == null) 160 return null; 161 162 return model.getAddress(); 163 } 164 165 168 public String getFamilyName() { 169 return familyName; 170 } 171 172 175 public String getGivenName() { 176 return givenName; 177 } 178 179 182 public String getNickName() { 183 return nickName; 184 } 185 186 189 public String getOrganisation() { 190 return organisation; 191 } 192 193 196 public String getProfession() { 197 return profession; 198 } 199 200 203 public String getNamePrefix() { 204 return namePrefix; 205 } 206 207 210 public String getNameSuffix() { 211 return nameSuffix; 212 } 213 214 218 public void setFamilyName(String familyName) { 219 this.familyName = familyName; 220 } 221 222 226 public void setAdditionalNames(String additionalNames) { 227 this.additionalNames = additionalNames; 228 } 229 230 234 public void setDepartment(String department) { 235 this.department = department; 236 } 237 238 242 public void setGivenName(String given) { 243 this.givenName = given; 244 } 245 246 250 public void setNickName(String nickname) { 251 this.nickName = nickname; 252 } 253 254 258 public void setOrganisation(String organisation) { 259 this.organisation = organisation; 260 } 261 262 266 public void setProfession(String position) { 267 this.profession = position; 268 } 269 270 274 public void setNamePrefix(String prefix) { 275 this.namePrefix = prefix; 276 } 277 278 282 public void setNameSuffix(String suffix) { 283 this.nameSuffix = suffix; 284 } 285 286 public String getHomePage() { 287 return homePage; 288 } 289 290 public String getWeblog() { 291 return weblog; 292 } 293 294 public String getCalendar() { 295 return calendar; 296 } 297 298 public String getFreeBusy() { 299 return freeBusy; 300 } 301 302 306 public void setCalendar(String calendar) { 307 this.calendar = calendar; 308 } 309 310 314 public void setFreeBusy(String freeBusy) { 315 this.freeBusy = freeBusy; 316 } 317 318 322 public void setHomePage(String homePage) { 323 this.homePage = homePage; 324 } 325 326 330 public void setWeblog(String weblog) { 331 this.weblog = weblog; 332 } 333 334 339 public String getFullName() { 340 return fullName; 341 } 342 343 349 public void setFullName(String fullName) { 350 this.fullName = fullName; 351 } 352 353 public String getFormattedName() { 354 return formattedName; 355 } 356 357 361 public void setFormattedName(String formattedName) { 362 this.formattedName = formattedName; 363 } 364 365 public Iterator getEmailIterator() { 366 return emailAddressVector.iterator(); 367 } 368 369 public void addEmail(IEmailModel emailAddress) { 370 if (emailAddress == null) 371 throw new IllegalArgumentException ("emailModel == null"); 372 373 emailAddressVector.add(emailAddress); 374 } 375 376 380 public Date getBirthday() { 381 return birthday; 382 } 383 384 public String getSortString() { 385 return sortString; 386 } 387 388 public ImageIcon getPhoto() { 389 return photo; 390 } 391 392 396 public void setBirthday(Date birthday) { 397 this.birthday = birthday; 398 } 399 400 404 public void setPhoto(ImageIcon photo) { 405 this.photo = photo; 406 } 407 408 412 public void setSortString(String sortString) { 413 this.sortString = sortString; 414 } 415 416 public Iterator getPhoneIterator() { 417 return phoneVector.iterator(); 418 } 419 420 public void addPhone(PhoneModel phoneModel) { 421 if (phoneModel == null) 422 throw new IllegalArgumentException ("phoneModel == null"); 423 424 phoneVector.add(phoneModel); 425 } 426 427 public Iterator getInstantMessagingIterator() { 428 return instantMessagingVector.iterator(); 429 } 430 431 public void addInstantMessaging(InstantMessagingModel instantMessagingModel) { 432 if (instantMessagingModel == null) 433 throw new IllegalArgumentException ("instantMessaging == null"); 434 435 instantMessagingVector.add(instantMessagingModel); 436 } 437 438 public String getPreferredPhone() { 439 return preferredPhone; 440 } 441 442 public void addAddress(AddressModel model) { 443 if (model == null) 444 throw new IllegalArgumentException ("model == null"); 445 446 addressVector.add(model); 447 } 448 449 public Iterator getAddressIterator() { 450 return addressVector.iterator(); 451 } 452 453 public String getTitle() { 454 return title; 455 } 456 457 461 public void setTitle(String title) { 462 this.title = title; 463 } 464 465 public String getNote() { 466 return note; 467 } 468 469 473 public void setNote(String note) { 474 this.note = note; 475 } 476 477 public String getCategory() { 478 return category; 479 } 480 481 485 public void setCategory(String category) { 486 this.category = category; 487 } 488 489 public String getOffice() { 490 return office; 491 } 492 493 496 public void setOffice(String office) { 497 this.office = office; 498 } 499 500 public String getPreferredInstantMessaging() { 501 Iterator it = getInstantMessagingIterator(); 502 if ( it.hasNext() ) { 503 InstantMessagingModel m = (InstantMessagingModel) it.next(); 504 return m.getUserId(); 505 } 506 507 return null; 508 } 509 510 public String getManager() { 511 return manager; 512 } 513 514 public void setManager(String manager) { 515 this.manager = manager; 516 } 517 } | Popular Tags |