org.geotools.factory
Class FactoryCreator

Object
  extended by ServiceRegistry
      extended by FactoryRegistry
          extended by FactoryCreator

public class FactoryCreator
extends FactoryRegistry

A factory registry capable to creates factories if no appropriate instance was found in the registry.

This class maintains a cache of previously created factories, as weak references. Calls to getServiceProvider first check if a previously created factory can fit.

Since:
2.1
Author:
Martin Desruisseaux, Jody Garnett
Module:
modules/library/metadata (gt-metadata.jar)

Nested Class Summary
 
Nested classes/interfaces inherited from class ServiceRegistry
ServiceRegistry.Filter
 
Field Summary
 
Fields inherited from class FactoryRegistry
LOGGER
 
Constructor Summary
FactoryCreator(Class<?> category)
          Constructs a new registry for the specified category.
FactoryCreator(Class<?>[] categories)
          Constructs a new registry for the specified categories.
FactoryCreator(Collection<Class<?>> categories)
          Constructs a new registry for the specified categories.
 
Method Summary
protected
<T> T
createServiceProvider(Class<T> category, Class<?> implementation, Hints hints)
          Creates a new instance of the specified factory using the specified hints.
<T> T
getServiceProvider(Class<T> category, ServiceRegistry.Filter filter, Hints hints, Hints.Key key)
          Returns a provider for the specified category, using the specified map of hints (if any).
 
Methods inherited from class FactoryRegistry
getClassLoaders, getServiceProviders, isAcceptable, scanForPlugins, setOrdering, setOrdering
 
Methods inherited from class ServiceRegistry
contains, deregisterAll, deregisterAll, deregisterServiceProvider, deregisterServiceProvider, finalize, getCategories, getServiceProviderByClass, getServiceProviders, getServiceProviders, lookupProviders, lookupProviders, registerServiceProvider, registerServiceProvider, registerServiceProviders, setOrdering, unsetOrdering
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FactoryCreator

public FactoryCreator(Class<?> category)
Constructs a new registry for the specified category.

Parameters:
category - The single category.
Since:
2.4

FactoryCreator

public FactoryCreator(Class<?>[] categories)
Constructs a new registry for the specified categories.

Parameters:
categories - The categories.
Since:
2.4

FactoryCreator

public FactoryCreator(Collection<Class<?>> categories)
Constructs a new registry for the specified categories.

Parameters:
categories - The categories.
Method Detail

getServiceProvider

public <T> T getServiceProvider(Class<T> category,
                                ServiceRegistry.Filter filter,
                                Hints hints,
                                Hints.Key key)
                     throws FactoryRegistryException
Returns a provider for the specified category, using the specified map of hints (if any). If a provider matching the requirements is found in the registry, it is returned. Otherwise, a new provider is created and returned. This creation step is the only difference between this method and the super-class method.

Overrides:
getServiceProvider in class FactoryRegistry
Type Parameters:
T - The class represented by the category argument.
Parameters:
category - The category to look for.
filter - An optional filter, or null if none.
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.
Returns:
A factory for the specified category and hints (never null).
Throws:
FactoryNotFoundException - if no factory was found, and the specified hints don't provide suffisient information for creating a new factory.
FactoryRegistryException - if the factory can't be created for some other reason.
See Also:
#getServiceProviders(Class, Filter, Hints), getServiceProvider(java.lang.Class, javax.imageio.spi.ServiceRegistry.Filter, org.geotools.factory.Hints, org.geotools.factory.Hints.Key)

createServiceProvider

protected <T> T createServiceProvider(Class<T> category,
                                      Class<?> implementation,
                                      Hints hints)
                           throws FactoryRegistryException
Creates a new instance of the specified factory using the specified hints. The default implementation tries to instantiate the given implementation class using the first of the following constructor found:

Parameters:
category - The category to instantiate.
implementation - The factory class to instantiate.
hints - The implementation hints.
Returns:
The factory.
Throws:
FactoryRegistryException - if the factory creation failed.


Copyright © 1996-2010 Geotools. All Rights Reserved.