public abstract class ServiceProvider extends Object
All the methods in this class are safe to use by multiple concurrent threads.
Modifier | Constructor | Description |
---|---|---|
protected |
ServiceProvider() |
Creates a new service provider.
|
Modifier and Type | Method | Description |
---|---|---|
static List<ServiceProvider> |
available() |
Returns the list of all service providers available for the current thread's context class loader.
|
static ServiceProvider |
current() |
Returns the current
ServiceProvider . |
abstract FormatService |
getFormatService() |
|
int |
getPriority() |
Allows to define a priority for a registered
ServiceProvider instance. |
abstract <Q extends Quantity<Q>> |
getQuantityFactory(Class<Q> quantity) |
Returns a factory for the given
Quantity type. |
abstract SystemOfUnitsService |
getSystemOfUnitsService() |
Returns the service to obtain a
SystemOfUnits , or null if none. |
abstract UnitFormatService |
getUnitFormatService() |
Deprecated.
Use
getFormatService() . This method will be removed in a future version, it is here for backward compatibility only. |
static ServiceProvider |
of(String name) |
Returns the
ServiceProvider with the specified name. |
static ServiceProvider |
setCurrent(ServiceProvider provider) |
Replaces the current
ServiceProvider . |
protected ServiceProvider()
public int getPriority()
ServiceProvider
instance.
When multiple providers are registered in the system, the provider with the highest priority value is taken.
If the annotation (from JSR-250) is present on the ServiceProvider
implementation class, then that annotation is taken and this getPriority()
method is ignored.
Otherwise – if the Priority
annotation is absent – this method is used as a fallback.
public abstract SystemOfUnitsService getSystemOfUnitsService()
SystemOfUnits
, or null
if none.SystemOfUnits
, or null
.@Deprecated public abstract UnitFormatService getUnitFormatService()
getFormatService()
. This method will be removed in a future version, it is here for backward compatibility only.UnitFormat
, or null
if none.UnitFormat
, or null
.public abstract FormatService getFormatService()
UnitFormat
and QuantityFormat
, or null
.public abstract <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory(Class<Q> quantity)
Quantity
type.Q
- the type of the Quantity
instances created by the factoryquantity
- the quantity typeQuantityFactory
for the given typepublic static final List<ServiceProvider> available()
public static ServiceProvider of(String name)
ServiceProvider
with the specified name.
The given name must match the name of at least one service provider available in the current thread's
context class loader. The service provider names are the values of annotations
when present, or the value of Object.toString()
method for providers without Named
annotation.
Implementors are encouraged to provide an Named
annotation or to override Object.toString()
and use a unique enough name, e.g. the class name or other distinct attributes.
Should multiple service providers nevertheless use the same name, the one with the highest
priority wins.
name
- the name of the service provider to returnServiceProvider
with the specified nameIllegalArgumentException
- if available service providers do not contain a provider with the specified nameNullPointerException
- if name
is nullObject.toString()
public static final ServiceProvider current()
ServiceProvider
. If necessary the ServiceProvider
will be lazily loaded.
If there are no providers available, an IllegalStateException is thrown.
Otherwise the provider with the highest priority is used
or the one explicitly designated via setCurrent(ServiceProvider)
.
ServiceProvider
used.IllegalStateException
- if no ServiceProvider
has been found.getPriority()
,
setCurrent(ServiceProvider)
public static final ServiceProvider setCurrent(ServiceProvider provider)
ServiceProvider
.provider
- the new ServiceProvider
Copyright © 2014–2019 Jean-Marie Dautelle, Werner Keil, Otavio Santana. All rights reserved.