KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.columba.addressbook.folder.IContactFolder;
24
25 public class ContactModelFactory {
26
27     public static IGroupModelPartial createGroupPartial(IGroupModel group,
28             IContactFolder folder) {
29         if (group == null)
30             throw new IllegalArgumentException JavaDoc("group == null");
31         if (folder == null)
32             throw new IllegalArgumentException JavaDoc("folder == null");
33
34         IGroupModelPartial groupPartial = new GroupModelPartial(folder.getId(), group
35                 .getName(), group.getDescription());
36
37         // retrieve list of all group members
38
String JavaDoc[] members = group.getMembers();
39         Map JavaDoc<String JavaDoc, IContactModelPartial> map = folder
40                 .getContactItemMap(members);
41
42         Iterator JavaDoc<IContactModelPartial> it = map.values().iterator();
43         while (it.hasNext()) {
44             IContactModelPartial partial = it.next();
45
46             groupPartial.addContact(partial);
47         }
48         
49         return groupPartial;
50     }
51
52     public static IContactModelPartial createContactModelPartial(
53             IContactModel model, String JavaDoc id) {
54         if (model == null)
55             throw new IllegalArgumentException JavaDoc("model == null");
56         if (id == null)
57             throw new IllegalArgumentException JavaDoc("id == null");
58
59         String JavaDoc sortString = model.getSortString();
60
61         // @author: fdietz
62
// This is a workaround. Generally, the contact dialog editor
63
// should ensure that all necessary fields are available
64
//
65

66         // fall-back to formatted name
67
if (sortString == null || sortString.length() == 0)
68             sortString = model.getFormattedName();
69
70         // fall-back to email address
71
if (sortString == null || sortString.length() == 0)
72             sortString = model.getPreferredEmail();
73
74         IContactModelPartial item = new ContactModelPartial(id, sortString,
75                 model.getGivenName(), model.getFamilyName(), model
76                         .getPreferredEmail(), model.getHomePage());
77
78         return item;
79     }
80 }
81
Popular Tags