Class AbstractResource

Object
AbstractResource
All Implemented Interfaces:
Resource
Direct Known Subclasses:
Abstract­Feature­Set, Abstract­Grid­Coverage­Resource

public abstract class AbstractResource extends Object implements Resource
Default implementations of several methods for classes that want to implement the Resource interface. This class provides a get­Metadata() method which extracts information from other methods. Subclasses should override the following methods:

Thread safety

Default methods of this abstract class are thread-safe. Synchronization, when needed, uses get­Synchronization­Lock().
Since:
1.2
  • Field Details

  • Constructor Details

    • AbstractResource

      protected AbstractResource(Resource parent)
      Creates a new resource, potentially as a child of another resource. The parent resource is typically, but not necessarily, an Aggregate.
      Parameters:
      parent - the parent resource, or null if none.
      Since:
      1.4
    • AbstractResource

      protected AbstractResource(StoreListeners parentListeners, boolean hidden)
      Creates a new resource which can send notifications to the given set of listeners. If hidden is false (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 if hidden is true, 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 is true or indirectly if hidden is false.

      Parameters:
      parent­Listeners - listeners of the parent resource, or null if none. This is usually the listeners of the Data­Store that created this resource.
      hidden - false if this resource shall use its own Store­Listeners with the specified parent, or true for using parent­Listeners directly.
  • Method Details

    • getIdentifier

      public Optional<GenericName> getIdentifier() throws DataStoreException
      Returns 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.

      Relationship with metadata

      The default implementation of create­Metadata() uses this identifier for initializing the metadata/identification­Info/citation/title property.
      Specified by:
      get­Identifier in interface Resource
      Returns:
      a persistent identifier unique within the data store, or absent if this resource has no such identifier.
      Throws:
      Data­Store­Exception - if an error occurred while fetching the identifier.
      See Also:
    • getEnvelope

      public Optional<Envelope> getEnvelope() throws DataStoreException
      Returns the spatiotemporal envelope of this resource. This information is part of API only in some kinds of resource such as Feature­Set. But the method is provided in this base class for convenience. The default implementation gives an empty value.

      Implementation note

      The default implementation of create­Metadata() uses this identifier for initializing the metadata/identification­Info/extent/geographic­Element property.
      Returns:
      the spatiotemporal resource extent.
      Throws:
      Data­Store­Exception - if an error occurred while reading or computing the envelope.
    • getMetadata

      public final Metadata getMetadata() throws DataStoreException
      Returns a description of this resource. This method invokes create­Metadata() in a synchronized block when first needed, then caches the result.
      Specified by:
      get­Metadata in interface Resource
      Returns:
      information about this resource (never null).
      Throws:
      Data­Store­Exception - if an error occurred while reading or computing the metadata.
      See Also:
    • createMetadata

      protected Metadata createMetadata() throws DataStoreException
      Invoked in a synchronized block the first time that get­Metadata() is invoked. The default implementation populates metadata based on information provided by get­Identifier() and get­Envelope(). Subclasses should override if they can provide more information. The default value can be completed by casting to Default­Metadata.
      Returns:
      the newly created metadata, or null if unknown.
      Throws:
      Data­Store­Exception - if an error occurred while reading metadata from this resource.
    • clearCache

      protected 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 cause create­Metadata() to be invoked again when first needed.
    • getSynchronizationLock

      protected Object getSynchronizationLock()
      Returns the object on which to perform synchronizations for thread-safety. The default implementation returns this. Subclasses can override for example for synchronizing everything on an enclosing Data­Store.
      Returns:
      the synchronization lock.
    • 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 forwards to listeners.add­Listener(event­Type, listener).
      Specified by:
      add­Listener in interface Resource
      Type Parameters:
      T - compile-time value of the event­Type argument.
      Parameters:
      event­Type - type of Store­Events to listen (cannot be null).
      listener - listener to notify about events.
    • 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 forwards to listeners.remove­Listener(event­Type, listener)
      Specified by:
      remove­Listener in interface Resource
      Type Parameters:
      T - compile-time value of the event­Type argument.
      Parameters:
      event­Type - type of Store­Events which were listened (cannot be null).
      listener - listener to stop notifying about events.