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