org.geotoolkit.factory
Class FactoryFinder

Object
  extended by Static
      extended by FactoryFinder
Direct Known Subclasses:
AuthorityFactoryFinder

@ThreadSafe
public class FactoryFinder
extends Static

Defines static methods used to access the application factory implementations. This class provide access to the following services:

This class is thread-safe but may have a high contention. Applications (or computational units in an application) are encouraged to save references to the factories they need in their own private fields. They would gain in performance and in stability, since the set of available factories may change during the execution.

Some methods like setVendorOrdering have a system-wide effect. Most applications should not need to invoke them. If an application needs to protect itself against configuration changes that may be performed by an other application sharing the Geotk library, it shall manage its own instance of FactoryRegistry. This FactoryFinder class itself is just a convenience wrapper around a FactoryRegistry instance.

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

Field Summary
static Hints.Key FILTER_KEY
          The key for a special hints specifying an additional Filter.
 
Method Summary
static Set<AggregateFactory> getAggregateFactories(Hints hints)
          Returns a set of all available implementations for the AggregateFactory interface.
static AggregateFactory getAggregateFactory(Hints hints)
          Returns the first implementation of AggregateFactory matching the specified hints.
static Set<CitationFactory> getCitationFactories(Hints hints)
          Returns a set of all available implementations for the CitationFactory interface.
static CitationFactory getCitationFactory(Hints hints)
          Returns the first implementation of CitationFactory matching the specified hints.
static Set<ComplexFactory> getComplexFactories(Hints hints)
          Returns a set of all available implementations for the ComplexFactory interface.
static ComplexFactory getComplexFactory(Hints hints)
          Returns the first implementation of ComplexFactory matching the specified hints.
static Set<CoordinateOperationFactory> getCoordinateOperationFactories(Hints hints)
          Returns a set of all available implementations for the CoordinateOperationFactory interface.
static CoordinateOperationFactory getCoordinateOperationFactory(Hints hints)
          Returns the first implementation of CoordinateOperationFactory matching the specified hints.
static Set<CRSFactory> getCRSFactories(Hints hints)
          Returns a set of all available implementations for the CRSFactory interface.
static CRSFactory getCRSFactory(Hints hints)
          Returns the first implementation of CRSFactory matching the specified hints.
static Set<CSFactory> getCSFactories(Hints hints)
          Returns a set of all available implementations for the CSFactory interface.
static CSFactory getCSFactory(Hints hints)
          Returns the first implementation of CSFactory matching the specified hints.
static Set<DatumFactory> getDatumFactories(Hints hints)
          Returns a set of all available implementations for the DatumFactory interface.
static DatumFactory getDatumFactory(Hints hints)
          Returns the first implementation of DatumFactory matching the specified hints.
static Set<FeatureFactory> getFeatureFactories(Hints hints)
          Returns a set of all available implementations for the FeatureFactory interface.
static FeatureFactory getFeatureFactory(Hints hints)
          Returns the first implementation of FeatureFactory matching the specified hints.
static Set<FeatureTypeFactory> getFeatureTypeFactories(Hints hints)
          Returns a set of all available implementations for the FeatureTypeFactory interface.
static FeatureTypeFactory getFeatureTypeFactory(Hints hints)
          Returns the first implementation of FeatureTypeFactory matching the specified hints.
static Set<FilterFactory> getFilterFactories(Hints hints)
          Returns a set of all available implementations for the FilterFactory interface.
static FilterFactory getFilterFactory(Hints hints)
          Returns the first implementation of FilterFactory matching the specified hints.
static Set<GeometryFactory> getGeometryFactories(Hints hints)
          Returns a set of all available implementations for the GeometryFactory interface.
static GeometryFactory getGeometryFactory(Hints hints)
          Returns the first implementation of GeometryFactory matching the specified hints.
static Set<MathTransformFactory> getMathTransformFactories(Hints hints)
          Returns a set of all available implementations for the MathTransformFactory interface.
static MathTransformFactory getMathTransformFactory(Hints hints)
          Returns the first implementation of MathTransformFactory matching the specified hints.
static Set<NameFactory> getNameFactories(Hints hints)
          Returns a set of all available implementations for the NameFactory interface.
static NameFactory getNameFactory(Hints hints)
          Returns the first implementation of NameFactory matching the specified hints.
static Set<PositionFactory> getPositionFactories(Hints hints)
          Returns a set of all available implementations for the PositionFactory interface.
static PositionFactory getPositionFactory(Hints hints)
          Returns the first implementation of PositionFactory matching the specified hints.
static Set<PrimitiveFactory> getPrimitiveFactories(Hints hints)
          Returns a set of all available implementations for the PrimitiveFactory interface.
