Class ANSSRegionsFactory


  • public class ANSSRegionsFactory
    extends java.lang.Object
    Class to manage ANSS Authoritative Region updates. Simplest usage: ANSSRegionsFactory.getFactory().getRegions() Regions are not fetched until startup() (or fetchRegions()) is called.
    • Field Detail

      • LOGGER

        public static final java.util.logging.Logger LOGGER
        logging object
      • MILLISECONDS_PER_DAY

        public static final long MILLISECONDS_PER_DAY
        milliseconds per day
        See Also:
        Constant Field Values
      • DEFAULT_REGIONS_JSON

        public static final java.lang.String DEFAULT_REGIONS_JSON
        path to write regions.json
        See Also:
        Constant Field Values
    • Constructor Detail

      • ANSSRegionsFactory

        public ANSSRegionsFactory()
        Use default GeoserveLayersService.
      • ANSSRegionsFactory

        public ANSSRegionsFactory​(GeoserveLayersService geoserveLayersService)
        Use custom GeoserveLayersService.
        Parameters:
        geoserveLayersService - to use
    • Method Detail

      • getFactory

        public static ANSSRegionsFactory getFactory()
        Get the global ANSSRegionsFactory, creating and starting if needed.
        Returns:
        ANSSRegionsFactory
      • getFactory

        public static ANSSRegionsFactory getFactory​(boolean startup)
        Parameters:
        startup - if Factory should be created and started, if needed
        Returns:
        ANSSRegionsFactory
      • setFactory

        public static void setFactory​(ANSSRegionsFactory factory)
        Set the global ANSSRegionsFactory, shutting down any existing factory if needed.
        Parameters:
        factory - to set
      • fetchRegions

        public void fetchRegions()
        Download regions from geoserve. Writes out to "regions.json" in current working directory and, if unable to update, reads in local copy.
      • loadFromFile

        protected Regions loadFromFile()
                                throws java.io.IOException
        Read regions from local regions file.
        Returns:
        Regions
        Throws:
        java.io.IOException - if error occurs
      • loadFromGeoserve

        protected Regions loadFromGeoserve()
                                    throws java.io.IOException
        Read regions from geoserve service.
        Returns:
        Regions
        Throws:
        java.io.IOException - if error occurs
      • saveToFile

        protected void saveToFile​(java.io.File regionsFile,
                                  javax.json.JsonObject json)
                           throws java.io.IOException
        Store json to local regions file.
        Parameters:
        regionsFile - to store to
        json - json response to store locally.
        Throws:
        java.io.IOException - if IO error occurs
      • startup

        public void startup()
        Start updating regions.
      • shutdown

        public void shutdown()
        Stop updating regions.
      • getGeoserveLayersService

        public GeoserveLayersService getGeoserveLayersService()
        Get the service.
        Returns:
        geoserveLayersService
      • setGeoserveLayersService

        public void setGeoserveLayersService​(GeoserveLayersService service)
        Set the service.
        Parameters:
        service - GeoserveLayersService to set
      • getLocalRegions

        public java.io.File getLocalRegions()
        Get the local regions file.
        Returns:
        localRegions
      • setLocalRegions

        public void setLocalRegions​(java.io.File localRegions)
        Set the local regions file.
        Parameters:
        localRegions - file to set
      • getRegions

        public Regions getRegions()
        Get the most recently fetched Regions.
        Returns:
        regions