javax.tools.diagnostics
Class FactoryRegistry

java.lang.Object
  extended by javax.tools.diagnostics.FactoryRegistry
All Implemented Interfaces:
java.lang.Iterable<ImageFactory>

public class FactoryRegistry
extends java.lang.Object
implements java.lang.Iterable<ImageFactory>

Experimental addition to the API.

This class provides a central registry for image factories

Image factories can be registered directly using the #addFactory() method.

The default registry obtained by calling getDefaultRegistry() uses ServiceRegistry to discover ImageFactory implementations.

To register an ImageFactory implementation that can be discovered by the registry do the following :


Constructor Summary
FactoryRegistry()
           Creates an empty registry.
 
Method Summary
 boolean addFactory(ImageFactory factory)
           Adds an ImageFactory to the registry instance If the factory instance is already in the registry it is not added again.
static FactoryRegistry getDefaultRegistry()
           Returns the default registry.
 ImageFactory[] getFactories()
           Always returns an array even if the registry is empty
 Image getImage(java.io.File file)
           Returns an appropriate Image for the provide file by locating the first registered image factory that can handle the case insensitive file name extension of the provided file.
 JavaRuntime getJavaRuntime(java.io.File file)
           Returns an appropriate Image for the provide file by locating the first registered image factory that can handle the case insensitive file name extension of the provided file.
 java.util.Iterator<ImageFactory> iterator()
           Returns an Iterator of ImageFactories registered to this registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FactoryRegistry

public FactoryRegistry()

Creates an empty registry. To obtain an populated registry use the getDefaultRegistry() method

Method Detail

getDefaultRegistry

public static FactoryRegistry getDefaultRegistry()

Returns the default registry. This registy is preloaded with ImageFactory implementations discovered using the ServiceRegistry

Returns:
default image factory

iterator

public java.util.Iterator<ImageFactory> iterator()

Returns an Iterator of ImageFactories registered to this registry.

Specified by:
iterator in interface java.lang.Iterable<ImageFactory>

addFactory

public boolean addFactory(ImageFactory factory)

Adds an ImageFactory to the registry instance If the factory instance is already in the registry it is not added again.

Parameters:
factory - factory to add to registry
Returns:
true if factory added
Throws:
IllegalArgument - if factory is null

getFactories

public ImageFactory[] getFactories()

Always returns an array even if the registry is empty

Returns:
Returns the factories in the registry as an array

getImage

public Image getImage(java.io.File file)
               throws java.io.IOException

Returns an appropriate Image for the provide file by locating the first registered image factory that can handle the case insensitive file name extension of the provided file. If no factory can be found to handle the file then null is returned.

File names without extension will always return null

Parameters:
file - to create image from
Returns:
Image or null
Throws:
java.lang.IllegalArgumentException - if file is null
java.io.IOException - if errors occur during image creation

getJavaRuntime

public JavaRuntime getJavaRuntime(java.io.File file)
                           throws java.io.IOException

Returns an appropriate Image for the provide file by locating the first registered image factory that can handle the case insensitive file name extension of the provided file. If no factory can be found to handle the file then null is returned.

File names without extension will always return null

Parameters:
file - to create image from
Returns:
Image or null
Throws:
java.lang.IllegalArgumentException - if file is null
java.io.IOException - if errors occur during image creation


Copyright © 2010. All Rights Reserved.