1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.struts.apps.mailreader.dao.impl;
24
25 import java.util.HashMap;
26
27 import org.apache.struts.apps.mailreader.dao.Subscription;
28 import org.apache.struts.apps.mailreader.dao.User;
29 import org.apache.struts.apps.mailreader.dao.UserDatabase;
30
31
32
33
34
35
36
37
38
39 public abstract class AbstractUser implements User {
40
41
42
43
44
45
46
47
48
49
50
51
52 public AbstractUser(UserDatabase database, String username) {
53
54 super();
55 this.database = database;
56 this.username = username;
57
58 }
59
60
61
62
63
64
65
66
67 private UserDatabase database = null;
68
69
70
71
72
73 private HashMap subscriptions = new HashMap();
74
75
76
77
78
79 private String username = null;
80
81
82
83
84
85
86
87
88 public UserDatabase getDatabase() {
89 return (this.database);
90 }
91
92
93
94
95
96 private String fromAddress = null;
97
98 public String getFromAddress() {
99 return (this.fromAddress);
100 }
101
102 public void setFromAddress(String fromAddress) {
103 this.fromAddress = fromAddress;
104 }
105
106
107
108
109
110 private String fullName = null;
111
112 public String getFullName() {
113 return (this.fullName);
114 }
115
116 public void setFullName(String fullName) {
117 this.fullName = fullName;
118 }
119
120
121
122
123
124 private String password = null;
125
126 public String getPassword() {
127 return (this.password);
128 }
129
130 public void setPassword(String password) {
131 this.password = password;
132 }
133
134
135
136
137
138 private String replyToAddress = null;
139
140 public String getReplyToAddress() {
141 return (this.replyToAddress);
142 }
143
144 public void setReplyToAddress(String replyToAddress) {
145 this.replyToAddress = replyToAddress;
146 }
147
148
149
150
151
152
153 public Subscription[] getSubscriptions() {
154
155 synchronized (subscriptions) {
156 Subscription results[] = new Subscription[subscriptions.size()];
157 return ((Subscription[]) subscriptions.values().toArray(results));
158 }
159
160 }
161
162
163
164
165
166 public String getUsername() {
167 return (this.username);
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183 public Subscription createSubscription(String host) {
184
185 synchronized (subscriptions) {
186 if (subscriptions.get(host) != null) {
187 throw new IllegalArgumentException("Duplicate host '" + host
188 + "' for user '" +
189 username + "'");
190 }
191 Subscription subscription =
192 new AbstractSubscription(this, host);
193 synchronized (subscriptions) {
194 subscriptions.put(host, subscription);
195 }
196 return (subscription);
197 }
198
199 }
200
201
202
203
204
205
206
207
208 public Subscription findSubscription(String host) {
209
210 synchronized (subscriptions) {
211 return ((Subscription) subscriptions.get(host));
212 }
213
214 }
215
216
217
218
219
220
221
222
223
224
225
226 public void removeSubscription(Subscription subscription) {
227
228 if (!(this == subscription.getUser())) {
229 throw new IllegalArgumentException
230 ("Subscription not associated with this user");
231 }
232 synchronized (subscriptions) {
233 subscriptions.remove(subscription.getHost());
234 }
235
236 }
237
238
239 }