Source Code Cross Referenced for ArchiveStorer.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_lib » genbase » utils » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_lib.genbase.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS : Java(TM) OpenSource Application Server
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
017:         * USA
018:         *
019:         * Initial Developer : Guillaume Sauthier
020:         * --------------------------------------------------------------------------
021:         * $Id: ArchiveStorer.java 6673 2005-04-28 16:53:00Z benoitf $
022:         * --------------------------------------------------------------------------
023:         */package org.objectweb.jonas_lib.genbase.utils;
024:
025:        import java.io.IOException;
026:        import java.io.InputStream;
027:        import java.io.OutputStream;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Map;
031:        import java.util.Vector;
032:
033:        import org.w3c.dom.Document;
034:
035:        import org.objectweb.jonas_lib.I18n;
036:        import org.objectweb.jonas_lib.genbase.GenBaseException;
037:        import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
038:        import org.objectweb.jonas_lib.xml.XMLSerializer;
039:
040:        import org.objectweb.jonas.common.Log;
041:
042:        import org.objectweb.util.monolog.api.BasicLevel;
043:        import org.objectweb.util.monolog.api.Logger;
044:
045:        /**
046:         * Store an Archive in compressed or uncompressed format
047:         *
048:         * @author Guillaume Sauthier
049:         */
050:        public abstract class ArchiveStorer {
051:
052:            /** Buffer Size */
053:            public static final int MAX_BUFFER_SIZE = 1024;
054:
055:            /** i18n */
056:            private static I18n i18n = I18n.getInstance(ArchiveStorer.class);
057:
058:            /** logger */
059:            private static Logger logger = Log
060:                    .getLogger(Log.JONAS_GENBASE_PREFIX);
061:
062:            /**
063:             * base J2EEArchive to be saved
064:             */
065:            private J2EEArchive archive;
066:
067:            /**
068:             * already saved filenames
069:             */
070:            private List already;
071:
072:            /** output filename */
073:            private String out = "";
074:
075:            /**
076:             * Creates a new ArchiveStorer object.
077:             *
078:             * @param archive archive to be saved
079:             */
080:            public ArchiveStorer(J2EEArchive archive) {
081:                this .archive = archive;
082:                already = new Vector();
083:                // we must use Manifestof the J2EEArchive
084:                already.add(convertName("META-INF/MANIFEST.MF"));
085:            }
086:
087:            /**
088:             * Fill an OutputStream with content from an InputStream
089:             *
090:             * @param is InputStream
091:             * @param os OutputStream
092:             *
093:             * @throws IOException When filling fails
094:             */
095:            protected static void fill(InputStream is, OutputStream os)
096:                    throws IOException {
097:                byte[] buffer = new byte[MAX_BUFFER_SIZE];
098:                int read;
099:
100:                while ((read = is.read(buffer, 0, MAX_BUFFER_SIZE)) != -1) {
101:                    os.write(buffer, 0, read);
102:                }
103:            }
104:
105:            /**
106:             * add a file in saved archive
107:             *
108:             * @param name file name
109:             *
110:             * @throws IOException When save fails
111:             */
112:            protected abstract void addFile(String name) throws IOException;
113:
114:            /**
115:             * convert a filename from unix to windows filename and reverse
116:             *
117:             * @param name name to be converted
118:             *
119:             * @return converted filename
120:             */
121:            protected abstract String convertName(String name);
122:
123:            /**
124:             * Returns an OutputStream from the given name
125:             *
126:             * @param name the filename we want to open/create
127:             *
128:             * @return an OutputStream from the given name
129:             *
130:             * @throws IOException When OS cannot be created
131:             */
132:            protected abstract OutputStream getOutputStream(String name)
133:                    throws IOException;
134:
135:            /**
136:             * Store the content of the contained archive.
137:             *
138:             * @throws GenBaseException When cannot add all files
139:             */
140:            public void store() throws GenBaseException {
141:
142:                if (logger.isLoggable(BasicLevel.DEBUG)) {
143:                    logger.log(BasicLevel.DEBUG, "Writing '" + out + "' ...");
144:                }
145:
146:                for (Iterator i = archive.getContainedFiles().iterator(); i
147:                        .hasNext();) {
148:                    String name = (String) i.next();
149:
150:                    try {
151:                        if (!archive.omit(convertName(name))
152:                                && !already.contains(convertName(name))) {
153:
154:                            addFile(name);
155:                            already.add(convertName(name));
156:                        }
157:                    } catch (IOException ioe) {
158:                        String err = i18n.getMessage(
159:                                "ArchiveStorer.store.addFile", name);
160:                        throw new GenBaseException(err, ioe);
161:                    }
162:                }
163:
164:                // add Descriptors
165:                Map descs = archive.getDescriptors();
166:
167:                for (Iterator i = descs.keySet().iterator(); i.hasNext();) {
168:                    String name = (String) i.next();
169:
170:                    try {
171:                        XMLSerializer ser = new XMLSerializer((Document) descs
172:                                .get(name));
173:                        ser.serialize(getOutputStream(name));
174:                    } catch (IOException ioe) {
175:                        String err = i18n.getMessage(
176:                                "ArchiveStorer.store.serialize", name);
177:                        throw new GenBaseException(err, ioe);
178:                    }
179:                }
180:            }
181:
182:            /**
183:             * @return Returns the i18n.
184:             */
185:            public static I18n getI18n() {
186:                return i18n;
187:            }
188:
189:            /**
190:             * @return Returns the archive.
191:             */
192:            public J2EEArchive getArchive() {
193:                return archive;
194:            }
195:
196:            /**
197:             * @param out The out to set.
198:             */
199:            public void setOut(String out) {
200:                this.out = out;
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.