| java.lang.Object javax.imageio.spi.ServiceRegistry org.geotools.factory.FactoryRegistry
All known Subclasses: org.geotools.factory.FactoryCreator,
FactoryRegistry | public class FactoryRegistry extends ServiceRegistry (Code) | | A registry for factories, organized by categories (usualy by interface).
For example
org.opengis.referencing.crs.CRSFactory .class is a category,
and
org.opengis.referencing.operation.MathTransformFactory .class
is an other category.
For each category, implementations are registered in a file placed in the
META-INF/services/ directory, as specified in the
ServiceRegistry javadoc. Those files are usually bundled into the JAR file distributed by the vendor.
If the same
META-INF/services/ file appears many time in different JARs,
they are processed as if their content were merged.
Example use:
Set categories = Collections.singleton(new Class[] {MathTransformProvider.class});
FactoryRegistry registry = new FactoryRegistry(categories);
// get the providers
Filter filter = null;
Hints hints = null;
Iterator providers =
registry.getServiceProviders(MathTransformProvider.class, filter, hints);
NOTE: This class is not thread safe. Users are responsable
for synchronisation. This is usually done in an utility class wrapping this
service registry (e.g.
org.geotools.referencing.ReferencingFactoryFinder ).
since: 2.1 version: $Id: FactoryRegistry.java 29058 2008-02-03 17:47:07Z desruisseaux $ author: Martin Desruisseaux author: Richard Gould author: Jody Garnett See Also: org.geotools.referencing.FactoryFinder See Also: org.geotools.coverage.FactoryFinder |
Field Summary | |
final protected static Logger | LOGGER The logger for all events related to factory registry. |
Method Summary | |
List | getCachedProviders(Class category) Returns the providers available in the cache, or
null if none. | final public Set | getClassLoaders() Returns all class loaders to be used for scanning plugins. | public Object | getServiceProvider(Class category, Filter filter, Hints hints, Hints.Key key) Returns the first provider in the registry for the specified category, using the specified
map of hints (if any). | public Iterator | getServiceProviders(Class category) Returns the providers in the registry for the specified category. | public Iterator | getServiceProviders(Class category, Filter filter, Hints hints) Returns the providers in the registry for the specified category, filter and hints.
Providers that are not
will be
ignored. | final Iterator | getUnfilteredProviders(Class category) Implementation of
FactoryRegistry.getServiceProviders(Class,Filter,Hints) without the filtering
applied by the
FactoryRegistry.isAcceptable(Object,Class,Hints,Filter) method. | final boolean | isAcceptable(Object candidate, Class category, Hints hints, Filter filter) Returns
true is the specified
factory meets the requirements specified by
a map of
hints and the filter. | protected boolean | isAcceptable(Object provider, Class category, Hints hints) Returns
true if the specified
provider meets the requirements specified by
a map of
hints . | public void | scanForPlugins() Scans for factory plug-ins on the application class path. | public boolean | setOrdering(Class category, Comparator comparator) Set pairwise ordering between all factories according a comparator. | public boolean | setOrdering(Class base, boolean set, Filter service1, Filter service2) Sets or unsets a pairwise ordering between all factories meeting a criterion. |
LOGGER | final protected static Logger LOGGER(Code) | | The logger for all events related to factory registry.
|
FactoryRegistry | public FactoryRegistry(Class category)(Code) | | Constructs a new registry for the specified category.
Parameters: category - The single category. since: 2.4 |
FactoryRegistry | public FactoryRegistry(Class[] categories)(Code) | | Constructs a new registry for the specified categories.
Parameters: categories - The categories. since: 2.4 |
FactoryRegistry | public FactoryRegistry(Collection categories)(Code) | | Constructs a new registry for the specified categories.
Parameters: categories - The categories. |
getCachedProviders | List getCachedProviders(Class category)(Code) | | Returns the providers available in the cache, or
null if none.
To be overridden by
FactoryCreator only.
|
getClassLoaders | final public Set getClassLoaders()(Code) | | Returns all class loaders to be used for scanning plugins. Current implementation
returns the following class loaders:
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.
|
getServiceProvider | public Object getServiceProvider(Class category, Filter filter, Hints hints, Hints.Key key) throws FactoryRegistryException(Code) | | Returns the first provider in the registry for the specified category, using the specified
map of hints (if any). This method may
the
first time it is invoked. Except as a result of this scan, no new provider instance is
created by the default implementation of this method. The
FactoryCreator class
change this behavior however.
Parameters: category - The category to look for. Must be one of the categories declared to theconstructor. Usually an interface class (not the actual implementationclass). Parameters: filter - An optional filter, or null if none.This is used for example in order to select the first factory for some. Parameters: hints - A , or null if none. Parameters: key - The key to use for looking for a user-provided instance in the hints, or null if none. A factory for use for thespecified category and hints. The returns type is Object instead ofFactory because the factory implementation doesn't need to be a Geotools one. throws: FactoryNotFoundException - if no factory was found for the specified category, filterand hints. throws: FactoryRegistryException - if a factory can't be returned for some other reason. See Also: FactoryRegistry.getServiceProviders(Class,Filter,Hints) See Also: FactoryCreator.getServiceProvider |
getServiceProviders | public Iterator getServiceProviders(Class category)(Code) | | Returns the providers in the registry for the specified category. Providers that are
not
will be ignored. This method
will
the first time it is invoked for
the given category.
Parameters: category - The category to look for. Usually an interface class(not the actual implementation class). Factories ready to use for the specified category.FactoryRegistry.getServiceProviders(Class,Filter,Hints) |
getServiceProviders | public Iterator getServiceProviders(Class category, Filter filter, Hints hints)(Code) | | Returns the providers in the registry for the specified category, filter and hints.
Providers that are not
will be
ignored. This method will
the first
time it is invoked for the given category.
Parameters: category - The category to look for. Usually an interface class(not the actual implementation class). Parameters: filter - The optional filter, or null . Parameters: hints - The optional user requirements, or null . Factories ready to use for the specified category, filter and hints. since: 2.3 |
isAcceptable | final boolean isAcceptable(Object candidate, Class category, Hints hints, Filter filter)(Code) | | Returns
true is the specified
factory meets the requirements specified by
a map of
hints and the filter. This method is the entry point for the following
public methods:
- Singleton
#getServiceProvider (Class category, Filter, Hints, Hints.Key)
- Iterator
#getServiceProviders(Class category, Filter, Hints)
Parameters: candidate - The factory to checks. Parameters: category - The factory category. Usually an interface. Parameters: hints - The optional user requirements, or null . Parameters: filter - The optional filter, or null . true if the factory meets the user requirements. |
isAcceptable | protected boolean isAcceptable(Object provider, Class category, Hints hints)(Code) | | Returns
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
AbstractFactory implementations, since their hints
are automatically checked. Override this method for non-Geotools 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.
}
Parameters: provider - The provider to checks. Parameters: category - The factory category. Usually an interface. Parameters: hints - The user requirements, or null if none. true if the provider meets the user requirements. |
scanForPlugins | public void scanForPlugins()(Code) | | Scans for factory plug-ins on the application class path. This method is
needed because the application class path can theoretically change, or
additional plug-ins may become available. Rather than re-scanning the
classpath on every invocation of the API, the class path is scanned
automatically only on the first invocation. Clients can call this
method to prompt a re-scan. Thus this method need only be invoked by
sophisticated applications which dynamically make new plug-ins
available at runtime.
|
setOrdering | public boolean setOrdering(Class category, Comparator comparator)(Code) | | Set pairwise ordering between all factories according a comparator. Calls to
(factory1, factory2) should returns:
-
-1 if
factory1 is preferred to
factory2
-
+1 if
factory2 is preferred to
factory1
-
0 if there is no preferred order between
factory1 and
factory2
Parameters: category - The category to set ordering. Parameters: comparator - The comparator to use for ordering. true if at least one ordering setting has been modified as a consequenceof this call. |
setOrdering | public boolean setOrdering(Class base, boolean set, Filter service1, Filter service2)(Code) | | Sets or unsets a pairwise ordering between all factories meeting a criterion. For example
in the CRS framework (
org.geotools.referencing.FactoryFinder ), this is used for
setting ordering between all factories provided by two vendors, or for two authorities.
If one or both factories are not currently registered, or if the desired ordering is
already set/unset, nothing happens and false is returned.
Parameters: base - The base category. Only categories to base will be processed. Parameters: set - true for setting the ordering, or false for unsetting. Parameters: service1 - Filter for the preferred factory. Parameters: service2 - Filter for the factory to which service1 is preferred. |
Methods inherited from javax.imageio.spi.ServiceRegistry | public boolean contains(Object provider)(Code)(Java Doc) public void deregisterAll(Class> category)(Code)(Java Doc) public void deregisterAll()(Code)(Java Doc) public boolean deregisterServiceProvider(T provider, Class<T> category)(Code)(Java Doc) public void deregisterServiceProvider(Object provider)(Code)(Java Doc) public void finalize() throws Throwable(Code)(Java Doc) public Iterator<Class<?>> getCategories()(Code)(Java Doc) public T getServiceProviderByClass(Class<T> providerClass)(Code)(Java Doc) public Iterator<T> getServiceProviders(Class<T> category, boolean useOrdering)(Code)(Java Doc) public Iterator<T> getServiceProviders(Class<T> category, Filter filter, boolean useOrdering)(Code)(Java Doc) public static Iterator<T> lookupProviders(Class<T> providerClass, ClassLoader loader)(Code)(Java Doc) public static Iterator<T> lookupProviders(Class<T> providerClass)(Code)(Java Doc) public boolean registerServiceProvider(T provider, Class<T> category)(Code)(Java Doc) public void registerServiceProvider(Object provider)(Code)(Java Doc) public void registerServiceProviders(Iterator> providers)(Code)(Java Doc) public boolean setOrdering(Class<T> category, T firstProvider, T secondProvider)(Code)(Java Doc) public boolean unsetOrdering(Class<T> category, T firstProvider, T secondProvider)(Code)(Java Doc)
|
|
|