|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.imageio.spi.ServiceRegistry
public class ServiceRegistry
A registry for service providers.
Nested Class Summary | |
---|---|
static interface |
ServiceRegistry.Filter
A filter for selecting service providers that match custom criteria. |
Constructor Summary | |
---|---|
ServiceRegistry(Iterator<Class<?>> categories)
Constructs a ServiceRegistry for the specified
service categories. |
Method Summary | ||
---|---|---|
boolean |
contains(Object provider)
Determines whether a provider has been registered with this registry. |
|
void |
deregisterAll()
De-registers all service providers. |
|
void |
deregisterAll(Class<?> category)
De-registers all providers which have been registered for the specified service category. |
|
void |
deregisterServiceProvider(Object provider)
De-registers a provider from all service categories it implements. |
|
|
deregisterServiceProvider(T provider,
Class<T> category)
De-registers a provider for the specified service category. |
|
void |
finalize()
Called by the Virtual Machine when it detects that this ServiceRegistry has become garbage. |
|
Iterator<Class<?>> |
getCategories()
Returns an iterator over all service categories. |
|
|
getServiceProviderByClass(Class<T> providerClass)
Returns one of the service providers that is a subclass of the specified class. |
|
|
getServiceProviders(Class<T> category,
boolean useOrdering)
Retrieves all providers that have been registered for the specified service category. |
|
|
getServiceProviders(Class<T> category,
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. |
|
static
|
lookupProviders(Class<T> spi)
Finds service providers that are implementing the specified Service Provider Interface, using the context class loader for loading providers. |
|
static
|
lookupProviders(Class<T> spi,
ClassLoader loader)
Finds service providers that are implementing the specified Service Provider Interface. |
|
void |
registerServiceProvider(Object provider)
Registers a provider under all service categories it implements. |
|
|
registerServiceProvider(T provider,
Class<T> category)
Registers a provider for the specified service category. |
|
void |
registerServiceProviders(Iterator<?> providers)
Registers a number of providers under all service categories they implement. |
|
|
setOrdering(Class<T> category,
T firstProvider,
T secondProvider)
Adds an ordering constraint on service providers. |
|
|
unsetOrdering(Class<T> category,
T firstProvider,
T secondProvider)
Removes an ordering constraint on service providers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServiceRegistry(Iterator<Class<?>> categories)
ServiceRegistry
for the specified
service categories.
categories
- the categories to support
IllegalArgumentException
- if categories
is
null
, or if its Iterator.next()
method
returns null
.
ClassCastException
- if categories
does not
iterate over instances of Class
.Method Detail |
---|
public static <T> Iterator<T> lookupProviders(Class<T> spi, ClassLoader loader)
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
is
null
. When lookupProviders
is called,
the current AccessControlContext
gets
recorded. This captured security context will determine the
permissions when services get loaded via the next()
method of the returned Iterator
.
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, or null
for the system class
loader. For using the context class loader, see lookupProviders(Class)
.
spi
.
IllegalArgumentException
- if spi
is
null
.public static <T> Iterator<T> lookupProviders(Class<T> spi)
spi
- the service provider interface which must be
implemented by any loaded service providers.
spi
.
IllegalArgumentException
- if spi
is
null
.lookupProviders(Class, ClassLoader)
public Iterator<Class<?>> getCategories()
Iterator
<Class
>.public <T> boolean registerServiceProvider(T provider, Class<T> category)
If provider
implements the RegisterableService
interface, its onRegistration
method is
invoked in order to inform the provider about the addition to
this registry.
provider
- the service provider to be registered.category
- the service category under which
provider
shall be registered.
true
if provider
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.
IllegalArgumentException
- if provider
is
null
, or if category
is not among the
categories passed to the constructor of this ServiceRegistry.
ClassCastException
- if provider
does not
implement category
.public void registerServiceProvider(Object provider)
If provider
implements the RegisterableService
interface, its onRegistration
method is
invoked in order to inform the provider about the addition to
this registry. If provider
implements several
service categories, onRegistration
gets called
multiple times.
provider
- the service provider to be registered.
IllegalArgumentException
- if provider
is
null
, or if provider
does not implement
any of the service categories passed to the constructor of this ServiceRegistry.public void registerServiceProviders(Iterator<?> providers)
If a provider implements the RegisterableService
interface, its onRegistration
method is invoked in order to inform the provider
about the addition to this registry. If provider
implements several service categories,
onRegistration
gets called multiple times.
IllegalArgumentException
- if providers
is
null
, if any iterated provider is null
,
or if some iterated provider does not implement any of the
service categories passed to the constructor of this
ServiceRegistry
.public <T> boolean deregisterServiceProvider(T provider, Class<T> category)
If provider
implements the RegisterableService
interface, its onDeregistration
method is
invoked in order to inform the provider about the removal from
this registry.
provider
- the service provider to be de-registered.category
- the service category from which
provider
shall be de-registered.
true
if provider
was previously
registered for the specified service category; false
if if the provider had not been registered.
IllegalArgumentException
- if provider
is
null
, or if category
is not among the
categories passed to the constructor of this ServiceRegistry.
ClassCastException
- if provider
does not
implement category
.public void deregisterServiceProvider(Object provider)
If provider
implements the RegisterableService
interface, its onDeregistration
method is
invoked in order to inform the provider about the removal from
this registry. If provider
implements several
service categories, onDeregistration
gets called
multiple times.
provider
- the service provider to be de-registered.
IllegalArgumentException
- if provider
is
null
, or if provider
does not implement
any of the service categories passed to the constructor of this
ServiceRegistry
.public void deregisterAll(Class<?> category)
If a provider implements the RegisterableService
interface, its onDeregistration
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.
category
- the category whose registered providers will be
de-registered.
IllegalArgumentException
- if category
is not
among the categories passed to the constructor of this
ServiceRegistry
.public void deregisterAll()
If a provider implements the RegisterableService
interface, its onDeregistration
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 finalize() throws Throwable
ServiceRegistry
has become garbage. De-registers all
service providers, which will cause those that implement RegisterableService
to receive a onDeregistration
notification.
finalize
in class Object
Throwable
- permits a subclass to throw anything in an
overridden version; but the default throws nothingSystem.gc()
,
System.runFinalizersOnExit(boolean)
,
java.lang.ref
public boolean contains(Object provider)
true
if provider
has been
registered under any service category; false
if
it is not registered.
IllegalArgumentException
- if provider
is
null
.public <T> Iterator<T> getServiceProviders(Class<T> category, boolean useOrdering)
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.
IllegalArgumentException
- if category
is not
among the categories passed to the constructor of this
ServiceRegistry
.getServiceProviders(Class, Filter, boolean)
public <T> Iterator<T> getServiceProviders(Class<T> category, ServiceRegistry.Filter filter, boolean useOrdering)
category
- the service category whose providers are
to be retrieved.filter
- a custom filter, or null
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.
IllegalArgumentException
- if category
is not
among the categories passed to the constructor of this
ServiceRegistry
.public <T> T getServiceProviderByClass(Class<T> providerClass)
providerClass
- a class to search for.public <T> boolean setOrdering(Class<T> category, T firstProvider, T secondProvider)
category
- the service category to which an ordering
constraint is to be added.firstProvider
- the provider which is supposed to come before
second
.secondProvider
- the provider which is supposed to come after
first
.
IllegalArgumentException
- if first
and
second
are referring to the same object, or if one
of them is null
.unsetOrdering(java.lang.Class, T, T)
,
getServiceProviders(Class, Filter, boolean)
public <T> boolean unsetOrdering(Class<T> category, T firstProvider, T secondProvider)
category
- the service category from which an ordering
constraint is to be removed.firstProvider
- the provider which is supposed to come before
second
.secondProvider
- the provider which is supposed to come after
first
.
IllegalArgumentException
- if first
and
second
are referring to the same object, or if one
of them is null
.setOrdering(java.lang.Class, T, T)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |