|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectServiceRegistry
FactoryRegistry
@NotThreadSafe public class FactoryRegistry
A registry for factories organized by categories. A category is an interface for a
service as described in the package javadoc.
FactoryRegistry extends ServiceRegistry with the following functionalities:
A scanForPlugins() method that scans for plugins in
the registry class loader,
the thread context class loader and
the system class loader.
When more than one implementation is available for the same Factory subclass,
an optional set of hints can specifies the criterion that the desired
implementation must meets. If a factory implementation depends on other factories, the
dependencies hints are checked recursively.
Optionally, if no factory matches the given hints, a new instance can be automatically created.
NOTE: This class is not thread safe. Users are responsible
for synchronization. This is usually done in an utility class wrapping this
service registry (e.g. FactoryFinder).
Factory,
Hints
| utility/geotk-utility (download) | View source code for this class |
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class ServiceRegistry |
|---|
ServiceRegistry.Filter |
| Field Summary | |
|---|---|
protected static Logger |
LOGGER
The logger for all events related to factory registry. |
| Constructor Summary | |
|---|---|
FactoryRegistry(Class<?> category)
Constructs a new registry for the specified category. |
|
FactoryRegistry(Class<?>[] categories)
Constructs a new registry for the specified categories. |
|
FactoryRegistry(Collection<Class<?>> categories)
Constructs a new registry for the specified categories. |
|
| Method Summary | ||
|---|---|---|
Set<ClassLoader> |
getClassLoaders()
Returns all class loaders to be used for scanning plugins. |
|
|
getServiceProvider(Class<T> category,
ServiceRegistry.Filter filter,
Hints hints,
Hints.ClassKey key)
Returns the first provider in the registry for the specified category, using the specified map of hints (if any). |
|
|
getServiceProviders(Class<T> category,
ServiceRegistry.Filter filter,
Hints hints,
Hints.ClassKey key)
Returns the providers in the registry for the specified category, filter and hints. |
|
protected
|
isAcceptable(T provider,
Class<T> category,
Hints hints)
Returns true if the specified provider meets the requirements specified by
a map of hints. |
|
void |
scanForPlugins()
Scans for factory plug-ins on the application class path. |
|
|
setOrdering(Class<T> category,
Comparator<T> comparator)
Sets pairwise ordering between all factories according a comparator. |
|
|
setOrdering(Class<T> base,
ServiceRegistry.Filter service1,
ServiceRegistry.Filter service2)
Sets or unsets a pairwise ordering between all factories meeting a criterion. |
|
String |
toString()
Returns a string representation of this registry for debugging purpose. |
|
|
unsetOrdering(Class<T> base,
ServiceRegistry.Filter service1,
ServiceRegistry.Filter service2)
Unset an previously set ordering. |
|
| Methods inherited from class Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final Logger LOGGER
| Constructor Detail |
|---|
public FactoryRegistry(Class<?> category)
category - The single category.public FactoryRegistry(Class<?>[] categories)
categories - The categories.public FactoryRegistry(Collection<Class<?>> categories)
categories - The categories.| Method Detail |
|---|
public <T> Iterator<T> getServiceProviders(Class<T> category,
ServiceRegistry.Filter filter,
Hints hints,
Hints.ClassKey key)
T - The class represented by the category argument.category - The category to look for. Usually an interface class
(not the actual implementation class).filter - The optional filter, or null.hints - The optional user requirements, or null.key - The key to use for looking for a user-provided instance
in the hints map, or null if none.
public <T> T getServiceProvider(Class<T> category,
ServiceRegistry.Filter filter,
Hints hints,
Hints.ClassKey key)
throws FactoryRegistryException
DynamicFactoryRegistry
class change this behavior however.
T - The class represented by the category argument.category - The category to look for. Must be one of the categories declared to the
constructor. Usually an interface class (not the actual implementation
class).filter - An optional filter, or null if none.
This is used for example in order to select the first factory for some
authority.hints - A map of hints, or null if none.key - The key to use for looking for a user-provided instance in the hints, or
null if none.
Object instead of Factory
because the factory implementation doesn't need to be a Geotk one.
FactoryNotFoundException - if no factory was found for the specified category, filter
and hints.
FactoryRegistryException - if a factory can't be returned for some other reason.getServiceProviders(java.lang.Class, javax.imageio.spi.ServiceRegistry.Filter, org.geotoolkit.factory.Hints, org.geotoolkit.factory.Hints.ClassKey) ,
getServiceProvider(java.lang.Class, javax.imageio.spi.ServiceRegistry.Filter, org.geotoolkit.factory.Hints, org.geotoolkit.factory.Hints.ClassKey)
protected <T> boolean isAcceptable(T provider,
Class<T> category,
Hints hints)
true if the specified provider meets the requirements specified by
a map of hints. The default implementation always returns true. There is no
need to override this method for Factory implementations, since their hints are
automatically checked. Override this method for non-Geotk implementations.
For example a JTS geometry factory finder may overrides this method in order to check
if a com.vividsolutions.jts.geom.GeometryFactory uses the required
com.vividsolutions.jts.geom.CoordinateSequenceFactory. Such method should be
implemented as below, since this method may be invoked for various kind of objects:
if (provider instanceof GeometryFactory) {
// ... Check the GeometryFactory state here.
}
T - The class represented by the category argument.provider - The provider to check.category - The factory category. Usually an interface.hints - The user requirements, or null if none.
true if the provider meets the user requirements.public Set<ClassLoader> getClassLoaders()
The actual number of class loaders may be smaller if redundancies was found. If some more classloaders should be scanned, they shall be added into the code of this method.
public void scanForPlugins()
public <T> boolean setOrdering(Class<T> category,
Comparator<T> comparator)
compare(factory1, factory2) should returns:
-1 if factory1 is preferred to factory2+1 if factory2 is preferred to factory10 if there is no preferred order between factory1 and
factory2
T - The class represented by the category argument.category - The category to set ordering.comparator - The comparator to use for ordering.
true if at least one ordering setting has been modified as a consequence
of this call.
public <T> boolean setOrdering(Class<T> base,
ServiceRegistry.Filter service1,
ServiceRegistry.Filter service2)
T - The class represented by the base argument.base - The base category. Only categories assignable to base will be processed.service1 - Filter for the preferred factory.service2 - Filter for the factory to which service1 is preferred.
true if the ordering changed as a result of this call.
public <T> boolean unsetOrdering(Class<T> base,
ServiceRegistry.Filter service1,
ServiceRegistry.Filter service2)
T - The class represented by the base argument.base - The base category. Only categories assignable to base will be processed.service1 - Filter for the preferred factory.service2 - Filter for the factory to which service1 was preferred.
true if the ordering changed as a result of this call.public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||