Source Code Cross Referenced for PackCompressorFactory.java in  » Installer » IzPack » com » izforge » izpack » compressor » 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 » Installer » IzPack » com.izforge.izpack.compressor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: PackCompressorFactory.java 2061 2008-02-25 20:05:31Z jponge $
003:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
004:         * 
005:         * http://izpack.org/
006:         * http://izpack.codehaus.org/
007:         * 
008:         * Copyright 2005 Klaus Bartz
009:         *
010:         * Licensed under the Apache License, Version 2.0 (the "License");
011:         * you may not use this file except in compliance with the License.
012:         * You may obtain a copy of the License at
013:         * 
014:         *     http://www.apache.org/licenses/LICENSE-2.0
015:         *     
016:         * Unless required by applicable law or agreed to in writing, software
017:         * distributed under the License is distributed on an "AS IS" BASIS,
018:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019:         * See the License for the specific language governing permissions and
020:         * limitations under the License.
021:         */
022:
023:        package com.izforge.izpack.compressor;
024:
025:        import java.util.HashMap;
026:
027:        import com.izforge.izpack.compiler.CompilerException;
028:
029:        /**
030:         * IzPack will be able to support different compression methods for the
031:         * packs included in the installation jar file.
032:         * This class is the factory which offers different "compressors" to
033:         * IzPack. It is made to mask the internal structure of each "compressor"
034:         * and gaves a common API for all supported compression methods to IzPack.
035:         * IzPacks compiler uses this class to get an encoder and the informations
036:         * which are needed to support the decompression in the installation. 
037:         * All "compressors" should use this class as API and should not be
038:         * included directly in the IzPack compiler.
039:         * 
040:         * @author Klaus Bartz
041:         */
042:        public class PackCompressorFactory {
043:            /** This map contains all registered "compressors".
044:             *  The keys are the symbolic names which are used for a particular
045:             *  compression format.
046:             */
047:            private static HashMap<String, PackCompressor> typeMap = new HashMap<String, PackCompressor>();
048:            private static CompilerException ShitHappens = null;
049:
050:            static { // Add the well known pack compressors to this factory
051:                catchedRegister(new RawPackCompressor());
052:                catchedRegister(new DefaultPackCompressor());
053:                catchedRegister(new BZip2PackCompressor());
054:            }
055:
056:            /**
057:             * No object of this factory needed.
058:             */
059:            private PackCompressorFactory() {
060:                super ();
061:            }
062:
063:            /**
064:             * Register a particular pack compressor to this factory.
065:             * The used symbolic name will be handled case insensitive.
066:             * @param pc an instance of the pack compressor which describes 
067:             * encoder and decoder for a special compression format
068:             */
069:            public static void catchedRegister(PackCompressor pc) {
070:                if (!good())
071:                    return;
072:                try {
073:                    register(pc);
074:                } catch (CompilerException e) {
075:                    ShitHappens = e;
076:                }
077:
078:            }
079:
080:            /**
081:             * Register a particular pack compressor to this factory.
082:             * The used symbolic name will be handled case insensitive.
083:             * @param pc an instance of the pack compressor which describes 
084:             * encoder and decoder for a special compression format
085:             * @throws CompilerException if the symbol already exist or if
086:             * the compressor is not valid
087:             */
088:            public static void register(PackCompressor pc)
089:                    throws CompilerException {
090:                String[] syms = pc.getCompressionFormatSymbols();
091:                for (String sym1 : syms) {
092:                    String sym = sym1.toLowerCase();
093:                    if (typeMap.containsKey(sym)) {
094:                        throw new CompilerException(
095:                                "PackCompressor for symbol " + sym
096:                                        + " allready registered");
097:                    }
098:                    typeMap.put(sym, pc);
099:                    // TODO: add verify of PackCompressor.
100:                }
101:            }
102:
103:            /**
104:             * Returns whether a compressor exists for the given symbolic
105:             * name or not.
106:             * @param type symbolic compression name to be tested
107:             * @return whether the given compression format will be supported
108:             * or not
109:             * @throws CompilerException
110:             */
111:            public static boolean isTypeSupported(String type)
112:                    throws CompilerException {
113:                if (!good())
114:                    throw (ShitHappens);
115:                type = type.toLowerCase();
116:                return (typeMap.containsKey(type));
117:            }
118:
119:            /**
120:             * Returns a newly created pack compressor with the given
121:             * compression format.
122:             * @param type symbol name of compression format to be used
123:             * @return a newly created pack compressor 
124:             * @throws CompilerException if no encoder is registered for 
125:             * the chosen compression format
126:             */
127:            public static PackCompressor get(String type)
128:                    throws CompilerException {
129:                if (!good())
130:                    throw (ShitHappens);
131:                type = type.toLowerCase();
132:                if (!typeMap.containsKey(type))
133:                    throw new CompilerException(
134:                            "No PackCompressor registered for the given symbol "
135:                                    + type + ".");
136:                return (typeMap.get(type));
137:
138:            }
139:
140:            /**
141:             * Returns the exception which was thrown during
142:             * registering of a pack compressor.
143:             * @return the exception which was thrown during
144:             * registering of a pack compressor
145:             */
146:            public static CompilerException getRegisterException() {
147:                return ShitHappens;
148:            }
149:
150:            /**
151:             * Sets an exception which was thrown during registering a pack compressor.
152:             * @param registerException The register exception to set.
153:             */
154:            public static void setRegisterException(
155:                    CompilerException registerException) {
156:                ShitHappens = registerException;
157:            }
158:
159:            public static boolean good() {
160:                return (ShitHappens == null);
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.