1 22 23 package com.izforge.izpack.compressor; 24 25 import java.util.HashMap ; 26 27 import com.izforge.izpack.compiler.CompilerException; 28 29 30 31 44 public class PackCompressorFactory 45 { 46 50 private static HashMap typeMap = new HashMap (); 51 private static CompilerException ShitHappens = null; 52 53 static 54 { catchedRegister(new RawPackCompressor()); 56 catchedRegister(new DefaultPackCompressor()); 57 catchedRegister(new BZip2PackCompressor()); 58 } 59 60 63 private PackCompressorFactory() 64 { 65 super(); 66 } 67 68 69 75 public static void catchedRegister(PackCompressor pc) 76 { 77 if( !good()) 78 return; 79 try 80 { 81 register(pc); 82 } 83 catch (CompilerException e) 84 { 85 ShitHappens = e; 86 } 87 88 } 89 90 98 public static void register(PackCompressor pc) 99 throws CompilerException 100 { 101 String [] syms = pc.getCompressionFormatSymbols(); 102 for(int i = 0; i < syms.length; ++i) 103 { 104 String sym = syms[i].toLowerCase(); 105 if( typeMap.containsKey(sym)) 106 throw new CompilerException("PackCompressor for symbol " 107 + sym + " allready registered"); 108 typeMap.put(sym, pc); 109 } 111 } 112 113 121 public static boolean isTypeSupported( String type ) throws CompilerException 122 { 123 if( ! good()) 124 throw(ShitHappens); 125 type = type.toLowerCase(); 126 return( typeMap.containsKey(type)); 127 } 128 129 137 public static PackCompressor get( String type) 138 throws CompilerException 139 { 140 if( ! good()) 141 throw(ShitHappens); 142 type = type.toLowerCase(); 143 if( ! typeMap.containsKey(type)) 144 throw new CompilerException( 145 "No PackCompressor registered for the given symbol " 146 + type + "."); 147 return((PackCompressor) typeMap.get(type)); 148 149 } 150 156 public static CompilerException getRegisterException() 157 { 158 return ShitHappens; 159 } 160 164 public static void setRegisterException(CompilerException registerException) 165 { 166 ShitHappens = registerException; 167 } 168 169 public static boolean good() 170 { 171 return( ShitHappens == null ); 172 } 173 } 174 | Popular Tags |