1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18 * @author Rustem V. Rafikov 19 * @version $Revision: 1.3 $ 20 */ 21 22package javax.imageio.spi; 23 24import java.util.Arrays; 25 26import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi; 27import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi; 28import org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi; 29import org.apache.harmony.x.imageio.plugins.png.PNGImageWriterSpi; 30import org.apache.harmony.x.imageio.spi.FileIISSpi; 31import org.apache.harmony.x.imageio.spi.FileIOSSpi; 32import org.apache.harmony.x.imageio.spi.InputStreamIISSpi; 33import org.apache.harmony.x.imageio.spi.OutputStreamIOSSpi; 34import org.apache.harmony.x.imageio.spi.RAFIISSpi; 35import org.apache.harmony.x.imageio.spi.RAFIOSSpi; 36 37/* 38 * @author Rustem V. Rafikov, Viskov Nikolay 39 * @version $Revision: 1.3 $ 40 */ 41 42/** 43 * The IIORegistry class registers service provider instances (SPI). Service 44 * provider instances are recognized by specific meta-information in the JAR 45 * files containing them. The JAR files with SPI classes are loaded from the 46 * application class path. 47 * 48 * @since Android 1.0 49 */ 50public final class IIORegistry extends ServiceRegistry { 51 52 /** 53 * The instance. 54 */ 55 private static IIORegistry instance; 56 57 /** 58 * The Constant CATEGORIES. 59 */ 60 private static final Class[] CATEGORIES = new Class[] { 61 javax.imageio.spi.ImageWriterSpi.class, javax.imageio.spi.ImageReaderSpi.class, 62 javax.imageio.spi.ImageInputStreamSpi.class, 63 // javax.imageio.spi.ImageTranscoderSpi.class, 64 javax.imageio.spi.ImageOutputStreamSpi.class 65 }; 66 67 /** 68 * Instantiates a new IIO registry. 69 */ 70 private IIORegistry() { 71 super(Arrays.<Class<?>> asList(CATEGORIES).iterator()); 72 registerBuiltinSpis(); 73 registerApplicationClasspathSpis(); 74 } 75 76 /** 77 * Register built-in SPIs. 78 */ 79 private void registerBuiltinSpis() { 80 registerServiceProvider(new JPEGImageWriterSpi()); 81 registerServiceProvider(new JPEGImageReaderSpi()); 82 registerServiceProvider(new PNGImageReaderSpi()); 83 registerServiceProvider(new PNGImageWriterSpi()); 84 registerServiceProvider(new FileIOSSpi()); 85 registerServiceProvider(new FileIISSpi()); 86 registerServiceProvider(new RAFIOSSpi()); 87 registerServiceProvider(new RAFIISSpi()); 88 registerServiceProvider(new OutputStreamIOSSpi()); 89 registerServiceProvider(new InputStreamIISSpi()); 90 // -- TODO implement 91 } 92 93 /** 94 * Gets the default IIORegistry instance. 95 * 96 * @return the default IIORegistry instance. 97 */ 98 public static IIORegistry getDefaultInstance() { 99 // TODO implement own instance for each ThreadGroup (see also 100 // ThreadLocal) 101 synchronized (IIORegistry.class) { 102 if (instance == null) { 103 instance = new IIORegistry(); 104 } 105 return instance; 106 } 107 } 108 109 /** 110 * Registers all service providers from the application class path. 111 */ 112 public void registerApplicationClasspathSpis() { 113 // -- TODO implement for non-builtin plugins 114 } 115} 116