Source Code Cross Referenced for UploadDownloadFileManager.java in  » Portal » Open-Portal » com » sun » portal » fabric » mbeans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.fabric.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: UploadDownloadFileManager.java,v 1.6 2005/09/21 10:46:51 dg154973 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.mbeans;
014:
015:        import java.io.IOException;
016:        import java.io.FileNotFoundException;
017:
018:        import java.util.List;
019:        import java.util.Hashtable;
020:        import java.util.logging.Level;
021:        import java.util.logging.Logger;
022:
023:        import com.sun.portal.log.common.PortalLogger;
024:        import com.sun.portal.admin.server.mbeans.PSResource;
025:        import com.sun.portal.admin.common.context.PSConfigContext;
026:        import com.sun.portal.admin.common.context.PortalDomainContext;
027:        import com.sun.portal.admin.common.PSMBeanException;
028:        import com.sun.portal.fabric.tasks.UploadInfo;
029:        import com.sun.portal.fabric.tasks.DownloadInfo;
030:
031:        /** 
032:         * This class implements UploadDownloadFileManagerMBean interface and implements
033:         * methods to upload and download files. 
034:         */
035:        public class UploadDownloadFileManager extends PSResource implements 
036:                UploadDownloadFileManagerMBean {
037:
038:            private static final String STRING_UPLOAD = "upload";
039:            private static final String STRING_DOWNLOAD = "download";
040:            private static final String STRING_HYPHEN = "-";
041:            private static final String MSG_PREFIX = "fileUploadDownload";
042:            private String psPortalID;
043:            private static Logger logger = PortalLogger
044:                    .getLogger(UploadDownloadFileManager.class);
045:            private PSConfigContext cc = null;
046:            private Hashtable mInfo = new Hashtable(); //hashtable used as it is synchronized.
047:            private int fileCounter = 0;
048:
049:            public UploadDownloadFileManager() {
050:                ;
051:            }
052:
053:            public void init(PSConfigContext cc, PortalDomainContext pdc,
054:                    List path) {
055:                super .init(cc, pdc, path);
056:                this .cc = cc;
057:                this .psPortalID = (String) path.get(1);
058:            }
059:
060:            /**
061:             * This method prepares for file upload.
062:             * Sets the appropriate values for this file in UploadInfo class object.
063:             * @param fileName without path as in file.getName()
064:             * @return String array with first element as fileID and second element as
065:             *         filename with complete path as generated on this file system.
066:             */
067:            public String[] initiateFileUpload(String fileName, Long fileSize)
068:                    throws PSMBeanException {
069:
070:                String mObjectId = STRING_UPLOAD + STRING_HYPHEN + getCounter();
071:                UploadInfo uploadInfo = null;
072:                try {
073:                    uploadInfo = new UploadInfo(fileName, fileSize.longValue(),
074:                            cc.getPSDataDir());
075:                } catch (IOException ioe) {
076:                    logger.log(Level.SEVERE, "PSFB_CSPFM0003", ioe);
077:                    Object tokens[] = { uploadInfo.getName() };
078:                    throw new PSMBeanException(MSG_PREFIX + "errorInUpload",
079:                            ioe.getMessage(), tokens);
080:                }
081:                mInfo.put(mObjectId, uploadInfo); //this is synchronized as hashtable used.
082:                String[] nameIdArray = { mObjectId, uploadInfo.getName() };
083:                return nameIdArray;
084:            }
085:
086:            /**
087:             * This method is synchronized to return unique counter as it can be accessed
088:             * by multiple requests.
089:             * @return This method returns unique updated counter.  
090:             */
091:            private synchronized int getCounter() {
092:                fileCounter = fileCounter + 1;
093:                return fileCounter;
094:            }
095:
096:            /**
097:             * This method writes bytesToUpload to the file whose objectId is passed as uploadId.
098:             * @param uploadId : Id of the file as generated in  initiateFileUpload
099:             *
100:             */
101:            public void uploadBytes(String uploadId, byte[] bytesToUpload)
102:                    throws PSMBeanException {
103:
104:                UploadInfo uploadInfo = (UploadInfo) mInfo.get(uploadId);
105:                try {
106:                    uploadInfo.writeBytes(bytesToUpload);
107:                } catch (IOException ioe) {
108:
109:                    Object tokens[] = { uploadInfo.getName() };
110:                    logger.log(Level.SEVERE, "PSFB_CSPFM0004", tokens);
111:                    logger.log(Level.SEVERE, "PSFB_CSPFM0003", ioe);
112:                    throw new PSMBeanException(MSG_PREFIX + "errorInUpload",
113:                            ioe.getMessage(), tokens);
114:                }
115:            }
116:
117:            /**
118:             * This method prepares for file download.
119:             * Sets the appropriate values for this file in DownloadInfo class
120:             * object.
121:             * @param fileName with full path on the filesystem.
122:             * @return Object array with first element as fileID and second element as fileSize
123:             */
124:            public Object[] initiateFileDownload(String fileName)
125:                    throws PSMBeanException {
126:
127:                String mObjectId = STRING_DOWNLOAD + STRING_HYPHEN
128:                        + getCounter();
129:                DownloadInfo downloadInfo = null;
130:                try {
131:                    downloadInfo = new DownloadInfo(fileName);
132:                } catch (FileNotFoundException fne) {
133:                    logger.log(Level.SEVERE, "PSFB_CSPFM0003", fne);
134:                    Object tokens[] = { fileName };
135:                    throw new PSMBeanException(MSG_PREFIX
136:                            + "errorInDownloadFileNotFound", fne.getMessage(),
137:                            tokens);
138:                }
139:                mInfo.put(mObjectId, downloadInfo);
140:                Object[] idSizeArray = { mObjectId,
141:                        new Long(downloadInfo.getSize()) };
142:                return idSizeArray;
143:            }
144:
145:            /**
146:             * This method reads downloadSize no. of bytes from the file whose object id
147:             * is passed as downloadId
148:             * @param downloadId : Id of the file as generated in  initiateFileDownload
149:             *        downloadSize : No. of bytes to download
150:             */
151:            public byte[] downloadBytes(String downloadId, Integer downloadSize)
152:                    throws PSMBeanException {
153:
154:                byte[] readBytes = null;
155:                DownloadInfo downloadInfo = (DownloadInfo) mInfo
156:                        .get(downloadId);
157:                try {
158:                    readBytes = downloadInfo.readBytes(downloadSize.intValue());
159:                } catch (IOException ioe) {
160:                    logger.log(Level.SEVERE, "PSFB_CSPFM0003", ioe);
161:                    Object tokens[] = { downloadInfo.getName() };
162:                    logger.log(Level.SEVERE, "PSFB_CSPFM0004", tokens);
163:                    throw new PSMBeanException(MSG_PREFIX + "errorInDownload",
164:                            ioe.getMessage(), tokens);
165:                }
166:                return readBytes;
167:            }
168:
169:            /**
170:             * This method deletes temporary file created while upload.
171:             * Also deletes this id entry from hash table
172:             * @param Id of the file as generated in initiateFileUpload or filedownloaded
173:             */
174:            public void cleanUp(String Id) {
175:                Object info = mInfo.get(Id);
176:                if (info instanceof  UploadInfo) {
177:                    UploadInfo uploadInfo = (UploadInfo) info;
178:                    boolean ret = false;
179:                    ret = uploadInfo.deleteFile();
180:                    if (!ret) {
181:                        logger.log(Level.SEVERE, "PSFB_CSPFM0005", uploadInfo
182:                                .getName());
183:                    }
184:                } else if (info instanceof  DownloadInfo) {
185:                    DownloadInfo downloadInfo = (DownloadInfo) info;
186:                    downloadInfo.cleanUp();
187:                }
188:                mInfo.remove(Id);
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.