Package org.geotools.util.factory
Class FactoryCreator
- Object
-
- FactoryRegistry
-
- 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
getFactory(Class, Predicate, Hints, Hints.Key)
} first check if a previously created factory can fit.- Since:
- 2.1
- Author:
- Martin Desruisseaux, Jody Garnett
-
-
Field Summary
-
Fields inherited from class FactoryRegistry
LOGGER
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> T
createFactory(Class<T> category, Class<?> implementation, Hints hints)
Creates a new instance of the specified factory using the specified hints.<T> T
getFactory(Class<T> category, Predicate<? super T> filter, Hints hints, Hints.Key key)
Factory for the specified category, using the specified map of hints (if any).-
Methods inherited from class FactoryRegistry
deregisterAll, deregisterAll, deregisterFactories, deregisterFactories, deregisterFactory, deregisterFactory, finalize, getClassLoaders, getFactories, getFactories, getFactories, getFactoryByClass, isAcceptable, registerFactories, registerFactories, registerFactory, registerFactory, scanForPlugins, setOrdering, setOrdering, setOrdering, streamCategories, unsetOrdering
-
-
-
-
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
-
getFactory
public <T> T getFactory(Class<T> category, Predicate<? super T> filter, Hints hints, Hints.Key key) throws FactoryRegistryException
Factory 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 FactoryRegistry.getFactory(Class, Predicate, Hints, Hints.Key) super-class method}.- Overrides:
getFactory
in classFactoryRegistry
- Type Parameters:
T
- The class represented by thecategory
argument.- Parameters:
category
- The category to look for.filter
- Optional predicate, ornull
if none.hints
- A map of hints, ornull
if none.key
- The key to use for looking for a user-provided instance in the hints, ornull
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:
FactoryRegistry.getFactories(Class, Predicate, Hints)
,getFactory(java.lang.Class<T>, java.util.function.Predicate<? super T>, org.geotools.util.factory.Hints, org.geotools.util.factory.Hints.Key)
-
createFactory
protected <T> T createFactory(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:- Constructor with a single
Hints
argument. - No-argument constructor.
- 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.
- Constructor with a single
-
-