Source Code Cross Referenced for ArchiveUpload.java in  » ESB » open-esb » com » sun » jbi » management » repository » 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 » ESB » open esb » com.sun.jbi.management.repository 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)ArchiveUpload.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.management.repository;
030:
031:        import com.sun.jbi.management.system.ManagementContext;
032:
033:        import com.sun.jbi.StringTranslator;
034:        import com.sun.jbi.management.LocalStringKeys;
035:        import com.sun.jbi.management.util.FileHelper;
036:
037:        import java.io.File;
038:        import java.io.OutputStream;
039:        import java.io.FileOutputStream;
040:        import java.net.URI;
041:        import java.util.HashMap;
042:        import java.util.Iterator;
043:        import java.util.logging.Logger;
044:        import java.rmi.server.UID;
045:
046:        /**
047:         *  Uploads archive bytes to a temporary store in the ESB repository.
048:         */
049:        public class ArchiveUpload implements  ArchiveUploadMBean {
050:            private StringTranslator mStrings;
051:            private Logger mLog;
052:            private File mUploadDir;
053:            private HashMap mSessions;
054:            private HashMap<String, File> mFiles;
055:
056:            public ArchiveUpload(ManagementContext ctx) {
057:                mSessions = new HashMap();
058:                mFiles = new HashMap();
059:                mLog = ctx.getLogger();
060:                mUploadDir = ctx.getRepository().getTempStore();
061:                mStrings = ctx.getEnvironmentContext().getStringTranslator(
062:                        "com.sun.jbi.management");
063:            }
064:
065:            /** Initiates an upload session.  The Object returned from this method
066:             *  is used as an identifier for uploading bytes with the 
067:             *  <code>uploadBytes()</code> method.
068:             *  @return a unique id used for uploading bytes
069:             */
070:            public Object initiateUpload(String archiveName)
071:                    throws java.io.IOException {
072:                String id;
073:                File dir;
074:                File file;
075:                FileOutputStream fos;
076:
077:                id = createUID();
078:                dir = new File(mUploadDir, id);
079:                dir.mkdir();
080:                file = new File(dir, archiveName);
081:                fos = new FileOutputStream(file);
082:
083:                mSessions.put(id, fos);
084:                mFiles.put(id, file);
085:                return id;
086:            }
087:
088:            /** Uploads a chunk of bytes to an existing temporary archive file.
089:             *  @param id the upload identifier
090:             *  @param bytes the content to upload
091:             */
092:            public void uploadBytes(Object id, byte[] bytes)
093:                    throws java.io.IOException {
094:                OutputStream out;
095:
096:                out = getUploadStream(id);
097:                out.write(bytes);
098:                out.flush();
099:            }
100:
101:            /** Used to indicate that the upload session with the specified id is
102:             *  complete.
103:             */
104:            public void terminateUpload(Object id, Long timestamp)
105:                    throws java.io.IOException {
106:                File file = mFiles.get(id);
107:
108:                getUploadStream(id).close();
109:                mSessions.remove(id);
110:                mFiles.remove(id);
111:                if (file != null && timestamp != null
112:                        && timestamp.longValue() != 0) {
113:                    file.setLastModified(timestamp.longValue());
114:                }
115:            }
116:
117:            public void terminateAllUploads() {
118:                Iterator ids;
119:
120:                try {
121:                    ids = mSessions.keySet().iterator();
122:                    while (ids.hasNext()) {
123:                        terminateUpload(ids.next(), null);
124:                    }
125:                } catch (java.io.IOException ioEx) {
126:                    mLog.warning(ioEx.getMessage());
127:                }
128:            }
129:
130:            /** Returns the location of the uploaded archive.
131:             *  @param id the upload identifier
132:             *  @return the location of the archive as a String URL, or null
133:             *  if the specified archive id does not exist in the repository.
134:             */
135:            public String getArchiveURL(Object id) {
136:                String arUrl = null;
137:                File dir = new File(mUploadDir, (String) id);
138:
139:                if (dir.exists()) {
140:                    File[] files = dir.listFiles();
141:
142:                    if (files.length > 0) {
143:                        File archive = files[0];
144:                        URI archiveURI = archive.toURI();
145:                        try {
146:                            arUrl = archiveURI.toURL().toString();
147:                        } catch (java.net.MalformedURLException muex) {
148:                            mLog.warning(muex.getMessage());
149:                        }
150:                    }
151:                }
152:
153:                return arUrl;
154:            }
155:
156:            /** Returns the absolute path to the location of the uploaded archive.
157:             *  @param id the upload identifier
158:             *  @return the absolute path to the location of the archive as a String , or null
159:             *  if the specified archive id does not exist in the repository.
160:             */
161:            public String getArchiveFilePath(Object id) {
162:                String archivePath = null;
163:                File dir = new File(mUploadDir, (String) id);
164:
165:                if (dir.exists()) {
166:                    File[] files = dir.listFiles();
167:
168:                    if (files.length > 0) {
169:                        File archive = files[0];
170:                        if (archive != null) {
171:                            archivePath = archive.getAbsolutePath();
172:                        }
173:                    }
174:                }
175:
176:                return archivePath;
177:            }
178:
179:            /** Delete the uploaded archive.
180:             *
181:             * @return true if the archive is deleted succcessfully, false otherwise
182:             */
183:            public boolean removeArchive(Object id) {
184:                File dir = new File(mUploadDir, (String) id);
185:                boolean removed = false;
186:
187:                removed = FileHelper.cleanDirectory(dir);
188:                if (removed) {
189:                    dir.delete();
190:                }
191:                return removed;
192:            }
193:
194:            /** Retrieve the output stream for a session. */
195:            private OutputStream getUploadStream(Object id)
196:                    throws java.io.IOException {
197:                FileOutputStream fos;
198:
199:                fos = (FileOutputStream) mSessions.get(id);
200:                if (fos == null) {
201:                    throw new java.io.IOException(
202:                            mStrings
203:                                    .getString(LocalStringKeys.JBI_ADMIN_UPLOAD_ID_NOT_FOUND));
204:                }
205:
206:                return fos;
207:            }
208:
209:            /** Create a unique id for the upload session. */
210:            private String createUID() {
211:                String uid;
212:
213:                uid = new UID().toString();
214:                uid = uid.replaceAll("-", "");
215:                uid = uid.replaceAll(":", "");
216:
217:                return uid;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.