Package org.apache.sis.storage
Class AbstractResource
Object
AbstractResource
- All Implemented Interfaces:
- Resource
- Direct Known Subclasses:
- AbstractFeatureSet,- AbstractGridCoverageResource
Default implementations of several methods for classes that want to implement the 
Resource interface.
 This class provides a getMetadata() method which extracts information from other methods.
 Subclasses should override the following methods:
 - getIdentifier()(strongly recommended)
- getEnvelope()(recommended)
- createMetadata()(optional)
- getSynchronizationLock()(optional)
Thread safety
Default methods of this abstract class are thread-safe. Synchronization, when needed, usesgetSynchronizationLock().- Since:
- 1.2
Defined in the sis-storage module
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final StoreListenersThe set of registeredStoreListeners for this resources.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractResource(StoreListeners parentListeners, boolean hidden) Creates a new resource which can send notifications to the given set of listeners.
- 
Method SummaryModifier and TypeMethodDescription<T extends StoreEvent>
 voidaddListener(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.protected voidClears any cache in this resource, forcing the data to be recomputed when needed again.protected MetadataInvoked in a synchronized block the first time thatgetMetadata()is invoked.Returns the spatiotemporal envelope of this resource.Returns the resource persistent identifier if available.final MetadataReturns a description of this resource.protected ObjectReturns the object on which to perform synchronizations for thread-safety.<T extends StoreEvent>
 voidremoveListener(Class<T> eventType, StoreListener<? super T> listener) Unregisters a listener previously added to this resource for the given type of events.
- 
Field Details- 
listenersThe set of registeredStoreListeners for this resources. ThisStoreListenershasDataStore.listenershas a parent.
 
- 
- 
Constructor Details- 
AbstractResourceCreates a new resource which can send notifications to the given set of listeners. Ifhiddenisfalse(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 ifhiddenistrue, 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 hiddenistrueor indirectly ifhiddenisfalse.- Parameters:
- parentListeners- listeners of the parent resource, or- nullif none. This is usually the listeners of the- DataStorethat created this resource.
- hidden-- falseif this resource shall use its own- StoreListenerswith the specified parent, or- truefor using- parentListenersdirectly.
 
 
- 
- 
Method Details- 
getIdentifierReturns the resource persistent identifier if available. The default implementation returns an empty value. Subclasses are strongly encouraged to override if they can provide a value.Implementation note: the default implementation ofcreateMetadata()uses this identifier for initializing themetadata/identificationInfo/citation/titleproperty.- Specified by:
- getIdentifierin 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:
 
- 
getEnvelopeReturns the spatiotemporal envelope of this resource. This information is part of API only in some kinds of resource such asFeatureSet. But the method is provided in this base class for convenience. The default implementation gives an empty value.Implementation note: the default implementation ofcreateMetadata()uses this identifier for initializing themetadata/identificationInfo/extent/geographicElementproperty.- Returns:
- the spatiotemporal resource extent.
- Throws:
- DataStoreException- if an error occurred while reading or computing the envelope.
 
- 
getMetadataReturns a description of this resource. This method invokescreateMetadata()in a synchronized block when first needed, then caches the result.- Specified by:
- getMetadatain interface- Resource
- Returns:
- information about this resource (never null).
- Throws:
- DataStoreException- if an error occurred while reading or computing the metadata.
- See Also:
 
- 
createMetadataInvoked in a synchronized block the first time thatgetMetadata()is invoked. The default implementation populates metadata based on information provided bygetIdentifier()andgetEnvelope(). Subclasses should override if they can provide more information. The default value can be completed by casting toDefaultMetadata.- Returns:
- the newly created metadata, or nullif unknown.
- Throws:
- DataStoreException- if an error occurred while reading metadata from this resource.
 
- 
clearCacheprotected void clearCache()Clears any cache in this resource, forcing the data to be recomputed when needed again. The default implementation clears the cached metadata object, which will causecreateMetadata()to be invoked again when first needed.
- 
getSynchronizationLockReturns the object on which to perform synchronizations for thread-safety. The default implementation returnsthis. Subclasses can override for example for synchronizing everything on an enclosingDataStore.- Returns:
- the synchronization lock.
 
- 
addListenerpublic <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 forwards tolisteners.addListener(eventType, listener).- Specified by:
- addListenerin interface- Resource
- Type Parameters:
- T- compile-time value of the- eventTypeargument.
- Parameters:
- eventType- type of- StoreEvents to listen (cannot be- null).
- listener- listener to notify about events.
 
- 
removeListenerpublic <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 forwards tolisteners.removeListener(eventType, listener)- Specified by:
- removeListenerin interface- Resource
- Type Parameters:
- T- compile-time value of the- eventTypeargument.
- Parameters:
- eventType- type of- StoreEvents which were listened (cannot be- null).
- listener- listener to stop notifying about events.
 
 
-