Package org.apache.sis.internal.storage
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
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final URI
TheDataStoreProvider.LOCATION
parameter value, ornull
if none.private Path
Thelocation
as a path, computed when first needed.private final boolean
WhetherlocationAsPath
was initialized at construction time (true
) of inferred from thelocation
URI at a later time (false
). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
URIDataStore
(DataStoreProvider provider, StorageConnector connector) Creates a new data store. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
addTitleOrIdentifier
(MetadataBuilder builder) Adds the filename (without extension) as the citation title if there are no titles, or as the identifier otherwise.Path[]
Returns the location as aPath
component or an empty array if none.private String
Returns the filename without path and without file extension, ornull
if none.Optional<org.opengis.util.GenericName>
Returns an identifier for the root resource of this data store, or an empty value if none.Optional<org.opengis.parameter.ParameterValueGroup>
Returns the parameters used to open this data store.final DataStore
Returns the originator of this resource, which is this data store itself.protected final Path
static Object
Returns the location (path, URL, URI, etc.) of the given resource.static org.opengis.parameter.ParameterValueGroup
parameters
(DataStoreProvider provider, URI location) Creates parameter value group for the current location, if non-null.Methods inherited from class org.apache.sis.storage.DataStore
addListener, close, findResource, getDisplayName, getLocale, getMetadata, getNativeMetadata, getProvider, removeListener, setLocale, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sis.storage.Resource
addListener, getMetadata, removeListener
-
Field Details
-
location
TheDataStoreProvider.LOCATION
parameter value, ornull
if none. -
locationAsPath
Thelocation
as a path, computed when first needed. If the storage given at construction time was aPath
or aFile
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 locationIsPathWhetherlocationAsPath
was initialized at construction time (true
) of inferred from thelocation
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 theOpenOption
are compatible with whether this data store is read-only or read/write.- Parameters:
provider
- the factory that created thisURIDataStore
instance, ornull
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
Returns the originator of this resource, which is this data store itself.- Specified by:
getOriginator
in interfaceStoreResource
- Returns:
this
.
-
getIdentifier
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 interfaceResource
- Overrides:
getIdentifier
in classDataStore
- Returns:
- an identifier for the root resource of this data store.
- Throws:
DataStoreException
- if an error occurred while fetching the identifier.- See Also:
-
getFilename
Returns the filename without path and without file extension, ornull
if none. -
getSpecifiedPath
If the location was specified as aPath
orFile
instance, returns that path. Otherwise returnsnull
. This method does not try to convert URI toPath
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
Returns the location as aPath
component or an empty array if none. The default implementation returns the storage specified at construction time if it was aPath
orFile
, or converts the URI to aPath
otherwise.- Specified by:
getComponentFiles
in interfaceResourceOnFileSystem
- Returns:
- the URI as a path, or an empty array if unknown.
- Throws:
DataStoreException
- if the URI cannot be converted to aPath
.
-
getOpenParameters
Returns the parameters used to open this data store.- Specified by:
getOpenParameters
in classDataStore
- 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 forDataStore.getOpenParameters()
implementations in publicDataStore
that cannot extendURIDataStore
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
Returns the location (path, URL, URI, etc.) of the given resource. The type of the returned object can be any of the types documented inDataStoreProvider.LOCATION
. The main ones areURI
,Path
and JDBC DataSource.- Parameters:
resource
- the resource for which to get the location, ornull
.- 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
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, afterDataStore
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.
-