Class AuthorityFactories<T extends org.opengis.referencing.AuthorityFactory>

All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>

final class AuthorityFactories<T extends org.opengis.referencing.AuthorityFactory> extends LazySet<T>
Provides the CRS, CS, datum and coordinate operation authority factories. Provides also the system-wide MultiAuthoritiesFactory instance used by CRS.forCode(String). Current version handles the EPSG factory in a special way, but we may try to avoid doing special cases in a future SIS version (this may require more help from ServiceLoader).
Since:
0.7
Version:
0.8
  • Field Details

    • EPSG

      private static final GeodeticAuthorityFactory[] EPSG
      An array containing only the EPSG factory. Content of this array is initially null. The EPSG factory will be created when first needed by initialValues(). This array is returned directly (not cloned) by initialValues().
    • ALL

      static final MultiAuthoritiesFactory ALL
      The unique system-wide authority factory instance that contains all factories found on the classpath, plus the EPSG factory. The EPSGFactoryProxy most be excluded from this list, since the EPSG factory is handled in a special way.
  • Constructor Details

    • AuthorityFactories

      private AuthorityFactories(Class<T> type)
      Creates a new provider for factories of the given type.
  • Method Details

    • EPSG

      static void EPSG(GeodeticAuthorityFactory factory)
      Sets the EPSG factory to the given value.
    • EPSG

      static GeodeticAuthorityFactory EPSG()
      Returns the factory connected to the EPSG geodetic dataset if possible, or the EPSG fallback otherwise. If an EPSG data source has been found, then this method returns an instance of EPSGFactory but there is no guarantee that attempts to use that factory will succeed; for example maybe the EPSG schema does not exist. Callers should be prepared to either receive an EPSGFactoryFallback directly if the EPSG data source does not exist, or replace the EPSGFactory by a EPSGFactoryFallback later if attempt to use the returned factory fails.
    • fallback

      Returns the fallback to use if the authority factory is not available. Unless the problem may be temporary, this method replaces the EPSGFactory instance by EPSGFactoryFallback in order to prevent the same exception to be thrown and logged on every calls to CRS.forCode(String).
      Throws:
      UnavailableFactoryException
    • failure

      static boolean failure(UnavailableFactoryException e)
      Notifies that a factory is unavailable, but without giving a fallback and without logging. The caller is responsible for throwing an exception, or for logging a warning and provide its own fallback.
      Returns:
      false if the caller can try again, or true if the failure can be considered final.
    • log

      private static void log(Exception e, boolean isWarning)
      Logs the given exception at the given level. This method pretends that the logging come from CRS.getAuthorityFactory(String), which is the public facade for EPSG().
    • initialValues

      protected T[] initialValues()
      Invoked by LazySet for adding the EPSG factory before any other factory fetched by ServiceLoader. We put the EPSG factory first because it is often used anyway even for CRS and AUTO namespaces.

      This method tries to instantiate an EPSGFactory if possible, or an EPSGFactoryFallback otherwise.

      Overrides:
      initialValues in class LazySet<T extends org.opengis.referencing.AuthorityFactory>
      Returns:
      the EPSG factory in an array. Callers shall not modify the returned array.
    • next

      protected T next(Iterator<? extends T> it)
      Invoked by LazySet for fetching the next element from the given iterator. Skips the EPSGFactoryProxy if possible, or returns null otherwise. Note that MultiAuthoritiesFactory is safe to null values.
      Overrides:
      next in class LazySet<T extends org.opengis.referencing.AuthorityFactory>
      Parameters:
      it - the iterator from which to get a next value.
      Returns:
      the next value (may be null).