KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > email > MailDataObject


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.email;
19
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.sape.carbon.services.email.util.MailAttachment;
25 import org.sape.carbon.services.email.util.MailContentTypeEnum;
26
27 /**
28  * <p>This class encapsulates all the information required to send an email.</p>
29  *
30  * <p>Copyright 2002 Sapient </p>
31  *
32  * @stereotype data object
33  * @since carbon 1.0
34  * @author $Author: dvoet $ $Date: 2003/05/05 21:21:29 $
35  * @version $Revision: 1.1
36  */

37 public class MailDataObject {
38
39     /**
40      * <p>A Map containing the mapping of emails to names for all 'TO'
41      * recipients of the mail.</p>
42      */

43     private HashMap JavaDoc toMap;
44
45
46     /**
47      * <p>A Map containing the mapping of email to names for all 'CC'
48      * recipients of the mail.</p>
49      */

50     private HashMap JavaDoc ccMap;
51
52
53     /**
54      * <p>A Map containing the mapping of email to names for all 'BCC'
55      * recipients of the mail.</p>
56      */

57     private HashMap JavaDoc bccMap;
58
59
60     /**
61      * <p>A Map containing the mapping of header name to header value for
62      * any additional headers for the mail.</p>
63      */

64     private HashMap JavaDoc headers;
65
66
67     /**
68      * <p>The email address for the sender of the mail.</p>
69      */

70     private String JavaDoc fromEmail;
71
72
73     /**
74      * <p>The name of the sender of the mail.</p>
75      */

76     private String JavaDoc fromPersonal;
77
78
79     /**
80      * <p>The subject of the mail. </p>
81      */

82     private String JavaDoc subject;
83
84
85     /**
86      * <p>The body of the mail. </p>
87      */

88     private String JavaDoc body;
89
90
91     /**
92      * <p>The charset used to encode the contents of the mail.</p>
93      */

94     private String JavaDoc charset;
95
96
97     /**
98      * <p>The <code>bodyType</code> of the mail. </p>
99      */

100     private MailContentTypeEnum bodyType;
101
102
103     /**
104      * <p>A array containing the attachments to be send alongwith
105      * the mail.</p>
106      */

107     private MailAttachment[] attachments;
108
109
110     /**
111      * <p>Initializes all the <code>HashMap's</code>
112      */

113     public MailDataObject() {
114
115         toMap = new HashMap JavaDoc();
116         ccMap = new HashMap JavaDoc();
117         bccMap = new HashMap JavaDoc();
118         headers = new HashMap JavaDoc();
119     }
120
121
122     /**
123      * <p>Adds a recipient email id and name in 'TO' recipients of the mail.</p>
124      *
125      * @param toEmail The email id of the recipient.
126      * @param toPersonal The name of the recipient.
127      */

128     public void addTo(String JavaDoc toEmail, String JavaDoc toPersonal) {
129
130         this.toMap.put(toEmail, toPersonal);
131     }
132
133
134     /**
135      * <p>Adds a map of recipients email id to name in 'TO' recipients of the
136      * mail.</p>
137      *
138      * @param toMap A Map containing the mapping of emails to names for all
139      * 'TO' recipients of the email.
140      */

141     public void addTo(Map JavaDoc toMap) {
142
143         this.toMap.putAll(toMap);
144     }
145
146
147     /**
148      * <p>Adds a recipient email id and name in 'CC' recipients of the mail.</p>
149      *
150      * @param ccEmail The email id of the recipient.
151      * @param ccPersonal The name of the recipient.
152      */

153     public void addCC(String JavaDoc ccEmail, String JavaDoc ccPersonal) {
154
155         this.ccMap.put(ccEmail, ccPersonal);
156     }
157
158
159     /**
160      * <p>Adds a map of recipients email id to name in 'CC' recipients of the
161      * mail.</p>
162      *
163      * @param ccMap A Map containing the mapping of emails to names for all
164      * 'CC' recipients of the email.
165      */

166     public void addCC(Map JavaDoc ccMap) {
167
168         this.ccMap.putAll(ccMap);
169     }
170
171
172     /**
173      * <p>Adds a recipient email id and name in 'BCC' recipients
174      * of the mail.</p>
175      *
176      * @param bccEmail The email id of the recipient.
177      * @param bccPersonal The name of the recipient.
178      */

179     public void addBCC(String JavaDoc bccEmail, String JavaDoc bccPersonal) {
180
181         this.bccMap.put(bccEmail, bccPersonal);
182     }
183
184
185     /**
186      * <p>Adds a map of recipients email id to name in 'BCC' recipients of the
187      * mail.</p>
188      *
189      * @param bccMap A Map containing the mapping of emails to names for all
190      * 'BCC' recipients of the email.
191      */

192     public void addBCC(Map JavaDoc bccMap) {
193
194         this.bccMap.putAll(bccMap);
195     }
196
197
198     /**
199      * <p>Set's the sender's email id and name.</p>
200      *
201      * @param fromEmail The sender's email id.
202      * @param fromPersonal The sender's name.
203      */

204     public void setFrom(String JavaDoc fromEmail, String JavaDoc fromPersonal) {
205
206         this.fromEmail = fromEmail;
207         this.fromPersonal = fromPersonal;
208     }
209
210
211     /**
212      * <p>Setter for mail subject. <p>
213      *
214      * @param subject the subject of the message
215      */

216     public void setSubject(String JavaDoc subject) {
217
218         this.subject = subject;
219     }
220
221
222     /**
223      * <p>Set's the mail body and body type. </p>
224      *
225      * @param body content of the message
226      * @param bodyType type of message body (plain, html, etc)
227      */

228     public void setBody(String JavaDoc body, MailContentTypeEnum bodyType) {
229
230         this.body = body;
231         this.bodyType = bodyType;
232     }
233
234
235     /**
236      * <p>Setter for charset. </p>
237      *
238      * @param charset the charset of the mail message
239      */

240     public void setCharset(String JavaDoc charset) {
241
242         this.charset = charset;
243     }
244
245
246     /**
247      * <p>Adds any addtional headers.</p>
248      *
249      * @param headerName name of header to add
250      * @param headerValue value of the header
251      */

252     public void addHeader(String JavaDoc headerName, String JavaDoc headerValue) {
253
254         this.headers.put(headerName, headerValue);
255     }
256
257
258     /**
259      * <p>Adds any addtional headers.</p>
260      *
261      * @param headers additional headers to add to the message
262      */

263     public void addHeader(Map JavaDoc headers) {
264
265         this.headers.putAll(headers);
266     }
267
268
269     /**
270      * <p>Sets the Attachments to be send alongwith the mail.
271      *
272      * @param attachments A array containing the attachments to be
273      * send along with the mail.
274      */

275     public void setAttachments(MailAttachment[] attachments) {
276
277         this.attachments = attachments;
278     }
279
280
281     /**
282      * <p>Getter for 'TO' recipients in the mail.</p>
283      *
284      * @return toMap.
285      */

286     public Map JavaDoc getToMap() {
287
288         return this.toMap;
289     }
290
291
292     /**
293      * <p>Getter for 'CC' recipients in the mail.</p>
294      *
295      * @return ccMap.
296      */

297     public Map JavaDoc getCCMap() {
298
299         return this.ccMap;
300     }
301
302
303     /**
304      * <p>Getter for 'BCC' recipients in the mail.</p>
305      *
306      * @return bccMap.
307      */

308     public Map JavaDoc getBCCMap() {
309
310         return this.bccMap;
311     }
312
313
314     /**
315      * <p>Getter for additional headers in the mail.</p>
316      *
317      * @return headers.
318      */

319     public Map JavaDoc getHeaders() {
320
321         return this.headers;
322     }
323
324
325     /**
326      * <p>Getter for sender's name.</p>
327      *
328      * @return fromPersonal.
329      */

330     public String JavaDoc getFromName() {
331
332         return this.fromPersonal;
333     }
334
335
336     /**
337      * <p>Getter for sender's email id.</p>
338      *
339      * @return fromEmail.
340      */

341     public String JavaDoc getFromEmail() {
342
343         return this.fromEmail;
344     }
345
346
347     /**
348      * <p>Getter for charset. </p>
349      *
350      * @return charset.
351      */

352     public String JavaDoc getCharset() {
353
354         return this.charset;
355     }
356
357
358     /**
359      * <p>Getter for subject.</p>
360      *
361      * @return subject.
362      */

363     public String JavaDoc getSubject() {
364
365         return this.subject;
366     }
367
368
369     /**
370      * <p>Getter for body.</p>
371      *
372      * @return body.
373      */

374     public String JavaDoc getBody() {
375
376         return this.body;
377     }
378
379
380     /**
381      * <p>Getter for body type.</p>
382      *
383      * @return bodyType.
384      */

385     public MailContentTypeEnum getBodyType() {
386
387         return this.bodyType;
388     }
389
390
391     /**
392      * <p>Getter for attachments. </p>
393      *
394      * @return attachments
395      */

396     public MailAttachment[] getAttachments() {
397
398         return this.attachments;
399     }
400 }
401
Popular Tags