Additional top-level classes in compilation unit: SubRegistry, FilterIterator.
Service providers are stored in one or more categories,
each of which is defined by a class or interface (described by a
Class object) that all of its members must implement.
The set of categories supported by this class is limited to the following standard Image I/O service types:
An attempt to load a provider that is not a subtype of one of the
above types will result in IllegalArgumentException.
For the general mechanism to load service providers, see
ServiceLoader, which is
the underlying standard mechanism used by this class.
Only a single instance of a given leaf class (that is, the
actual class returned by getClass(), as opposed to any
inherited classes or interfaces) may be registered. That is,
suppose that the
com.mycompany.mypkg.GreenImageReaderProvider class
is a subclass of javax.imageio.spi.ImageReaderSpi.
If a GreenImageReaderProvider instance is
registered, it will be stored in the category defined by the
ImageReaderSpi class. If a new instance of
GreenImageReaderProvider is registered, it will replace
the previous instance. In practice, service provider objects are
usually singletons so this behavior is appropriate.
The service provider classes should be lightweight and quick to load. Implementations of these interfaces should avoid complex dependencies on other classes and on native code. The usual pattern for more complex services is to register a lightweight proxy for the heavyweight service.
An application may customize the contents of a registry as it sees fit.
For information on how to create and deploy service providers,
refer to the documentation on ServiceLoader
RegisterableService, java.util.ServiceLoader
| Modifier and Type | Class and Description |
|---|---|
| public static interface | ServiceRegistry.
A simple filter interface used by
|
| Modifier and Type | Field and Description |
|---|---|
| private Map |
| Access | Constructor and Description |
|---|---|
| public | ServiceRegistry(Iterator<Class<?>>
an categories)Iterator containing
Class objects to be used to define categories.Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| private static void | checkClassAllowed(Class<?> clazz)
Checks whether the provided class is one of the allowed ImageIO service provider classes. |
| public boolean | |
| public void | deregisterAll(Class<?>
the category to be emptied. category)Deregisters all service provider object currently registered under the given category. |
| public void | |
| public < the type of the provider. T> boolean | Returns: true if the provider was previously
registered in the same category category,
false otherwise.the service provider object to be deregistered. provider, Class<T> the category from which to deregister the
provider. category)Removes a service provider object from the given category. |
| public void | deregisterServiceProvider(Object
the service provider object to be deregistered. provider)Removes a service provider object from all categories that contain it. |
| public Iterator | Returns: anIterator containing
Class objects.Returns an |
| public < the type of the provider. T> T | Returns: a currently registered service provider object with the desiredClass type, or null is none is
present.the providerClass)Class of the desired
service provider object.Returns the currently registered service provider object that is of the given class type. |
| public < the type of the category. T> Iterator | Returns: anIterator containing service provider
objects from the given category, possibly in order.the category to be retrieved from. category, boolean true if pairwise orderings
should be taken account in ordering the returned objects.Returns an |
| public < the type of the category. T> Iterator | Returns: anIterator containing service provider
objects from the given category, possibly in order.the category to be retrieved from. category, ServiceRegistry.an instance of filter,ServiceRegistry.Filter
whose filter method will be invoked.true if pairwise orderings
should be taken account in ordering the returned objects.Returns an |
| private Iterator | getSubRegistries(Object provider)
Returns an Iterator containing the subregistries to which the provider belongs. |
| public static < the type of the providerClass. T> Iterator | Returns: AnIterator that yields provider objects
for the given service, in some arbitrary order. The iterator
will throw an Error if a provider-configuration
file violates the specified format or if a provider class
cannot be found and instantiated.a providerClass, ClassLoader Class object indicating the
class or interface of the service providers being detected.the class loader to be used to load
provider-configuration files and instantiate provider classes,
or loader)null if the system class loader (or, failing that
the bootstrap class loader) is to be used.Searches for implementations of a particular service class using the given class loader. |
| public static < the type of the providerClass. T> Iterator | Returns: AnIterator that yields provider objects
for the given service, in some arbitrary order. The iterator
will throw an Error if a provider-configuration
file violates the specified format or if a provider class
cannot be found and instantiated.a providerClass)Class object indicating the
class or interface of the service providers being detected.Locates and incrementally instantiates the available providers of a given service using the context class loader. |
| public < the type of the provider. T> boolean | Returns: true if no provider of the same class was previously registered in the same category category.the service provide object to be registered. provider, Class<T> the category under which to register the
provider. category)Adds a service provider object to the registry. |
| public void | registerServiceProvider(Object
the service provider object to be registered. provider)Adds a service provider object to the registry. |
| public void | registerServiceProviders(Iterator<?>
an Iterator containing service provider
objects to be registered. providers)Adds a set of service provider objects, taken from an
|
| public < the type of the category. T> boolean | Returns: true if a previously unset ordering
was established.a category, T Class object indicating the
category under which the preference is to be established.the preferred provider. firstProvider, T the provider to which
secondProvider)firstProvider is preferred.Sets a pairwise ordering between two service provider objects within a given category. |
| public < the type of the category. T> boolean | Returns: true if a previously set ordering was
disestablished.a category, T Class object indicating the
category under which the preference is to be disestablished.the formerly preferred provider. firstProvider, T the provider to which
secondProvider)firstProvider was formerly preferred.Sets a pairwise ordering between two service provider objects within a given category. |
| categoryMap | back to summary |
|---|---|
| private Map<Class<?>, SubRegistry> categoryMap | |
| ServiceRegistry | back to summary |
|---|---|
| public ServiceRegistry(Iterator<Class<?>> categories) Constructs a
| |
| checkClassAllowed | back to summary |
|---|---|
| private static void checkClassAllowed(Class<?> clazz) Checks whether the provided class is one of the allowed ImageIO service provider classes. If it is, returns normally. If it is not, throws IllegalArgumentException.
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object provider) Returns
| |
| deregisterAll | back to summary |
|---|---|
| public void deregisterAll(Class<?> category) Deregisters all service provider object currently registered under the given category.
| |
| deregisterAll | back to summary |
|---|---|
| public void deregisterAll() Deregisters all currently registered service providers from all categories.
If an application creates a new | |
| deregisterServiceProvider | back to summary |
|---|---|
| public <T> boolean deregisterServiceProvider(T provider, Class<T> category) Removes a service provider object from the given category. If
the provider was not previously registered, nothing happens and
If
| |
| deregisterServiceProvider | back to summary |
|---|---|
| public void deregisterServiceProvider(Object provider) Removes a service provider object from all categories that contain it.
| |
| getCategories | back to summary |
|---|---|
| public Iterator Returns an | |
| getServiceProviderByClass | back to summary |
|---|---|
| public <T> T getServiceProviderByClass(Class<T> providerClass) Returns the currently registered service provider object that
is of the given class type. At most one object of a given
class is allowed to be registered at any given time. If no
registered object has the desired class type,
| |
| getServiceProviders | back to summary |
|---|---|
| public <T> Iterator Returns an
| |
| getServiceProviders | back to summary |
|---|---|
| public <T> Iterator Returns an The
| |
| getSubRegistries | back to summary |
|---|---|
| private Iterator Returns an Iterator containing the subregistries to which the provider belongs. | |
| lookupProviders | back to summary |
|---|---|
| public static <T> Iterator Searches for implementations of a particular service class using the given class loader. The service class must be one of the service types listed
in the class specification. If it is not, This method transforms the name of the given service class
into a provider-configuration filename as described in the
class comment and then uses the Because it is possible for extensions to be installed into a running Java virtual machine, this method may return different results each time it is invoked.
| |
| lookupProviders | back to summary |
|---|---|
| public static <T> Iterator Locates and incrementally instantiates the available providers of a given service using the context class loader. This convenience method is equivalent to: ClassLoader cl = Thread.currentThread().getContextClassLoader(); return Service.providers(service, cl); The service class must be one of the service types listed
in the class specification. If it is not,
| |
| registerServiceProvider | back to summary |
|---|---|
| public <T> boolean registerServiceProvider(T provider, Class<T> category) Adds a service provider object to the registry. The provider is associated with the given category. If
| |
| registerServiceProvider | back to summary |
|---|---|
| public void registerServiceProvider(Object provider) Adds a service provider object to the registry. The provider
is associated within each category present in the registry
whose If
| |
| registerServiceProviders | back to summary |
|---|---|
| public void registerServiceProviders(Iterator<?> providers) Adds a set of service provider objects, taken from an
For each entry of
| |
| setOrdering | back to summary |
|---|---|
| public <T> boolean setOrdering(Class<T> category, T firstProvider, T secondProvider) Sets a pairwise ordering between two service provider objects
within a given category. If one or both objects are not
currently registered within the given category, or if the
desired ordering is already set, nothing happens and
The ordering will be used by the
| |
| unsetOrdering | back to summary |
|---|---|
| public <T> boolean unsetOrdering(Class<T> category, T firstProvider, T secondProvider) Sets a pairwise ordering between two service provider objects
within a given category. If one or both objects are not
currently registered within the given category, or if no
ordering is currently set between them, nothing happens
and The ordering will be used by the
| |
ServiceRegistry.getServiceProviders to select
providers matching an arbitrary criterion. Classes that
implement this interface should be defined in order to make use
of the getServiceProviders method of
ServiceRegistry that takes a Filter.
| Modifier and Type | Method and Description |
|---|---|
| public boolean |
| filter | back to summary |
|---|---|
| public boolean filter(Object provider) Returns
| |