Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.imageio.spi.ServiceRegistry
public class ServiceRegistry
extends Object
Nested Class Summary | |
static interface |
|
Constructor Summary | |
|
Method Summary | |
|
|
|
|
static |
|
static |
|
|
|
|
|
|
|
|
|
|
|
boolean | |
void |
|
void |
|
void |
|
void |
|
Iterator |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public ServiceRegistry(Iterator> categories)
Constructs aServiceRegistry
for the specified service categories.
- Parameters:
categories
- the categories to support
- Throws:
IllegalArgumentException
- ifcategories
isnull
, or if itsIterator.next()
method returnsnull
.ClassCastException
- ifcategories
does not iterate over instances ofClass
.
publicIterator getServiceProviders (Classcategory, boolean useOrdering)
Retrieves all providers that have been registered for the specified service category.
- Parameters:
category
- the service category whose providers are to be retrieved.useOrdering
-true
in order to retrieve the providers in an order imposed by the ordering constraints;false
in order to retrieve the providers in any order.
- Throws:
IllegalArgumentException
- ifcategory
is not among the categories passed to the constructor of thisServiceRegistry
.
- See Also:
getServiceProviders(Class, Filter, boolean)
publicIterator getServiceProviders (Classcategory, ServiceRegistry.Filter filter, boolean useOrdering)
Retrieves all providers that have been registered for the specified service category and that satisfy the criteria of a custom filter.
- Parameters:
category
- the service category whose providers are to be retrieved.filter
- a custom filter, ornull
to retrieve all registered providers for the specified category.useOrdering
-true
in order to retrieve the providers in an order imposed by the ordering constraints;false
in order to retrieve the providers in any order.
- Throws:
IllegalArgumentException
- ifcategory
is not among the categories passed to the constructor of thisServiceRegistry
.
public staticIterator lookupProviders (Classspi)
Finds service providers that are implementing the specified Service Provider Interface, using the context class loader for loading providers.
- Parameters:
spi
- the service provider interface which must be implemented by any loaded service providers.
- Returns:
- an iterator over instances of
spi
.
- Throws:
IllegalArgumentException
- ifspi
isnull
.
- See Also:
lookupProviders(Class, ClassLoader)
public staticIterator lookupProviders (Classspi, ClassLoader loader)
Finds service providers that are implementing the specified Service Provider Interface.On-demand loading: Loading and initializing service providers is delayed as much as possible. The rationale is that typical clients will iterate through the set of installed service providers until one is found that matches some criteria (like supported formats, or quality of service). In such scenarios, it might make sense to install only the frequently needed service providers on the local machine. More exotic providers can be put onto a server; the server will only be contacted when no suitable service could be found locally.
Security considerations: Any loaded service providers are loaded through the specified ClassLoader, or the system ClassLoader if
classLoader
isnull
. WhenlookupProviders
is called, the currentAccessControlContext
gets recorded. This captured security context will determine the permissions when services get loaded via thenext()
method of the returnedIterator
.
- Parameters:
spi
- the service provider interface which must be implemented by any loaded service providers.loader
- the class loader that will be used to load the service providers, ornull
for the system class loader. For using the context class loader, seelookupProviders(Class)
.
- Returns:
- an iterator over instances of
spi
.
- Throws:
IllegalArgumentException
- ifspi
isnull
.
publicT getServiceProviderByClass(Class providerClass)
Returns one of the service providers that is a subclass of the specified class.
- Parameters:
providerClass
- a class to search for.
publicboolean deregisterServiceProvider(T provider, Class category)
De-registers a provider for the specified service category.If
provider
implements theRegisterableService
interface, itsonDeregistration
method is invoked in order to inform the provider about the removal from this registry.
- Parameters:
provider
- the service provider to be de-registered.category
- the service category from whichprovider
shall be de-registered.
- Returns:
true
ifprovider
was previously registered for the specified service category;false
if if the provider had not been registered.
- Throws:
IllegalArgumentException
- ifprovider
isnull
, or ifcategory
is not among the categories passed to the constructor of this ServiceRegistry.ClassCastException
- ifprovider
does not implementcategory
.
publicboolean registerServiceProvider(T provider, Class category)
Registers a provider for the specified service category.If
provider
implements theRegisterableService
interface, itsonRegistration
method is invoked in order to inform the provider about the addition to this registry.
- Parameters:
provider
- the service provider to be registered.category
- the service category under whichprovider
shall be registered.
- Returns:
true
ifprovider
is the first provider that gets registered for the specified service category;false
if other providers have already been registered for the same servide category.
- Throws:
IllegalArgumentException
- ifprovider
isnull
, or ifcategory
is not among the categories passed to the constructor of this ServiceRegistry.ClassCastException
- ifprovider
does not implementcategory
.
publicboolean setOrdering(Class category, T firstProvider, T secondProvider)
Adds an ordering constraint on service providers.
- Parameters:
category
- the service category to which an ordering constraint is to be added.firstProvider
- the provider which is supposed to come beforesecond
.secondProvider
- the provider which is supposed to come afterfirst
.
- Throws:
IllegalArgumentException
- iffirst
andsecond
are referring to the same object, or if one of them isnull
.
- See Also:
ServiceRegistry
,getServiceProviders(Class, Filter, boolean)
publicboolean unsetOrdering(Class category, T firstProvider, T secondProvider)
Removes an ordering constraint on service providers.
- Parameters:
category
- the service category from which an ordering constraint is to be removed.firstProvider
- the provider which is supposed to come beforesecond
.secondProvider
- the provider which is supposed to come afterfirst
.
- Throws:
IllegalArgumentException
- iffirst
andsecond
are referring to the same object, or if one of them isnull
.
- See Also:
ServiceRegistry
public boolean contains(Object provider)
Determines whether a provider has been registered with this registry.
- Returns:
true
ifprovider
has been registered under any service category;false
if it is not registered.
- Throws:
IllegalArgumentException
- ifprovider
isnull
.
public void deregisterAll()
De-registers all service providers.If a provider implements the
RegisterableService
interface, itsonDeregistration
method is invoked in order to inform the provider about the removal from this registry. If the provider implements several service categories,onDeregistration
gets called multiple times.
public void deregisterAll(Class category)
De-registers all providers which have been registered for the specified service category.If a provider implements the
RegisterableService
interface, itsonDeregistration
method is invoked in order to inform the provider about the removal from this registry. If the provider implements several service categories,onDeregistration
gets called multiple times.
- Parameters:
category
- the category whose registered providers will be de-registered.
- Throws:
IllegalArgumentException
- ifcategory
is not among the categories passed to the constructor of thisServiceRegistry
.
public void deregisterServiceProvider(Object provider)
De-registers a provider from all service categories it implements.If
provider
implements theRegisterableService
interface, itsonDeregistration
method is invoked in order to inform the provider about the removal from this registry. Ifprovider
implements several service categories,onDeregistration
gets called multiple times.
- Parameters:
provider
- the service provider to be de-registered.
- Throws:
IllegalArgumentException
- ifprovider
isnull
, or ifprovider
does not implement any of the service categories passed to the constructor of thisServiceRegistry
.
public void finalize() throws Throwable
Called by the Virtual Machine when it detects that thisServiceRegistry
has become garbage. De-registers all service providers, which will cause those that implementRegisterableService
to receive aonDeregistration
notification.
public void registerServiceProvider(Object provider)
Registers a provider under all service categories it implements.If
provider
implements theRegisterableService
interface, itsonRegistration
method is invoked in order to inform the provider about the addition to this registry. Ifprovider
implements several service categories,onRegistration
gets called multiple times.
- Parameters:
provider
- the service provider to be registered.
- Throws:
IllegalArgumentException
- ifprovider
isnull
, or ifprovider
does not implement any of the service categories passed to the constructor of this ServiceRegistry.
public void registerServiceProviders(Iterator providers)
Registers a number of providers under all service categories they implement.If a provider implements the
RegisterableService
interface, itsonRegistration
method is invoked in order to inform the provider about the addition to this registry. Ifprovider
implements several service categories,onRegistration
gets called multiple times.
- Throws:
IllegalArgumentException
- ifproviders
isnull
, if any iterated provider isnull
, or if some iterated provider does not implement any of the service categories passed to the constructor of thisServiceRegistry
.