KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > model > ContactModel


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.model;
19
20 import java.util.Date JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import javax.swing.ImageIcon JavaDoc;
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 /**
34  * Contact model POJO.
35  *
36  * @author fdietz
37  */

38 public class ContactModel implements IContactModel {
39
40     private String JavaDoc id;
41
42     private String JavaDoc organisation;
43
44     private String JavaDoc department;
45
46     private String JavaDoc office;
47
48     private String JavaDoc title;
49
50     private String JavaDoc profession;
51
52     private String JavaDoc manager;
53     
54     private String JavaDoc sortString;
55
56     private String JavaDoc familyName;
57
58     private String JavaDoc givenName;
59
60     private String JavaDoc additionalNames;
61
62     private String JavaDoc nickName;
63
64     private String JavaDoc namePrefix;
65
66     private String JavaDoc nameSuffix;
67
68     private String JavaDoc fullName;
69
70     private String JavaDoc formattedName;
71
72     private String JavaDoc homePage;
73
74     private String JavaDoc weblog;
75
76     private String JavaDoc calendar;
77
78     private String JavaDoc freeBusy;
79
80     private Date JavaDoc birthday;
81
82     private ImageIcon JavaDoc photo;
83
84     private String JavaDoc category;
85
86     private Vector JavaDoc emailAddressVector = new Vector JavaDoc();
87
88     private String JavaDoc preferredPhone;
89
90     private Vector JavaDoc phoneVector = new Vector JavaDoc();
91
92     private Vector JavaDoc instantMessagingVector = new Vector JavaDoc();
93
94     private Vector JavaDoc addressVector = new Vector JavaDoc();
95
96     private String JavaDoc note;
97     
98     public ContactModel(IContactItem contactItem) {
99         if (contactItem == null || contactItem.getEmailAddress() == null || contactItem.getEmailAddress().length() == 0)
100             throw new IllegalArgumentException JavaDoc(
101                     "address == null or empty String");
102
103         Address adr;
104
105         String JavaDoc fn = contactItem.getName() != null ? contactItem.getName() : contactItem.getEmailAddress();
106         setFormattedName(fn);
107         
108         // backwards compatibility
109
setSortString(fn);
110         addEmail(new EmailModel(contactItem.getEmailAddress(), EmailModel.TYPE_WORK));
111
112         String JavaDoc[] 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 JavaDoc id) {
123         if (id == null)
124             throw new IllegalArgumentException JavaDoc("id == null");
125         
126         this.id = id;
127     }
128
129     public String JavaDoc getId() {
130         return id;
131     }
132
133     /**
134      * @see org.columba.addressbook.model.IContactModel#getAdditionalNames()
135      */

136     public String JavaDoc getAdditionalNames() {
137         return additionalNames;
138     }
139
140     /**
141      * @see org.columba.addressbook.model.IContactModel#getDepartment()
142      */

143     public String JavaDoc getDepartment() {
144         return department;
145     }
146
147     /**
148      * @see org.columba.addressbook.model.IContactModel#getPreferredEmail()
149      */

150     public String JavaDoc getPreferredEmail() {
151         Iterator JavaDoc it = getEmailIterator();
152
153         // get first item
154
IEmailModel model = (IEmailModel) it.next();
155
156         // backwards compatiblity
157
// -> its not possible anymore to create a contact model without email
158
// address
159
if (model == null)
160             return null;
161
162         return model.getAddress();
163     }
164
165     /**
166      * @see org.columba.addressbook.model.IContactModel#getFamilyName()
167      */

168     public String JavaDoc getFamilyName() {
169         return familyName;
170     }
171
172     /**
173      * @see org.columba.addressbook.model.IContactModel#getGivenName()
174      */

175     public String JavaDoc getGivenName() {
176         return givenName;
177     }
178
179     /**
180      * @see org.columba.addressbook.model.IContactModel#getNickName()
181      */

182     public String JavaDoc getNickName() {
183         return nickName;
184     }
185
186     /**
187      * @see org.columba.addressbook.model.IContactModel#getOrganisation()
188      */

189     public String JavaDoc getOrganisation() {
190         return organisation;
191     }
192
193     /**
194      * @see org.columba.addressbook.model.IContactModel#getProfession()
195      */

196     public String JavaDoc getProfession() {
197         return profession;
198     }
199
200     /**
201      * @see org.columba.addressbook.model.IContactModel#getNamePrefix()
202      */

203     public String JavaDoc getNamePrefix() {
204         return namePrefix;
205     }
206
207     /**
208      * @see org.columba.addressbook.model.IContactModel#getNameSuffix()
209      */

210     public String JavaDoc getNameSuffix() {
211         return nameSuffix;
212     }
213
214     /**
215      * @param familyName
216      * The familyName to set.
217      */

218     public void setFamilyName(String JavaDoc familyName) {
219         this.familyName = familyName;
220     }
221
222     /**
223      * @param additionalNames
224      * The additionalNames to set.
225      */

226     public void setAdditionalNames(String JavaDoc additionalNames) {
227         this.additionalNames = additionalNames;
228     }
229
230     /**
231      * @param department
232      * The department to set.
233      */

234     public void setDepartment(String JavaDoc department) {
235         this.department = department;
236     }
237
238     /**
239      * @param given
240      * The given to set.
241      */

242     public void setGivenName(String JavaDoc given) {
243         this.givenName = given;
244     }
245
246     /**
247      * @param nickname
248      * The nickname to set.
249      */

250     public void setNickName(String JavaDoc nickname) {
251         this.nickName = nickname;
252     }
253
254     /**
255      * @param organisation
256      * The organisation to set.
257      */

258     public void setOrganisation(String JavaDoc organisation) {
259         this.organisation = organisation;
260     }
261
262     /**
263      * @param position
264      * The position to set.
265      */

266     public void setProfession(String JavaDoc position) {
267         this.profession = position;
268     }
269
270     /**
271      * @param prefix
272      * The prefix to set.
273      */

274     public void setNamePrefix(String JavaDoc prefix) {
275         this.namePrefix = prefix;
276     }
277
278     /**
279      * @param suffix
280      * The suffix to set.
281      */

282     public void setNameSuffix(String JavaDoc suffix) {
283         this.nameSuffix = suffix;
284     }
285
286     public String JavaDoc getHomePage() {
287         return homePage;
288     }
289
290     public String JavaDoc getWeblog() {
291         return weblog;
292     }
293
294     public String JavaDoc getCalendar() {
295         return calendar;
296     }
297
298     public String JavaDoc getFreeBusy() {
299         return freeBusy;
300     }
301
302     /**
303      * @param calendar
304      * The calendar to set.
305      */

306     public void setCalendar(String JavaDoc calendar) {
307         this.calendar = calendar;
308     }
309
310     /**
311      * @param freeBusy
312      * The freeBusy to set.
313      */

314     public void setFreeBusy(String JavaDoc freeBusy) {
315         this.freeBusy = freeBusy;
316     }
317
318     /**
319      * @param homePage
320      * The homePage to set.
321      */

322     public void setHomePage(String JavaDoc homePage) {
323         this.homePage = homePage;
324     }
325
326     /**
327      * @param weblog
328      * The weblog to set.
329      */

330     public void setWeblog(String JavaDoc weblog) {
331         this.weblog = weblog;
332     }
333
334     /**
335      * @deprecated use getFormattedName() instead
336      *
337      * @see org.columba.addressbook.model.IContactModel#getFullName()
338      */

339     public String JavaDoc getFullName() {
340         return fullName;
341     }
342
343     /**
344      * @deprecated use setFormattedName() instead
345      *
346      * @param fullName
347      * The fullName to set.
348      */

349     public void setFullName(String JavaDoc fullName) {
350         this.fullName = fullName;
351     }
352
353     public String JavaDoc getFormattedName() {
354         return formattedName;
355     }
356
357     /**
358      * @param formattedName
359      * The formattedName to set.
360      */

361     public void setFormattedName(String JavaDoc formattedName) {
362         this.formattedName = formattedName;
363     }
364
365     public Iterator JavaDoc getEmailIterator() {
366         return emailAddressVector.iterator();
367     }
368
369     public void addEmail(IEmailModel emailAddress) {
370         if (emailAddress == null)
371             throw new IllegalArgumentException JavaDoc("emailModel == null");
372
373         emailAddressVector.add(emailAddress);
374     }
375
376     // public String getAgent() {
377
// return agent;
378
// }
379

380     public Date JavaDoc getBirthday() {
381         return birthday;
382     }
383
384     public String JavaDoc getSortString() {
385         return sortString;
386     }
387
388     public ImageIcon JavaDoc getPhoto() {
389         return photo;
390     }
391
392     /**
393      * @param birthday
394      * The birthday to set.
395      */

396     public void setBirthday(Date JavaDoc birthday) {
397         this.birthday = birthday;
398     }
399
400     /**
401      * @param photo
402      * The photo to set.
403      */

404     public void setPhoto(ImageIcon JavaDoc photo) {
405         this.photo = photo;
406     }
407
408     /**
409      * @param sortString
410      * The sortString to set.
411      */

412     public void setSortString(String JavaDoc sortString) {
413         this.sortString = sortString;
414     }
415
416     public Iterator JavaDoc getPhoneIterator() {
417         return phoneVector.iterator();
418     }
419
420     public void addPhone(PhoneModel phoneModel) {
421         if (phoneModel == null)
422             throw new IllegalArgumentException JavaDoc("phoneModel == null");
423
424         phoneVector.add(phoneModel);
425     }
426
427     public Iterator JavaDoc getInstantMessagingIterator() {
428         return instantMessagingVector.iterator();
429     }
430
431     public void addInstantMessaging(InstantMessagingModel instantMessagingModel) {
432         if (instantMessagingModel == null)
433             throw new IllegalArgumentException JavaDoc("instantMessaging == null");
434
435         instantMessagingVector.add(instantMessagingModel);
436     }
437
438     public String JavaDoc getPreferredPhone() {
439         return preferredPhone;
440     }
441
442     public void addAddress(AddressModel model) {
443         if (model == null)
444             throw new IllegalArgumentException JavaDoc("model == null");
445
446         addressVector.add(model);
447     }
448
449     public Iterator JavaDoc getAddressIterator() {
450         return addressVector.iterator();
451     }
452
453     public String JavaDoc getTitle() {
454         return title;
455     }
456
457     /**
458      * @param title
459      * The title to set.
460      */

461     public void setTitle(String JavaDoc title) {
462         this.title = title;
463     }
464
465     public String JavaDoc getNote() {
466         return note;
467     }
468
469     /**
470      * @param note
471      * The note to set.
472      */

473     public void setNote(String JavaDoc note) {
474         this.note = note;
475     }
476
477     public String JavaDoc getCategory() {
478         return category;
479     }
480
481     /**
482      * @param category
483      * The category to set.
484      */

485     public void setCategory(String JavaDoc category) {
486         this.category = category;
487     }
488
489     public String JavaDoc getOffice() {
490         return office;
491     }
492
493     /**
494      * @param office The office to set.
495      */

496     public void setOffice(String JavaDoc office) {
497         this.office = office;
498     }
499
500     public String JavaDoc getPreferredInstantMessaging() {
501         Iterator JavaDoc 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 JavaDoc getManager() {
511         return manager;
512     }
513
514     public void setManager(String JavaDoc manager) {
515         this.manager = manager;
516     }
517 }
Popular Tags