KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > folder > virtual > VirtualFolder


1 package org.columba.addressbook.folder.virtual;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.Hashtable JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.UUID JavaDoc;
8 import java.util.Vector JavaDoc;
9
10 import javax.swing.ImageIcon JavaDoc;
11 import javax.swing.tree.TreeNode JavaDoc;
12
13 import org.columba.addressbook.folder.AbstractFolder;
14 import org.columba.addressbook.folder.IContactStorage;
15 import org.columba.addressbook.model.ContactModelFactory;
16 import org.columba.addressbook.model.IContactModel;
17 import org.columba.addressbook.model.IContactModelPartial;
18 import org.columba.api.exception.StoreException;
19
20 public class VirtualFolder extends AbstractFolder implements IContactStorage {
21
22     private Map JavaDoc<String JavaDoc, VirtualItem> map = new Hashtable JavaDoc<String JavaDoc, VirtualItem>();
23
24     public VirtualFolder() {
25         super("name", "directory");
26     }
27
28     public String JavaDoc add(IContactStorage parentStore, String JavaDoc parentId) {
29         if ( parentStore == null ) throw new IllegalArgumentException JavaDoc("parentStore == null");
30         if ( parentId == null ) throw new IllegalArgumentException JavaDoc("parentId == null");
31         
32         VirtualItem item = new VirtualItem(parentStore, parentId);
33         String JavaDoc uuid = UUID.randomUUID().toString();
34         map.put(uuid, item);
35
36         return uuid;
37     }
38
39     public String JavaDoc add(IContactModel contact) throws StoreException {
40         throw new IllegalArgumentException JavaDoc("add() not supported");
41     }
42
43     public int count() throws StoreException {
44         return map.size();
45     }
46
47     public boolean exists(String JavaDoc id) throws StoreException {
48         if ( id == null ) throw new IllegalArgumentException JavaDoc("id == null");
49         return map.containsKey(id);
50     }
51     
52     /**
53      * @see org.columba.addressbook.folder.IContactStorage#getHeaderItemList()
54      *
55      */

56     @Override JavaDoc
57     public Map JavaDoc<String JavaDoc, IContactModelPartial> getContactItemMap()
58             throws StoreException {
59         Map JavaDoc<String JavaDoc, IContactModelPartial> result = new Hashtable JavaDoc<String JavaDoc, IContactModelPartial>();
60
61         Iterator JavaDoc<Map.Entry JavaDoc<String JavaDoc, VirtualItem>> it = map.entrySet().iterator();
62         while (it.hasNext()) {
63             Map.Entry JavaDoc<String JavaDoc, VirtualItem> entry = it.next();
64             VirtualItem item = entry.getValue();
65             IContactStorage parentStore = item.getParentStore();
66             String JavaDoc parentId = item.getParentId();
67             
68             IContactModel model = parentStore.get(parentId);
69             IContactModelPartial partial = ContactModelFactory
70                     .createContactModelPartial(model, entry.getKey());
71             result.put(entry.getKey(), partial);
72         }
73         
74         return result;
75     }
76
77     public IContactModel get(String JavaDoc id) throws StoreException {
78         if ( id == null ) throw new IllegalArgumentException JavaDoc("id == null");
79         
80         VirtualItem item = map.get(id);
81         IContactStorage parentStore = item.getParentStore();
82         String JavaDoc parentId = item.getParentId();
83
84         IContactModel model = parentStore.get(parentId);
85         return model;
86     }
87
88     public void modify(String JavaDoc id, IContactModel contact) throws StoreException {
89         if ( id == null ) throw new IllegalArgumentException JavaDoc("id == null");
90         if ( contact == null ) throw new IllegalArgumentException JavaDoc("contact == null");
91         
92         VirtualItem item = map.get(id);
93         IContactStorage parentStore = item.getParentStore();
94         String JavaDoc parentId = item.getParentId();
95
96         parentStore.modify(parentId, contact);
97     }
98
99     public void remove(String JavaDoc id) throws StoreException {
100         if ( id == null ) throw new IllegalArgumentException JavaDoc("id == null");
101         
102         VirtualItem item = map.get(id);
103         IContactStorage parentStore = item.getParentStore();
104         String JavaDoc parentId = item.getParentId();
105
106         parentStore.remove(parentId);
107     }
108
109     public ImageIcon JavaDoc getIcon() {
110         return null;
111     }
112
113     public String JavaDoc getId() {
114         return "id";
115     }
116
117     public String JavaDoc getName() {
118         return "vfolder";
119     }
120
121     public Enumeration JavaDoc children() {
122         return new Vector JavaDoc().elements();
123     }
124
125     public boolean getAllowsChildren() {
126         return false;
127     }
128
129     public TreeNode JavaDoc getChildAt(int childIndex) {
130         return null;
131     }
132
133     public int getChildCount() {
134         return 0;
135     }
136
137     public int getIndex(TreeNode JavaDoc node) {
138         return 0;
139     }
140
141     public TreeNode JavaDoc getParent() {
142         return null;
143     }
144
145     public boolean isLeaf() {
146         return false;
147     }
148
149 }
150
Popular Tags