KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > UploadManager


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.vfs;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import com.sslexplorer.core.CoreUtil;
26 import com.sslexplorer.vfs.actions.ShowUploadAction;
27
28
29 /**
30  *
31  * Maintains a list of {@link UploadDetails} ands allows the upload system
32  * to access them via their id.
33  * <p>
34  * In general, a user would request an upload. The controlling action would
35  * then create a new upload details object and add it to their sessions
36  * upload manager. Control would then be passed to {@link ShowUploadAction}
37  * given it the upload id.
38  * <p>
39  * In general, you would never need to create an instance of this class
40  * yourself and should instead use {@link CoreUtil#addUpload(javax.servlet.http.HttpSession, UploadDetails)}.
41  *
42  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class UploadManager {
45
46     // Private instance variables
47
private Map JavaDoc uploads = new HashMap JavaDoc();
48     private int id = 0;
49     
50     /**
51      * Add a new upload and return its id.
52      *
53      * @param upload upload
54      * @return id
55      */

56     public synchronized int addUpload(UploadDetails upload) {
57         id++;
58         uploads.put(new Integer JavaDoc(id), upload);
59         return id;
60     }
61     
62     /**
63      * Remove an upload given its id
64      *
65      * @param id id
66      * @return removed details
67      */

68     public UploadDetails removeUpload(int id) {
69         return (UploadDetails)uploads.remove(new Integer JavaDoc(id));
70     }
71     
72     /**
73      * Get an upload given its id. <code>null</code> will be returned if no
74      * such upload exists.
75      *
76      * @param id id
77      * @return upload
78      */

79     public UploadDetails getUpload(int id) {
80         return (UploadDetails)uploads.get(new Integer JavaDoc(id));
81     }
82
83     /**
84      * Get if there are no uploads being managed.
85      *
86      * @return empty
87      */

88     public boolean isEmpty() {
89         return uploads.size() == 0;
90     }
91
92 }
93
Popular Tags