Class URIDataStore

java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.internal.storage.URIDataStore
All Implemented Interfaces:
AutoCloseable, ResourceOnFileSystem, StoreResource, Resource, Localized
Direct Known Subclasses:
PRJDataStore, StaxDataStore, Store, Store, Store

public abstract class URIDataStore extends DataStore implements StoreResource, ResourceOnFileSystem
A data store for a storage that may be represented by a URI. It is still possible to create a data store with a ReadableByteChannel, InputStream or Reader, in which case the location will be null.
Since:
0.8
Version:
1.2
  • Field Details

    • location

      protected final URI location
      The DataStoreProvider.LOCATION parameter value, or null if none.
    • locationAsPath

      private volatile Path locationAsPath
      The location as a path, computed when first needed. If the storage given at construction time was a Path or a File instance, then this field is initialized in the constructor in order to avoid a "path → URI → path" roundtrip (such roundtrip transforms relative paths into absolute paths).
      See Also:
    • locationIsPath

      private final boolean locationIsPath
      Whether locationAsPath was initialized at construction time (true) of inferred from the location URI at a later time (false).
      See Also:
  • Constructor Details

    • URIDataStore

      protected URIDataStore(DataStoreProvider provider, StorageConnector connector) throws DataStoreException
      Creates a new data store. This constructor does not open the file, so subclass constructors can decide whether to open in read-only or read/write mode. It is caller's responsibility to ensure that the OpenOption are compatible with whether this data store is read-only or read/write.
      Parameters:
      provider - the factory that created this URIDataStore instance, or null if unspecified.
      connector - information about the storage (URL, stream, reader instance, etc).
      Throws:
      DataStoreException - if an error occurred while creating the data store for the given storage.
  • Method Details

    • getOriginator

      public final DataStore getOriginator()
      Returns the originator of this resource, which is this data store itself.
      Specified by:
      getOriginator in interface StoreResource
      Returns:
      this.
    • getIdentifier

      public Optional<org.opengis.util.GenericName> getIdentifier() throws DataStoreException
      Returns an identifier for the root resource of this data store, or an empty value if none. The default implementation returns the filename without path and without file extension.
      Specified by:
      getIdentifier in interface Resource
      Overrides:
      getIdentifier in class DataStore
      Returns:
      an identifier for the root resource of this data store.
      Throws:
      DataStoreException - if an error occurred while fetching the identifier.
      See Also:
    • getFilename

      private String getFilename()
      Returns the filename without path and without file extension, or null if none.
    • getSpecifiedPath

      protected final Path getSpecifiedPath()
      If the location was specified as a Path or File instance, returns that path. Otherwise returns null. This method does not try to convert URI to Path because this conversion may fail for HTTP and FTP connections.
      Returns:
      the path specified at construction time, or null if the storage was not specified as a path.
    • getComponentFiles

      public Path[] getComponentFiles() throws DataStoreException
      Returns the location as a Path component or an empty array if none. The default implementation returns the storage specified at construction time if it was a Path or File, or converts the URI to a Path otherwise.
      Specified by:
      getComponentFiles in interface ResourceOnFileSystem
      Returns:
      the URI as a path, or an empty array if unknown.
      Throws:
      DataStoreException - if the URI cannot be converted to a Path.
    • getOpenParameters

      public Optional<org.opengis.parameter.ParameterValueGroup> getOpenParameters()
      Returns the parameters used to open this data store.
      Specified by:
      getOpenParameters in class DataStore
      Returns:
      parameters used for opening this DataStore.
      See Also:
    • parameters

      public static org.opengis.parameter.ParameterValueGroup parameters(DataStoreProvider provider, URI location)
      Creates parameter value group for the current location, if non-null. This convenience method is used for DataStore.getOpenParameters() implementations in public DataStore that cannot extend URIDataStore directly, because this class is internal.
      Parameters:
      provider - the provider of the data store for which to get open parameters.
      location - file opened by the data store.
      Returns:
      parameters to be returned by DataStore.getOpenParameters().
    • location

      public static Object location(Resource resource) throws DataStoreException
      Returns the location (path, URL, URI, etc.) of the given resource. The type of the returned object can be any of the types documented in DataStoreProvider.LOCATION. The main ones are URI, Path and JDBC DataSource.
      Parameters:
      resource - the resource for which to get the location, or null.
      Returns:
      location of the given resource, or null if none.
      Throws:
      DataStoreException - if an error on the file system prevent the creation of the path.
      Since:
      1.1
    • addTitleOrIdentifier

      protected final void addTitleOrIdentifier(MetadataBuilder builder)
      Adds the filename (without extension) as the citation title if there are no titles, or as the identifier otherwise. This method should be invoked last, after DataStore implementation did its best effort for adding a title. The intent is actually to provide an identifier, but since the title is mandatory in ISO 19115 metadata, providing only an identifier without title would be invalid.
      Parameters:
      builder - where to add the title or identifier.