KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > transport > mail > server > Storage


1 package org.apache.axis2.transport.mail.server;
2
3 /**
4  * Inmemory storage to used to store the mails.
5  * @author Chamil Thanthrimudalige.
6  */

7
8 import javax.mail.internet.MimeMessage JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Hashtable JavaDoc;
11
12 public class Storage {
13     private ArrayList JavaDoc mails = new ArrayList JavaDoc();
14     
15     private Hashtable JavaDoc users = new Hashtable JavaDoc();
16     
17     
18     public Storage(){
19     }
20
21     public void addMail(String JavaDoc user, MimeMessage JavaDoc mail){
22         ArrayList JavaDoc curMailBox = null;
23         if (users.containsKey(user)){
24             curMailBox = (ArrayList JavaDoc)users.get(user);
25         } else {
26             curMailBox = new ArrayList JavaDoc();
27             users.put(user, curMailBox);
28         }
29         curMailBox.add(mail);
30     }
31
32     public ArrayList JavaDoc popUserMails(String JavaDoc user){
33         ArrayList JavaDoc usrMailBox = new ArrayList JavaDoc(); // This will return a emty list when the user has no mails or no mail box.
34
if (users.containsKey(user)){
35             usrMailBox = (ArrayList JavaDoc)users.get(user);
36         }
37         return usrMailBox;
38     }
39 }
Popular Tags