static PrimitiveFactory getPrimitiveFactory(Hints hints)
          Returns the first implementation of PrimitiveFactory matching the specified hints.
static Set<StyleFactory> getStyleFactories(Hints hints)
          Returns a set of all available implementations for the StyleFactory interface.
static StyleFactory getStyleFactory(Hints hints)
          Returns the first implementation of StyleFactory matching the specified hints.
static Set<TemporalFactory> getTemporalFactories(Hints hints)
          Returns a set of all available implementations for the TemporalFactory interface.
static TemporalFactory getTemporalFactory(Hints hints)
          Returns the first implementation of TemporalFactory matching the specified hints.
static boolean isRegistered(Object factory)
          Returns true if the specified factory is registered.
static void listProviders(Writer out, Locale locale)
          Lists all available factory implementations in a tabular format.
static void scanForPlugins()
          Scans for factory plug-ins on the application class path.
static boolean setImplementationOrdering(String package1, String package2)
          Sets a pairwise ordering between two implementations defined by package names.
static boolean setVendorOrdering(String vendor1, String vendor2)
          Sets a pairwise ordering between two vendors.
static boolean unsetImplementationOrdering(String package1, String package2)
          Unsets a pairwise ordering between two implementations defined by package names.
static boolean unsetVendorOrdering(String vendor1, String vendor2)
          Unsets a pairwise ordering between two vendors.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILTER_KEY

public static final Hints.Key FILTER_KEY
The key for a special hints specifying an additional Filter. If a value is given to this key in a Hints map, then every factory candidate will be filtered by the given filter in addition of being checked for the other hints.

Since:
3.03
Method Detail

getNameFactory

public static NameFactory getNameFactory(Hints hints)
                                  throws FactoryRegistryException
Returns the first implementation of NameFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first name factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the NameFactory interface.
Since:
3.00
See Also:
Hints.NAME_FACTORY

getNameFactories

public static Set<NameFactory> getNameFactories(Hints hints)
Returns a set of all available implementations for the NameFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available name factory implementations.
Since:
3.00

getCitationFactory

public static CitationFactory getCitationFactory(Hints hints)
                                          throws FactoryRegistryException
Returns the first implementation of CitationFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first citation factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the CitationFactory interface.
Since:
3.00
See Also:
Hints.CITATION_FACTORY

getCitationFactories

public static Set<CitationFactory> getCitationFactories(Hints hints)
Returns a set of all available implementations for the CitationFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available citation factory implementations.
Since:
3.00

getDatumFactory

public static DatumFactory getDatumFactory(Hints hints)
                                    throws FactoryRegistryException
Returns the first implementation of DatumFactory matching the specified hints. If no implementation matches, a new one is created if possible or an exception is thrown otherwise. If more than one implementation is registered and an ordering is set, then the preferred implementation is returned. Otherwise an arbitrary one is selected.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first datum factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the DatumFactory interface.
See Also:
Hints.DATUM_FACTORY

getDatumFactories

public static Set<DatumFactory> getDatumFactories(Hints hints)
Returns a set of all available implementations for the DatumFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available datum factory implementations.

getCSFactory

public static CSFactory getCSFactory(Hints hints)
                              throws FactoryRegistryException
Returns the first implementation of CSFactory matching the specified hints. If no implementation matches, a new one is created if possible or an exception is thrown otherwise. If more than one implementation is registered and an ordering is set, then the preferred implementation is returned. Otherwise an arbitrary one is selected.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first coordinate system factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the CSFactory interface.
See Also:
Hints.CS_FACTORY

getCSFactories

public static Set<CSFactory> getCSFactories(Hints hints)
Returns a set of all available implementations for the CSFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available coordinate system factory implementations.

getCRSFactory

public static CRSFactory getCRSFactory(Hints hints)
                                throws FactoryRegistryException
Returns the first implementation of CRSFactory matching the specified hints. If no implementation matches, a new one is created if possible or an exception is thrown otherwise. If more than one implementation is registered and an ordering is set, then the preferred implementation is returned. Otherwise an arbitrary one is selected.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first coordinate reference system factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the CRSFactory interface.
See Also:
Hints.CRS_FACTORY

getCRSFactories

public static Set<CRSFactory> getCRSFactories(Hints hints)
Returns a set of all available implementations for the CRSFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available coordinate reference system factory implementations.

getCoordinateOperationFactory

public static CoordinateOperationFactory getCoordinateOperationFactory(Hints hints)
                                                                throws FactoryRegistryException
Returns the first implementation of CoordinateOperationFactory matching the specified hints. If no implementation matches, a new one is created if possible or an exception is thrown otherwise. If more than one implementation is registered and an ordering is set, then the preferred implementation is returned. Otherwise an arbitrary one is selected.

