org.geotoolkit.factory
Class DynamicFactoryRegistry

Object
  extended by ServiceRegistry
      extended by FactoryRegistry
          extended by DynamicFactoryRegistry

public class DynamicFactoryRegistry
extends FactoryRegistry

A factory registry having the additional capability to create new factory instances on the fly. Instances can be created dynamically when the following conditions are meet:

New factories are cached using weak references. Calls to getServiceProvider first check if a previously created factory can fit.

Since:
2.1
Version:
3.03
Author:
Martin Desruisseaux (IRD, Geomatys), Jody Garnett (Refractions)
Module:
utility/geotk-utility (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class ServiceRegistry
ServiceRegistry.Filter
 
Field Summary
 
Fields inherited from class FactoryRegistry
LOGGER
 
Constructor Summary
DynamicFactoryRegistry(Class<?> category)
          Constructs a new registry for the specified category.
DynamicFactoryRegistry(Class<?>[] categories)
          Constructs a new registry for the specified categories.
DynamicFactoryRegistry(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.
 void scanForPlugins()
          Scans for factory plug-ins on the application class path.
 
Methods inherited from class FactoryRegistry
getClassLoaders, getServiceProvider, getServiceProviders, isAcceptable, setOrdering, setOrdering, toString, unsetOrdering
 
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, wait, wait, wait
 

Constructor Detail

DynamicFactoryRegistry

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

Parameters:
category - The single category.
Since:
2.4

DynamicFactoryRegistry

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

Parameters:
categories - The categories.
Since:
2.4

DynamicFactoryRegistry

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

Parameters:
categories - The categories.
Method Detail

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 constructors found:

Type Parameters:
T - The category to instantiate.
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.

scanForPlugins

public void scanForPlugins()
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.

Overrides:
scanForPlugins in class FactoryRegistry


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.