FileDocCategorySizeDatePackage
IIORegistry.javaAPI DocJava SE 5 API7430Fri Aug 26 14:57:30 BST 2005javax.imageio.spi

IIORegistry

public final class IIORegistry extends ServiceRegistry
A registry for service provider instances. Service provider classes may be detected at run time by means of meta-information in the JAR files containing them. The intent is that it be relatively inexpensive to load and inspect all available service provider classes. These classes may them be used to locate and instantiate more heavyweight classes that will perform actual work, in this case instances of ImageReader, ImageWriter, ImageTranscoder, ImageInputStream, and ImageOutputStream.

Service providers found on the system classpath (e.g., the jre/lib/ext directory in Sun's implementation of JDK) are automatically loaded as soon as this class is instantiated.

When the registerApplicationClasspathSpis method is called, service provider instances declared in the meta-information section of JAR files on the application class path are loaded. To declare a service provider, a services subdirectory is placed within the META-INF directory that is present in every JAR file. This directory contains a file for each service provider interface that has one or more implementation classes present in the JAR file. For example, if the JAR file contained a class named com.mycompany.imageio.MyFormatReaderSpi which implements the ImageReaderSpi interface, the JAR file would contain a file named:

META-INF/services/javax.imageio.spi.ImageReaderSpi
containing the line:
com.mycompany.imageio.MyFormatReaderSpi

The service provider classes are intended to be lightweight and quick to load. Implementations of these interfaces should avoid complex dependencies on other classes and on native code.

It is also possible to manually add service providers not found automatically, as well as to remove those that are using the interfaces of the ServiceRegistry class. Thus the application may customize the contents of the registry as it sees fit.

For more details on declaring service providers, and the JAR format in general, see the JAR File Specification.

version
0.5

Fields Summary
private static final Vector
initialCategories
A Vector containing the valid IIO registry categories (superinterfaces) to be used in the constructor.
Constructors Summary
private IIORegistry()
Set up the valid service provider categories and automatically register all available service providers.

The constructor is private in order to prevent creation of additional instances.


     
        initialCategories.add(ImageReaderSpi.class);
        initialCategories.add(ImageWriterSpi.class);
        initialCategories.add(ImageTranscoderSpi.class);
        initialCategories.add(ImageInputStreamSpi.class);
        initialCategories.add(ImageOutputStreamSpi.class);
    
        super(initialCategories.iterator());
        registerStandardSpis();
        registerApplicationClasspathSpis();
    
Methods Summary
public static javax.imageio.spi.IIORegistrygetDefaultInstance()
Returns the default IIORegistry instance used by the Image I/O API. This instance should be used for all registry functions.

Each ThreadGroup will receive its own instance; this allows different Applets in the same browser (for example) to each have their own registry.

return
the default registry for the current ThreadGroup.

        AppContext context = AppContext.getAppContext();
        IIORegistry registry =
            (IIORegistry)context.get(IIORegistry.class);
        if (registry == null) {
            // Create an instance for this AppContext
            registry = new IIORegistry();
            context.put(IIORegistry.class, registry);
        }
        return registry;
    
public voidregisterApplicationClasspathSpis()
Registers all available service providers found on the application class path, using the default ClassLoader. This method is typically invoked by the ImageIO.scanForPlugins method.

see
javax.imageio.ImageIO#scanForPlugins
see
ClassLoader#getResources

        // FIX: load only from application classpath
        
	ClassLoader loader = Thread.currentThread().getContextClassLoader();

        Iterator categories = getCategories();
        while (categories.hasNext()) {
            Class c = (Class)categories.next();
            Iterator riter = Service.providers(c, loader);
            while (riter.hasNext()) {
                IIOServiceProvider r = (IIOServiceProvider)riter.next();
                registerServiceProvider(r);
            }
        }
    
private voidregisterStandardSpis()

        // Hardwire standard SPIs
        registerServiceProvider(new GIFImageReaderSpi());
        registerServiceProvider(new BMPImageReaderSpi());
        registerServiceProvider(new BMPImageWriterSpi());
        registerServiceProvider(new WBMPImageReaderSpi());
        registerServiceProvider(new WBMPImageWriterSpi());
        registerServiceProvider(new PNGImageReaderSpi());
        registerServiceProvider(new PNGImageWriterSpi());
        registerServiceProvider(new JPEGImageReaderSpi());
        registerServiceProvider(new JPEGImageWriterSpi());
        registerServiceProvider(new FileImageInputStreamSpi());
        registerServiceProvider(new FileImageOutputStreamSpi());
        registerServiceProvider(new InputStreamImageInputStreamSpi());
        registerServiceProvider(new OutputStreamImageOutputStreamSpi());
        registerServiceProvider(new RAFImageInputStreamSpi());
        registerServiceProvider(new RAFImageOutputStreamSpi());