Hints that may be understood includes MATH_TRANSFORM_FACTORY, DATUM_SHIFT_METHOD, LENIENT_DATUM_SHIFT and VERSION.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first coordinate operation factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the CoordinateOperationFactory interface.
See Also:
Hints.COORDINATE_OPERATION_FACTORY

getCoordinateOperationFactories

public static Set<CoordinateOperationFactory> getCoordinateOperationFactories(Hints hints)
Returns a set of all available implementations for the CoordinateOperationFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available coordinate operation factory implementations.

getMathTransformFactory

public static MathTransformFactory getMathTransformFactory(Hints hints)
                                                    throws FactoryRegistryException
Returns the first implementation of MathTransformFactory matching the specified hints. If no implementation matches, a new one is created if possible or an exception is thrown otherwise. If more than one implementation is registered and an ordering is set, then the preferred implementation is returned. Otherwise an arbitrary one is selected.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first math transform factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the MathTransformFactory interface.
See Also:
Hints.MATH_TRANSFORM_FACTORY

getMathTransformFactories

public static Set<MathTransformFactory> getMathTransformFactories(Hints hints)
Returns a set of all available implementations for the MathTransformFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available math transform factory implementations.

getTemporalFactory

public static TemporalFactory getTemporalFactory(Hints hints)
                                          throws FactoryRegistryException
Returns the first implementation of TemporalFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first temporal factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the TemporalFactory interface.
Since:
3.18
See Also:
Hints.TEMPORAL_FACTORY

getTemporalFactories

public static Set<TemporalFactory> getTemporalFactories(Hints hints)
Returns a set of all available implementations for the TemporalFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available temporal factory implementations.
Since:
3.18

getPositionFactory

public static PositionFactory getPositionFactory(Hints hints)
                                          throws FactoryRegistryException
Returns the first implementation of PositionFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first position factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the PositionFactory interface.
Since:
3.01
See Also:
Hints.POSITION_FACTORY

getPositionFactories

public static Set<PositionFactory> getPositionFactories(Hints hints)
Returns a set of all available implementations for the PositionFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available position factory implementations.
Since:
3.01

getPrimitiveFactory

public static PrimitiveFactory getPrimitiveFactory(Hints hints)
                                            throws FactoryRegistryException
Returns the first implementation of PrimitiveFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first primitive factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the PrimitiveFactory interface.
Since:
3.01
See Also:
Hints.PRIMITIVE_FACTORY

getPrimitiveFactories

public static Set<PrimitiveFactory> getPrimitiveFactories(Hints hints)
Returns a set of all available implementations for the PrimitiveFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available primitive factory implementations.
Since:
3.01

getGeometryFactory

public static GeometryFactory getGeometryFactory(Hints hints)
                                          throws FactoryRegistryException
Returns the first implementation of GeometryFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first geometry factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the GeometryFactory interface.
Since:
3.01
See Also:
Hints.GEOMETRY_FACTORY

getGeometryFactories

public static Set<GeometryFactory> getGeometryFactories(Hints hints)
Returns a set of all available implementations for the GeometryFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available geometry factory implementations.
Since:
3.01

getComplexFactory

public static ComplexFactory getComplexFactory(Hints hints)
                                        throws FactoryRegistryException
Returns the first implementation of ComplexFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first complex factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the ComplexFactory interface.
Since:
3.01
See Also:
Hints.COMPLEX_FACTORY

getComplexFactories

public static Set<ComplexFactory> getComplexFactories(Hints hints)
Returns a set of all available implementations for the ComplexFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available complex factory implementations.
Since:
3.01

getAggregateFactory

public static AggregateFactory getAggregateFactory(Hints hints)
                                            throws FactoryRegistryException
Returns the first implementation of AggregateFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first aggregate factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the ComplexFactory interface.
Since:
3.01
See Also:
Hints.AGGREGATE_FACTORY

getAggregateFactories

public static Set<AggregateFactory> getAggregateFactories(Hints hints)
Returns a set of all available implementations for the AggregateFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available complex factory implementations.
Since:
3.01

getFeatureTypeFactory

public static FeatureTypeFactory getFeatureTypeFactory(Hints hints)
                                                throws FactoryRegistryException
Returns the first implementation of FeatureTypeFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first feature type factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the FeatureTypeFactory interface.
Since:
3.15
See Also:
Hints.FEATURE_TYPE_FACTORY

getFeatureTypeFactories

public static Set<FeatureTypeFactory> getFeatureTypeFactories(Hints hints)
Returns a set of all available implementations for the FeatureTypeFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available feature type factory implementations.
Since:
3.15

getFeatureFactory

public static FeatureFactory getFeatureFactory(Hints hints)
                                        throws FactoryRegistryException
