org.geotools.factory
Class FactoryCreator

java.lang.Object
  extended byjavax.imageio.spi.ServiceRegistry
      extended byorg.geotools.factory.FactoryRegistry
          extended byorg.geotools.factory.FactoryCreator

public class FactoryCreator
extends FactoryRegistry

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

Factory created "on the fly" are not cached; all invocation to getServiceProvider(...) will creates them again if no registered factory matches the requirements (filter and/or hints).

If caching is wanted, the instances to cache should be declared likes all other services in the directory. For the caching to be effective, their no-argument constructor shall setup the factory with implementation hints matching the hints that the application is expected to ask for. It is preferable that such custom implementation order itself after the default implementations.

Version:
$Id: FactoryCreator.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux, Jody Garnett

Nested Class Summary
 
Nested classes inherited from class javax.imageio.spi.ServiceRegistry
javax.imageio.spi.ServiceRegistry.Filter
 
Field Summary
 
Fields inherited from class org.geotools.factory.FactoryRegistry
LOGGER
 
Constructor Summary
FactoryCreator(java.util.Collection categories)
          Constructs a new registry for the specified categories.
 
Method Summary
protected  java.lang.Object createServiceProvider(java.lang.Class category, java.lang.Class implementation, Hints hints)
          Creates a new instance of the specified factory using the specified hints.
 java.lang.Object getServiceProvider(java.lang.Class category, javax.imageio.spi.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 org.geotools.factory.FactoryRegistry
getClassLoaders, getServiceProviders, isAcceptable, scanForPlugins, setOrdering, setOrdering
 
Methods inherited from class javax.imageio.spi.ServiceRegistry
contains, deregisterAll, deregisterAll, deregisterServiceProvider, deregisterServiceProvider, finalize, getCategories, getServiceProviderByClass, getServiceProviders, getServiceProviders, lookupProviders, lookupProviders, registerServiceProvider, registerServiceProvider, registerServiceProviders, setOrdering, unsetOrdering
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FactoryCreator

public FactoryCreator(java.util.Collection categories)
Constructs a new registry for the specified categories.

Parameters:
categories - The categories.
Method Detail

getServiceProvider

public java.lang.Object getServiceProvider(java.lang.Class category,
                                           javax.imageio.spi.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
Parameters:
category - The category to look for.
filter - An optional filter, or if none.
hints - A map of hints, or if none.
key - The key to use for looking for a user-provided instance in the hints, or if none.
Returns:
A factory for the specified category and hints (never ).
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:
FactoryRegistry.getServiceProviders(java.lang.Class), getServiceProvider(java.lang.Class, javax.imageio.spi.ServiceRegistry.Filter, org.geotools.factory.Hints, org.geotools.factory.Hints.Key)

createServiceProvider

protected java.lang.Object createServiceProvider(java.lang.Class category,
                                                 java.lang.Class implementation,
                                                 Hints hints)
                                          throws FactoryRegistryException
Creates a new instance of the specified factory using the specified hints. The default implementation try to instantiate the given implementation class 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 © GeoTools. All Rights Reserved.