Package org.apache.sis.storage
Class AbstractGridCoverageResource
java.lang.Object
org.apache.sis.storage.AbstractResource
org.apache.sis.storage.AbstractGridCoverageResource
- All Implemented Interfaces:
DataSet
,GridCoverageResource
,Resource
- Direct Known Subclasses:
ConcatenatedGridResource
,CoverageSubset
,MemoryGridResource
,TiledGridResource
,WorldFileResource
public abstract class AbstractGridCoverageResource
extends AbstractResource
implements GridCoverageResource
Default implementations of several methods for classes that want to implement the
GridCoverageResource
interface.
Subclasses should override the following methods:
GridCoverageResource.getGridGeometry()
(mandatory)GridCoverageResource.getSampleDimensions()
(mandatory)
read(…)
method in subclasses:
canNotRead(String, GridGeometry, Throwable)
for reporting a failure to read operation.logReadOperation(Object, GridGeometry, long)
for logging a notice about a read operation.
- Since:
- 1.2
- Version:
- 1.2
-
Field Summary
Fields inherited from class org.apache.sis.storage.AbstractResource
listeners
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractGridCoverageResource
(StoreListeners parentListeners, boolean hidden) Creates a new resource which can send notifications to the given set of listeners. -
Method Summary
Modifier and TypeMethodDescriptionprotected DataStoreException
canNotRead
(String filename, GridGeometry request, Throwable cause) Creates an exception for a failure to load data.protected org.opengis.metadata.Metadata
Invoked in a synchronized block the first time thatgetMetadata()
is invoked.Optional<org.opengis.geometry.Envelope>
Returns the envelope of the grid geometry if known.private static boolean
isReferencing
(Throwable cause) Returnstrue
if the given exception isFactoryException
orTransformException
.protected void
logReadOperation
(Object file, GridGeometry domain, long startTime) Logs the execution of aGridCoverageResource.read(GridGeometry, int...)
operation.Methods inherited from class org.apache.sis.storage.AbstractResource
addListener, clearCache, createExceptionMessage, getIdentifier, getMetadata, getSynchronizationLock, removeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.sis.storage.GridCoverageResource
getGridGeometry, getLoadingStrategy, getResolutions, getSampleDimensions, read, setLoadingStrategy, subset
Methods inherited from interface org.apache.sis.storage.Resource
addListener, getIdentifier, getMetadata, removeListener
-
Constructor Details
-
AbstractGridCoverageResource
Creates a new resource which can send notifications to the given set of listeners. Ifhidden
isfalse
(the recommended value), then this resource will have its own set of listeners with this resource declared as the source of events. It will be possible to add and remove listeners independently from the set of parent listeners. Conversely ifhidden
istrue
, then the given listeners will be used directly and this resource will not appear as the source of any event.In any cases, the listeners of all parents (ultimately the data store that created this resource) will always be notified, either directly if
hidden
istrue
or indirectly ifhidden
isfalse
.- Parameters:
parentListeners
- listeners of the parent resource, ornull
if none. This is usually the listeners of theDataStore
that created this resource.hidden
-false
if this resource shall use its ownStoreListeners
with the specified parent, ortrue
for usingparentListeners
directly.
-
-
Method Details
-
getEnvelope
Returns the envelope of the grid geometry if known. The envelope is absent if the grid geometry does not provide this information.- Specified by:
getEnvelope
in interfaceDataSet
- Overrides:
getEnvelope
in classAbstractResource
- Returns:
- the grid geometry envelope.
- Throws:
DataStoreException
- if an error occurred while computing the grid geometry.- See Also:
-
createMetadata
Invoked in a synchronized block the first time thatgetMetadata()
is invoked. The default implementation populates metadata based on information provided bygetIdentifier()
,getEnvelope()
,getGridGeometry()
andgetSampleDimensions()
. Subclasses should override if they can provide more information. The default value can be completed by casting toDefaultMetadata
.- Overrides:
createMetadata
in classAbstractResource
- Returns:
- the newly created metadata, or
null
if unknown. - Throws:
DataStoreException
- if an error occurred while reading metadata from this resource.
-
canNotRead
Creates an exception for a failure to load data. The exception sub-type is inferred from the arguments. If the failure is caused by an envelope outside the resource domain, then that envelope will be inferred from therequest
argument.- Parameters:
filename
- some identification (typically a file name) of the data that cannot be read.request
- the requested domain, ornull
if unspecified.cause
- the cause of the failure, ornull
if none.- Returns:
- the exception to throw.
- See Also:
-
isReferencing
Returnstrue
if the given exception isFactoryException
orTransformException
. This is for deciding if an exception should be rethrown as anDataStoreReferencingException
.- Parameters:
cause
- the exception to verify.- Returns:
- whether the given exception is
FactoryException
orTransformException
.
-
logReadOperation
Logs the execution of aGridCoverageResource.read(GridGeometry, int...)
operation. The log level will beLevel.FINE
if the operation was quick enough, orPerformanceLevel.SLOWNESS
or higher level otherwise.- Parameters:
file
- the file that was opened, ornull
forStoreListeners.getSourceName()
.domain
- domain of the created grid coverage.startTime
- value ofSystem.nanoTime()
when the loading process started.
-