Class GridResourceWrapper

java.lang.Object
org.apache.sis.internal.storage.GridResourceWrapper
All Implemented Interfaces:
DataSet, GridCoverageResource, Resource
Direct Known Subclasses:
Band, MultiResolutionImage

public abstract class GridResourceWrapper extends Object implements GridCoverageResource
A grid coverage resource which is a wrapper around another grid coverage resource. Wrappers can be used for delaying data loading, modifying the identifier, completing metadata, etc. The wrapped resource is created only when first needed.
Since:
1.1
Version:
1.2
  • Field Details

    • source

      private GridCoverageResource source
      The coverage resource instance which provides the data. This is initially null and created when first needed.
  • Constructor Details

    • GridResourceWrapper

      protected GridResourceWrapper()
      Creates a new wrapper.
  • Method Details

    • getSynchronizationLock

      protected abstract Object getSynchronizationLock()
      Returns the object on which to perform all synchronizations for thread-safety.
      Returns:
      the object on which to perform synchronizations.
    • createSource

      protected abstract GridCoverageResource createSource() throws DataStoreException
      Creates the resource on which to delegate operations. This method is invoked in a synchronized block when first needed and the result is cached.
      Returns:
      the resource on which to delegate operations.
      Throws:
      DataStoreException - if the resource cannot be created.
    • source

      protected final GridCoverageResource source() throws DataStoreException
      Returns the potentially cached source. This method invokes createSource() when first needed and caches the result.
      Returns:
      the resource on which to delegate operations.
      Throws:
      DataStoreException - if the resource cannot be created.
    • getIdentifier

      public Optional<org.opengis.util.GenericName> getIdentifier() throws DataStoreException
      Returns the resource persistent identifier. The default implementation delegates to the source.
      Specified by:
      getIdentifier in interface Resource
      Returns:
      a persistent identifier unique within the data store, or absent if this resource has no such identifier.
      Throws:
      DataStoreException - if an error occurred while fetching the identifier.
      See Also:
    • getMetadata

      public org.opengis.metadata.Metadata getMetadata() throws DataStoreException
      Returns information about this resource. The default implementation delegates to the source.
      Specified by:
      getMetadata in interface Resource
      Returns:
      information about this resource. Should not be null.
      Throws:
      DataStoreException - if an error occurred while reading the metadata.
      See Also:
    • getEnvelope

      public Optional<org.opengis.geometry.Envelope> getEnvelope() throws DataStoreException
      Returns the spatiotemporal extent of this resource in its most natural coordinate reference system. This is not necessarily the smallest bounding box encompassing all data. The default implementation delegates to the source.
      Specified by:
      getEnvelope in interface DataSet
      Returns:
      the spatiotemporal resource extent. May be absent if none or too costly to compute.
      Throws:
      DataStoreException - if an error occurred while reading or computing the envelope.
    • getGridGeometry

      public GridGeometry getGridGeometry() throws DataStoreException
      Returns the valid extent of grid coordinates together with the conversion from those grid coordinates to real world coordinates. The default implementation delegates to the source.
      Specified by:
      getGridGeometry in interface GridCoverageResource
      Returns:
      extent of grid coordinates together with their mapping to "real world" coordinates.
      Throws:
      DataStoreException - if an error occurred while reading definitions from the underlying data store.
      See Also:
    • getSampleDimensions

      public List<SampleDimension> getSampleDimensions() throws DataStoreException
      Returns the ranges of sample values together with the conversion from samples to real values. The default implementation delegates to the source.
      Specified by:
      getSampleDimensions in interface GridCoverageResource
      Returns:
      ranges of sample values together with their mapping to "real values".
      Throws:
      DataStoreException - if an error occurred while reading definitions from the underlying data store.
      See Also:
    • getResolutions

      public List<double[]> getResolutions() throws DataStoreException
      Returns the preferred resolutions (in units of CRS axes) for read operations in this data store. Elements are ordered from finest (smallest numbers) to coarsest (largest numbers) resolution.
      Specified by:
      getResolutions in interface GridCoverageResource
      Returns:
      preferred resolutions for read operations in this data store, or an empty array if none.
      Throws:
      DataStoreException - if an error occurred while reading definitions from the underlying data store.
      See Also:
    • read

      public GridCoverage read(GridGeometry domain, int... ranges) throws DataStoreException
      Loads a subset of the grid coverage represented by this resource. The default implementation delegates to the source.
      Specified by:
      read in interface GridCoverageResource
      Parameters:
      domain - desired grid extent and resolution, or null for reading the whole domain.
      ranges - 0-based indices of sample dimensions to read, or null or an empty sequence for reading them all.
      Returns:
      the grid coverage for the specified domain and ranges.
      Throws:
      DataStoreException - if an error occurred while reading the grid coverage data.
    • getLoadingStrategy

      public RasterLoadingStrategy getLoadingStrategy() throws DataStoreException
      Returns an indication about when the "physical" loading of raster data will happen. The default implementation delegates to the source.
      Specified by:
      getLoadingStrategy in interface GridCoverageResource
      Returns:
      current raster data loading strategy for this resource.
      Throws:
      DataStoreException - if an error occurred while fetching data store configuration.
    • setLoadingStrategy

      public boolean setLoadingStrategy(RasterLoadingStrategy strategy) throws DataStoreException
      Sets the preferred strategy about when to do the "physical" loading of raster data. The default implementation delegates to the source.
      Specified by:
      setLoadingStrategy in interface GridCoverageResource
      Parameters:
      strategy - the desired strategy for loading raster data.
      Returns:
      true if the given strategy has been accepted, or false if this implementation replaced the given strategy by an alternative.
      Throws:
      DataStoreException - if an error occurred while setting data store configuration.
    • addListener

      public <T extends StoreEvent> void addListener(Class<T> eventType, StoreListener<? super T> listener)
      Registers a listener to notify when the specified kind of event occurs in this resource or in children. The default implementation delegates to the source.
      Specified by:
      addListener in interface Resource
      Type Parameters:
      T - compile-time value of the eventType argument.
      Parameters:
      listener - listener to notify about events.
      eventType - type of StoreEvent to listen (cannot be null).
    • removeListener

      public <T extends StoreEvent> void removeListener(Class<T> eventType, StoreListener<? super T> listener)
      Unregisters a listener previously added to this resource for the given type of events. The default implementation delegates to the source.
      Specified by:
      removeListener in interface Resource
      Type Parameters:
      T - compile-time value of the eventType argument.
      Parameters:
      listener - listener to stop notifying about events.
      eventType - type of StoreEvent which were listened (cannot be null).
    • closeDataStore

      public final void closeDataStore() throws DataStoreException
      Closes the data store associated to the resource, then discards the resource. This method does not verify if the data store is still used by other resources.
      Throws:
      DataStoreException - if an error occurred while closing the data store.