1 7 8 package javax.imageio.spi; 9 10 import java.security.PrivilegedAction ; 11 import java.security.AccessController ; 12 import java.util.HashMap ; 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import java.util.NoSuchElementException ; 16 import java.util.Set ; 17 import java.util.Vector ; 18 import com.sun.imageio.spi.FileImageInputStreamSpi; 19 import com.sun.imageio.spi.FileImageOutputStreamSpi; 20 import com.sun.imageio.spi.InputStreamImageInputStreamSpi; 21 import com.sun.imageio.spi.OutputStreamImageOutputStreamSpi; 22 import com.sun.imageio.spi.RAFImageInputStreamSpi; 23 import com.sun.imageio.spi.RAFImageOutputStreamSpi; 24 import com.sun.imageio.plugins.gif.GIFImageReaderSpi; 25 import com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi; 26 import com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi; 27 import com.sun.imageio.plugins.png.PNGImageReaderSpi; 28 import com.sun.imageio.plugins.png.PNGImageWriterSpi; 29 import com.sun.imageio.plugins.bmp.BMPImageReaderSpi; 30 import com.sun.imageio.plugins.bmp.BMPImageWriterSpi; 31 import com.sun.imageio.plugins.wbmp.WBMPImageReaderSpi; 32 import com.sun.imageio.plugins.wbmp.WBMPImageWriterSpi; 33 import sun.awt.AppContext; 34 import sun.misc.Service; 35 import sun.misc.ServiceConfigurationError; 36 37 94 public final class IIORegistry extends ServiceRegistry { 95 96 100 private static final Vector initialCategories = new Vector (5); 101 102 static { 103 initialCategories.add(ImageReaderSpi .class); 104 initialCategories.add(ImageWriterSpi .class); 105 initialCategories.add(ImageTranscoderSpi .class); 106 initialCategories.add(ImageInputStreamSpi .class); 107 initialCategories.add(ImageOutputStreamSpi .class); 108 } 109 110 117 private IIORegistry() { 118 super(initialCategories.iterator()); 119 registerStandardSpis(); 120 registerApplicationClasspathSpis(); 121 } 122 123 135 public static IIORegistry getDefaultInstance() { 136 AppContext context = AppContext.getAppContext(); 137 IIORegistry registry = 138 (IIORegistry )context.get(IIORegistry .class); 139 if (registry == null) { 140 registry = new IIORegistry (); 142 context.put(IIORegistry .class, registry); 143 } 144 return registry; 145 } 146 147 private void registerStandardSpis() { 148 registerServiceProvider(new GIFImageReaderSpi()); 150 registerServiceProvider(new BMPImageReaderSpi()); 151 registerServiceProvider(new BMPImageWriterSpi()); 152 registerServiceProvider(new WBMPImageReaderSpi()); 153 registerServiceProvider(new WBMPImageWriterSpi()); 154 registerServiceProvider(new PNGImageReaderSpi()); 155 registerServiceProvider(new PNGImageWriterSpi()); 156 registerServiceProvider(new JPEGImageReaderSpi()); 157 registerServiceProvider(new JPEGImageWriterSpi()); 158 registerServiceProvider(new FileImageInputStreamSpi()); 159 registerServiceProvider(new FileImageOutputStreamSpi()); 160 registerServiceProvider(new InputStreamImageInputStreamSpi()); 161 registerServiceProvider(new OutputStreamImageOutputStreamSpi()); 162 registerServiceProvider(new RAFImageInputStreamSpi()); 163 registerServiceProvider(new RAFImageOutputStreamSpi()); 164 165 registerInstalledProviders(); 166 } 167 168 177 public void registerApplicationClasspathSpis() { 178 180 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 181 182 Iterator categories = getCategories(); 183 while (categories.hasNext()) { 184 Class c = (Class )categories.next(); 185 Iterator <IIOServiceProvider > riter = Service.providers(c, loader); 186 while (riter.hasNext()) { 187 try { 188 IIOServiceProvider r = riter.next(); 189 registerServiceProvider(r); 190 } catch (ServiceConfigurationError err) { 191 if (System.getSecurityManager() != null) { 192 err.printStackTrace(); 195 } else { 196 throw err; 199 } 200 } 201 } 202 } 203 } 204 205 private void registerInstalledProviders() { 206 213 PrivilegedAction doRegistration = 214 new PrivilegedAction () { 215 public Object run() { 216 Iterator categories = getCategories(); 217 while (categories.hasNext()) { 218 Class c = (Class )categories.next(); 219 Iterator <IIOServiceProvider > providers = 220 Service.installedProviders(c); 221 while (providers.hasNext()) { 222 IIOServiceProvider p = providers.next(); 223 registerServiceProvider(p); 224 } 225 } 226 return this; 227 } 228 }; 229 230 AccessController.doPrivileged(doRegistration); 231 } 232 } 233 | Popular Tags |