Returns the first implementation of FeatureFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first feature factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the FeatureFactory interface.
Since:
3.01
See Also:
Hints.FEATURE_FACTORY

getFeatureFactories

public static Set<FeatureFactory> getFeatureFactories(Hints hints)
Returns a set of all available implementations for the FeatureFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available feature factory implementations.
Since:
3.01

getFilterFactory

public static FilterFactory getFilterFactory(Hints hints)
                                      throws FactoryRegistryException
Returns the first implementation of FilterFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first filter factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the FilterFactory interface.
Since:
3.00
See Also:
Hints.FILTER_FACTORY

getFilterFactories

public static Set<FilterFactory> getFilterFactories(Hints hints)
Returns a set of all available implementations for the FilterFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available filter factory implementations.
Since:
3.00

getStyleFactory

public static StyleFactory getStyleFactory(Hints hints)
                                    throws FactoryRegistryException
Returns the first implementation of StyleFactory matching the specified hints.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
The first style factory that matches the supplied hints.
Throws:
FactoryRegistryException - if no implementation was found or can be created for the StyleFactory interface.
Since:
3.00
See Also:
Hints.STYLE_FACTORY

getStyleFactories

public static Set<StyleFactory> getStyleFactories(Hints hints)
Returns a set of all available implementations for the StyleFactory interface.

Parameters:
hints - An optional map of hints, or null for the default ones.
Returns:
Set of available style factory implementations.
Since:
3.00

setVendorOrdering

@Configuration
public static boolean setVendorOrdering(String vendor1,
                                                      String vendor2)
Sets a pairwise ordering between two vendors. If one or both vendors are not currently registered, or if the desired ordering is already set, then nothing happens and false is returned.

The example below said that an ESRI implementation (if available) is preferred over the Geotoolkit.org one:

FactoryFinder.setVendorOrdering("ESRI", "Geotoolkit.org");

Parameters:
vendor1 - The preferred vendor.
vendor2 - The vendor to which vendor1 is preferred.
Returns:
true if the ordering was set for at least one category.
See Also:
AuthorityFactoryFinder.setAuthorityOrdering(String, String)

unsetVendorOrdering

@Configuration
public static boolean unsetVendorOrdering(String vendor1,
                                                        String vendor2)
Unsets a pairwise ordering between two vendors. If one or both vendors are not currently registered, or if the desired ordering is already unset, then nothing happens and false is returned.

Parameters:
vendor1 - The preferred vendor.
vendor2 - The vendor to which vendor1 was preferred.
Returns:
true if the ordering was unset for at least one category.
See Also:
AuthorityFactoryFinder.unsetAuthorityOrdering(String, String)

setImplementationOrdering

@Configuration
public static boolean setImplementationOrdering(String package1,
                                                              String package2)
Sets a pairwise ordering between two implementations defined by package names. If one or both implementations are not currently registered, or if the desired ordering is already set, then nothing happens and false is returned.

This method is preferred to setVendorOrdering(String, String) when the package name are known, because it avoid the potentially costly (on some implementations) call to Factory.getVendor().

Note: An example of costly getVendor() implementation is the one in the CachingAuthorityFactory class, because it needs to create the underlying backing store in order to query its vendor property.

Parameters:
package1 - The package name of the preferred implementation.
package2 - The package name of the implementation to which package1 is preferred.
Returns:
true if the ordering was set for at least one category.
Since:
3.16
See Also:
setVendorOrdering(String, String)

unsetImplementationOrdering

@Configuration
public static boolean unsetImplementationOrdering(String package1,
                                                                String package2)
Unsets a pairwise ordering between two implementations defined by package names. If one or both implementations are not currently registered, or if the desired ordering is already unset, then nothing happens and false is returned.

Parameters:
package1 - The preferred vendor.
package2 - The vendor to which vendor1 was preferred.
Returns:
true if the ordering was unset for at least one category.
Since:
3.16
See Also:
unsetVendorOrdering(String, String)

isRegistered

public static boolean isRegistered(Object factory)
Returns true if the specified factory is registered. A factory may have been registered by scanForPlugins() if it was declared in a META-INF/services file, or it may have been added programmatically.

Parameters:
factory - The factory to check for registration.
Returns:
true if the given factory is registered.
Since:
2.4

listProviders

@Debug
public static void listProviders(Writer out,
                                       Locale locale)
                          throws IOException
Lists all available factory implementations in a tabular format. For each factory interface, the first implementation listed is the default one. This method provides a way to check the state of a system, usually for debugging purpose.

Parameters:
out - The output stream where to format the list.
locale - The locale for the list, or null.
Throws:
IOException - if an error occurs while writing to out.
Since:
3.00

scanForPlugins

@Configuration
public static 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.



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