Author: desruisseaux
Date: Thu Sep 7 15:04:44 2017
New Revision: 1807614
URL: http://svn.apache.org/viewvc?rev=1807614&view=rev
Log:
Refactor the new getOpenParameters() in a URIDataStore common class.
Added:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
(with props)
Modified:
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStore.java
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStoreProvider.java
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/StoreProvider.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/StorageConnectorTest.java
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Store.java
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/StoreProvider.java
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
Modified:
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStore.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStore.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -29,8 +29,7 @@ import org.apache.sis.storage.DataStoreE
import org.apache.sis.storage.DataStoreReferencingException;
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.storage.StorageConnector;
-import org.apache.sis.storage.Resource;
-import org.apache.sis.parameter.Parameters;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.setup.OptionKey;
import org.apache.sis.util.Debug;
@@ -73,7 +72,11 @@ public class LandsatStore extends DataSt
* The reader, or {@code null} if closed.
*/
private Reader source;
- private URI sourceUri;
+
+ /**
+ * The {@link LandsatStoreProvider#LOCATION} parameter value, or {@code
null} if none.
+ */
+ private final URI location;
/**
* The object returned by {@link #getMetadata()}, created when first
needed and cached.
@@ -91,12 +94,8 @@ public class LandsatStore extends DataSt
*/
public LandsatStore(final LandsatStoreProvider provider, final
StorageConnector connector) throws DataStoreException {
super(provider, connector);
+ location = connector.getStorageAs(URI.class);
source = connector.getStorageAs(Reader.class);
- try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
connector.closeAllExcept(source);
if (source == null) {
throw new UnsupportedStorageException(super.getLocale(),
LandsatStoreProvider.NAME,
@@ -130,14 +129,19 @@ public class LandsatStore extends DataSt
}
/**
- * {@inheritDoc }
+ * Returns the parameters used to open this Landsat data store.
+ * If non-null, the parameters are described by {@link
LandsatStoreProvider#getOpenParameters()}
+ * and contains at least a parameter named {@value
LandsatStoreProvider#LOCATION} with a {@link URI} value.
+ * This method may return {@code null} if the storage input can not be
described by a URI
+ * (for example a Landsat file reading directly from a {@link
java.nio.channels.ReadableByteChannel}).
+ *
+ * @return parameters used for opening this data store, or {@code null} if
not available.
+ *
+ * @since 0.8
*/
@Override
public ParameterValueGroup getOpenParameters() {
- if (sourceUri==null) return null;
- final Parameters parameters =
Parameters.castOrWrap(LandsatStoreProvider.OPEN_DESCRIPTOR.createValue());
-
parameters.getOrCreate(LandsatStoreProvider.PARAM_LOCATION).setValue(sourceUri);
- return parameters;
+ return URIDataStore.parameters(provider, location);
}
/**
Modified:
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,8 +16,6 @@
*/
package org.apache.sis.storage.earthobservation;
-import java.net.URI;
-import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreProvider;
@@ -26,8 +24,8 @@ import org.apache.sis.storage.StorageCon
import org.apache.sis.storage.ProbeResult;
import org.apache.sis.internal.storage.Capability;
import org.apache.sis.internal.storage.Capabilities;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.storage.wkt.FirstKeywordPeek;
-import org.apache.sis.parameter.ParameterBuilder;
/**
@@ -51,15 +49,9 @@ public class LandsatStoreProvider extend
static final String NAME = "Landsat";
/**
- * Landsat location.
+ * The parameter descriptor to be returned by {@link #getOpenParameters()}.
*/
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new ParameterBuilder().addName(NAME).createGroup(PARAM_LOCATION);
+ private static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
URIDataStore.Provider.descriptor(NAME);
/**
* The object to use for verifying if the first keyword is the expected
one.
@@ -156,7 +148,11 @@ public class LandsatStoreProvider extend
}
/**
- * {@inheritDoc }
+ * Returns a description of all parameters accepted by this provider for
opening a Landsat file.
+ *
+ * @return description of available parameters for opening a Landsat file.
+ *
+ * @since 0.8
*/
@Override
public ParameterDescriptorGroup getOpenParameters() {
Modified:
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -35,11 +35,10 @@ import org.apache.sis.storage.DataStoreC
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.internal.storage.io.ChannelDataInput;
import org.apache.sis.internal.storage.MetadataBuilder;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.metadata.sql.MetadataStoreException;
-import org.apache.sis.parameter.Parameters;
import org.apache.sis.storage.DataStoreClosedException;
-import org.apache.sis.storage.Resource;
import org.apache.sis.util.resources.Errors;
@@ -64,7 +63,11 @@ public class GeoTiffStore extends DataSt
* The GeoTIFF reader implementation, or {@code null} if the store has
been closed.
*/
private Reader reader;
- private URI sourceUri;
+
+ /**
+ * The {@link GeoTiffStoreProvider#LOCATION} parameter value, or {@code
null} if none.
+ */
+ private final URI location;
/**
* The metadata, or {@code null} if not yet created.
@@ -91,13 +94,9 @@ public class GeoTiffStore extends DataSt
throw new UnsupportedStorageException(super.getLocale(),
Constants.GEOTIFF,
connector.getStorage(),
connector.getOption(OptionKey.OPEN_OPTIONS));
}
+ location = connector.getStorageAs(URI.class);
connector.closeAllExcept(input);
try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
- try {
reader = new Reader(this, input);
} catch (IOException e) {
throw new DataStoreException(e);
@@ -142,14 +141,19 @@ public class GeoTiffStore extends DataSt
}
/**
- * {@inheritDoc }
+ * Returns the parameters used to open this GeoTIFF data store.
+ * If non-null, the parameters are described by {@link
GeoTiffStoreProvider#getOpenParameters()}
+ * and contains at least a parameter named {@value
GeoTiffStoreProvider#LOCATION} with a {@link URI} value.
+ * This method may return {@code null} if the storage input can not be
described by a URI
+ * (for example a GeoTIFF file reading directly from a {@link
java.nio.channels.ReadableByteChannel}).
+ *
+ * @return parameters used for opening this data store, or {@code null} if
not available.
+ *
+ * @since 0.8
*/
@Override
public ParameterValueGroup getOpenParameters() {
- if (sourceUri==null) return null;
- final Parameters parameters =
Parameters.castOrWrap(GeoTiffStoreProvider.OPEN_DESCRIPTOR.createValue());
-
parameters.getOrCreate(GeoTiffStoreProvider.PARAM_LOCATION).setValue(sourceUri);
- return parameters;
+ return URIDataStore.parameters(provider, location);
}
/**
Modified:
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,10 +16,8 @@
*/
package org.apache.sis.storage.geotiff;
-import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.apache.sis.util.Version;
import org.apache.sis.storage.DataStore;
@@ -29,8 +27,8 @@ import org.apache.sis.storage.ProbeResul
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.internal.storage.Capabilities;
import org.apache.sis.internal.storage.Capability;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.util.Constants;
-import org.apache.sis.parameter.ParameterBuilder;
/**
@@ -62,15 +60,9 @@ public class GeoTiffStoreProvider extend
private static final Version VERSION = new Version("6.0");
/**
- * Geotiff location.
+ * The parameter descriptor to be returned by {@link #getOpenParameters()}.
*/
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new
ParameterBuilder().addName(Constants.GEOTIFF).createGroup(PARAM_LOCATION);
+ private static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
URIDataStore.Provider.descriptor(Constants.GEOTIFF);
/**
* Creates a new provider.
@@ -89,7 +81,11 @@ public class GeoTiffStoreProvider extend
}
/**
- * {@inheritDoc }
+ * Returns a description of all parameters accepted by this provider for
opening a GeoTIFF file.
+ *
+ * @return description of available parameters for opening a GeoTIFF file.
+ *
+ * @since 0.8
*/
@Override
public ParameterDescriptorGroup getOpenParameters() {
Modified:
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -26,10 +26,9 @@ import org.apache.sis.storage.DataStoreE
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.internal.netcdf.Decoder;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.metadata.ModifiableMetadata;
-import org.apache.sis.parameter.Parameters;
import org.apache.sis.setup.OptionKey;
-import org.apache.sis.storage.Resource;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.Version;
import ucar.nc2.constants.CDM;
@@ -53,7 +52,11 @@ public class NetcdfStore extends DataSto
* depending on whether we are using the embedded SIS decoder or a wrapper
around the UCAR library.
*/
private final Decoder decoder;
- private URI sourceUri;
+
+ /**
+ * The {@link NetcdfStoreProvider#LOCATION} parameter value, or {@code
null} if none.
+ */
+ private final URI location;
/**
* The object returned by {@link #getMetadata()}, created when first
needed and cached.
@@ -88,11 +91,7 @@ public class NetcdfStore extends DataSto
*/
public NetcdfStore(final NetcdfStoreProvider provider, final
StorageConnector connector) throws DataStoreException {
super(provider, connector);
- try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
+ location = connector.getStorageAs(URI.class);
try {
decoder = NetcdfStoreProvider.decoder(listeners, connector);
} catch (IOException e) {
@@ -127,14 +126,19 @@ public class NetcdfStore extends DataSto
}
/**
- * {@inheritDoc }
+ * Returns the parameters used to open this netCDF data store.
+ * If non-null, the parameters are described by {@link
NetcdfStoreProvider#getOpenParameters()}
+ * and contains at least a parameter named {@value
NetcdfStoreProvider#LOCATION} with a {@link URI} value.
+ * This method may return {@code null} if the storage input can not be
described by a URI
+ * (for example a netCDF file reading directly from a {@link
java.nio.channels.ReadableByteChannel}).
+ *
+ * @return parameters used for opening this data store, or {@code null} if
not available.
+ *
+ * @since 0.8
*/
@Override
public ParameterValueGroup getOpenParameters() {
- if (sourceUri==null) return null;
- final Parameters parameters =
Parameters.castOrWrap(NetcdfStoreProvider.OPEN_DESCRIPTOR.createValue());
-
parameters.getOrCreate(NetcdfStoreProvider.PARAM_LOCATION).setValue(sourceUri);
- return parameters;
+ return URIDataStore.parameters(provider, location);
}
/**
Modified:
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -26,8 +26,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
-import java.net.URI;
-import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.apache.sis.internal.netcdf.Decoder;
import org.apache.sis.internal.netcdf.Resources;
@@ -36,9 +34,9 @@ import org.apache.sis.internal.netcdf.uc
import org.apache.sis.internal.storage.io.ChannelDataInput;
import org.apache.sis.internal.storage.Capabilities;
import org.apache.sis.internal.storage.Capability;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.system.SystemListener;
import org.apache.sis.internal.system.Modules;
-import org.apache.sis.parameter.ParameterBuilder;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.StorageConnector;
@@ -81,15 +79,9 @@ public class NetcdfStoreProvider extends
static final String MIME_TYPE = "application/x-netcdf";
/**
- * NetCDF location.
+ * The parameter descriptor to be returned by {@link #getOpenParameters()}.
*/
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new ParameterBuilder().addName(NAME).createGroup(PARAM_LOCATION);
+ private static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
URIDataStore.Provider.descriptor(NAME);
/**
* The name of the {@link ucar.nc2.NetcdfFile} class, which is {@value}.
@@ -150,7 +142,11 @@ public class NetcdfStoreProvider extends
}
/**
- * {@inheritDoc }
+ * Returns a description of all parameters accepted by this provider for
opening a netCDF file.
+ *
+ * @return description of available parameters for opening a netCDF file.
+ *
+ * @since 0.8
*/
@Override
public ParameterDescriptorGroup getOpenParameters() {
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -21,7 +21,6 @@ import org.opengis.metadata.distribution
import org.apache.sis.metadata.sql.MetadataSource;
import org.apache.sis.metadata.sql.MetadataStoreException;
import org.apache.sis.storage.DataStore;
-import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.logging.WarningListeners;
import org.apache.sis.internal.system.Modules;
@@ -36,7 +35,7 @@ import org.apache.sis.internal.system.Mo
* @since 0.8
* @module
*/
-public abstract class DocumentedStoreProvider extends DataStoreProvider {
+public abstract class DocumentedStoreProvider extends URIDataStore.Provider {
/**
* The primary key to use for searching in the {@code MD_Format} table, or
{@code null} if none.
* This primary name is also the value returned by {@link #getShortName()}
default implementation.
Added:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java?rev=1807614&view=auto
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
(added)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.storage;
+
+import java.net.URI;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.parameter.ParameterValueGroup;
+import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStoreProvider;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.StorageConnector;
+
+
+/**
+ * A data store for a storage that may be represented by a {@link URI}.
+ * It is still possible to create a data store with an {@link
java.nio.channels.ReadableByteChannel},
+ * {@link java.io.InputStream} or {@link java.io.Reader}, in which case the
{@linkplain #location} will be null.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since 0.8
+ * @module
+ */
+public abstract class URIDataStore extends DataStore {
+ /**
+ * The {@link DataStoreProvider#LOCATION} parameter value, or {@code null}
if none.
+ */
+ protected final URI location;
+
+ /**
+ * Creates a new data store.
+ *
+ * @param provider the factory that created this {@code URIDataStore}
instance, or {@code null} if unspecified.
+ * @param connector information about the storage (URL, stream, reader
instance, <i>etc</i>).
+ * @throws DataStoreException if an error occurred while creating the data
store for the given storage.
+ */
+ protected URIDataStore(final DataStoreProvider provider, final
StorageConnector connector) throws DataStoreException {
+ super(provider, connector);
+ location = connector.getStorageAs(URI.class);
+ }
+
+ /**
+ * Returns the parameters used to open this data store.
+ *
+ * @return parameters used for opening this {@code DataStore}, or {@code
null} if not available.
+ */
+ @Override
+ public ParameterValueGroup getOpenParameters() {
+ return parameters(provider, location);
+ }
+
+ /**
+ * Creates parameter value group for the current location, if non-null.
+ * This convenience method is used for public {@code DataStore}
implementations that can not extend
+ * {@code URIDataStore} directly, because this class is internal.
+ *
+ * @param provider
+ * @param location
+ * @return
+ *
+ * @todo Verify if non-exported classes in JDK9 are hidden from Javadoc,
like package-private classes.
+ * If true, we could remove this hack and extend {@code
URIDataStore} even in public classes.
+ */
+ public static ParameterValueGroup parameters(final DataStoreProvider
provider, final URI location) {
+ if (location == null || provider == null) return null;
+ final ParameterValueGroup pg =
provider.getOpenParameters().createValue();
+ pg.parameter(DataStoreProvider.LOCATION).setValue(location);
+ return pg;
+ }
+
+ /**
+ * Provider for {@link URIDataStore} instances.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since 0.8
+ * @module
+ */
+ public abstract static class Provider extends DataStoreProvider {
+ /**
+ * Description of the location parameter.
+ */
+ protected static final ParameterDescriptor<URI> LOCATION_PARAM = new
ParameterBuilder()
+ .addName(LOCATION)
+ .setRequired(true)
+ .create(URI.class, null);
+
+ /**
+ * The parameter descriptor to be returned by {@link
#getOpenParameters()}.
+ * Created when first needed.
+ */
+ private volatile ParameterDescriptorGroup openDescriptor;
+
+ /**
+ * Creates a new provider.
+ */
+ protected Provider() {
+ }
+
+ /**
+ * Returns a description of all parameters accepted by this provider
for opening a data store.
+ * This method creates the descriptor only when first needed.
Subclasses can override the
+ * {@link #build(ParameterBuilder)} method if they need to modify the
descriptor to create.
+ *
+ * @return description of the parameters required for opening a {@link
DataStore}.
+ */
+ @Override
+ public final ParameterDescriptorGroup getOpenParameters() {
+ ParameterDescriptorGroup desc = openDescriptor;
+ if (desc == null) {
+ openDescriptor = desc = build(new
ParameterBuilder().addName(getShortName()));
+ }
+ return desc;
+ }
+
+ /**
+ * Invoked by {@link #getOpenParameters()} the first time that a
parameter descriptor needs
+ * to be created. When invoked, the parameter group name is set to a
name derived from the
+ * {@link #getShortName()} value. The default implementation creates a
group containing only
+ * {@link #LOCATION_PARAM}. Subclasses can override if they need to
create a group with more
+ * parameters.
+ *
+ * @param builder the builder to use for creating parameter
descriptor. The group name is already set.
+ * @return the parameters descriptor created from the given builder.
+ */
+ protected ParameterDescriptorGroup build(final ParameterBuilder
builder) {
+ return builder.createGroup(LOCATION_PARAM);
+ }
+
+ /**
+ * Convenience method creating a parameter descriptor containing only
{@link #LOCATION_PARAM}.
+ * This convenience method is used for public providers that can not
extend this {@code Provider}
+ * class because it is internal.
+ *
+ * @param name short name of the data store format.
+ * @return the descriptor for open parameters.
+ *
+ * @todo Verify if non-exported classes in JDK9 are hidden from
Javadoc, like package-private classes.
+ * If true, we could remove this hack and extend {@code
URIDataStore} even in public classes.
+ */
+ public static ParameterDescriptorGroup descriptor(final String name) {
+ return new
ParameterBuilder().addName(name).createGroup(LOCATION_PARAM);
+ }
+ }
+}
Propchange:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -38,7 +38,6 @@ import org.opengis.metadata.maintenance.
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.crs.TemporalCRS;
import org.opengis.referencing.operation.TransformException;
-import org.opengis.parameter.ParameterValueGroup;
import org.apache.sis.feature.DefaultAttributeType;
import org.apache.sis.feature.DefaultFeatureType;
import org.apache.sis.referencing.CRS;
@@ -50,11 +49,11 @@ import org.apache.sis.internal.storage.i
import org.apache.sis.internal.feature.Geometries;
import org.apache.sis.internal.feature.MovingFeature;
import org.apache.sis.internal.storage.Resources;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.geometry.GeneralEnvelope;
import org.apache.sis.geometry.ImmutableEnvelope;
import org.apache.sis.metadata.iso.DefaultMetadata;
import org.apache.sis.metadata.sql.MetadataStoreException;
-import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.DataStoreContentException;
import org.apache.sis.storage.DataStoreReferencingException;
@@ -87,7 +86,7 @@ import org.opengis.feature.AttributeType
* @since 0.7
* @module
*/
-public final class Store extends DataStore implements FeatureSet {
+public final class Store extends URIDataStore implements FeatureSet {
/**
* The character at the beginning of lines to ignore in the header.
* Note that this is not part of OGC Moving Feature Specification.
@@ -138,7 +137,6 @@ public final class Store extends DataSto
* @see #readLine()
*/
private BufferedReader source;
- private URI sourceUri;
/**
* The character encoding, or {@code null} if unspecified (in which case
the platform default is assumed).
@@ -235,11 +233,6 @@ public final class Store extends DataSto
{
super(provider, connector);
final Reader r = connector.getStorageAs(Reader.class);
- try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
connector.closeAllExcept(r);
if (r == null) {
throw new UnsupportedStorageException(super.getLocale(),
StoreProvider.NAME,
@@ -639,19 +632,6 @@ public final class Store extends DataSto
}
/**
- * Returns the parameters used to open this data store.
- *
- * @return parameters used for opening this {@code DataStore}, or {@code
null} if not available.
- */
- @Override
- public ParameterValueGroup getOpenParameters() {
- if (sourceUri == null) return null;
- final ParameterValueGroup pg =
StoreProvider.OPEN_DESCRIPTOR.createValue();
- pg.parameter(StoreProvider.LOCATION).setValue(sourceUri);
- return pg;
- }
-
- /**
* Returns the type of features in the CSV file. The feature type name
will be the value
* specified at the following path (only one such value exists for a CSV
data store):
*
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,18 +16,14 @@
*/
package org.apache.sis.internal.storage.csv;
-import java.net.URI;
-import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.ParameterDescriptorGroup;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.ProbeResult;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.internal.storage.Capability;
import org.apache.sis.internal.storage.Capabilities;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.storage.wkt.FirstKeywordPeek;
-import org.apache.sis.parameter.ParameterBuilder;
/**
@@ -44,24 +40,13 @@ import org.apache.sis.parameter.Paramete
* @module
*/
@Capabilities(Capability.READ)
-public final class StoreProvider extends DataStoreProvider {
+public final class StoreProvider extends URIDataStore.Provider {
/**
* The format names for static features and moving features.
*/
static final String NAME = "CSV", MOVING = "CSV-MF";
/**
- * CSV source.
- */
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new ParameterBuilder().addName(NAME).createGroup(PARAM_LOCATION);
-
- /**
* The object to use for verifying if the first keyword is the expected
one.
*/
private static final class Peek extends FirstKeywordPeek {
@@ -132,14 +117,6 @@ public final class StoreProvider extends
}
/**
- * {@inheritDoc }
- */
- @Override
- public ParameterDescriptorGroup getOpenParameters() {
- return OPEN_DESCRIPTOR;
- }
-
- /**
* Returns {@link ProbeResult#SUPPORTED} if the given storage appears to
be supported by CSV {@link Store}.
* Returning {@code SUPPORTED} from this method does not guarantee that
reading or writing will succeed, only
* that there appears to be a reasonable chance of success based on a
brief inspection of the storage header.
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -23,25 +23,23 @@ import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.io.Reader;
import java.io.IOException;
-import java.net.URI;
import java.text.ParsePosition;
import java.text.ParseException;
import org.opengis.metadata.Metadata;
import org.opengis.util.FactoryException;
import org.opengis.referencing.ReferenceSystem;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.parameter.ParameterValueGroup;
import org.apache.sis.internal.storage.Resources;
import org.apache.sis.internal.system.Loggers;
import org.apache.sis.io.wkt.WKTFormat;
import org.apache.sis.io.wkt.Warnings;
-import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.DataStoreContentException;
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.internal.referencing.DefinitionVerifier;
import org.apache.sis.internal.storage.MetadataBuilder;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.setup.OptionKey;
import org.apache.sis.util.CharSequences;
@@ -54,7 +52,7 @@ import org.apache.sis.util.CharSequences
* @since 0.7
* @module
*/
-final class Store extends DataStore {
+final class Store extends URIDataStore {
/**
* Arbitrary size limit. Files that big are likely to be something else
than WKT,
* so this limit allows earlier error reporting than loading huge amount
of data
@@ -66,7 +64,6 @@ final class Store extends DataStore {
* The reader, set by the constructor and cleared when no longer needed.
*/
private Reader source;
- private URI sourceUri;
/**
* The parsed objects, filled only when first needed.
@@ -90,11 +87,6 @@ final class Store extends DataStore {
super(provider, connector);
objects = new ArrayList<>();
source = connector.getStorageAs(Reader.class);
- try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
connector.closeAllExcept(source);
if (source == null) {
throw new UnsupportedStorageException(super.getLocale(),
StoreProvider.NAME,
@@ -203,19 +195,6 @@ final class Store extends DataStore {
}
/**
- * Returns the parameters used to open this data store.
- *
- * @return parameters used for opening this {@code DataStore}, or {@code
null} if not available.
- */
- @Override
- public ParameterValueGroup getOpenParameters() {
- if (sourceUri == null) return null;
- final ParameterValueGroup pg =
StoreProvider.OPEN_DESCRIPTOR.createValue();
- pg.parameter(StoreProvider.LOCATION).setValue(sourceUri);
- return pg;
- }
-
- /**
* Closes this data store and releases any underlying resources.
*
* @throws DataStoreException if an error occurred while closing this data
store.
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,21 +16,17 @@
*/
package org.apache.sis.internal.storage.wkt;
-import java.net.URI;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.ParameterDescriptorGroup;
import org.apache.sis.storage.DataStore;
-import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.ProbeResult;
import org.apache.sis.internal.storage.Capability;
import org.apache.sis.internal.storage.Capabilities;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.metadata.WKTKeywords;
-import org.apache.sis.parameter.ParameterBuilder;
import org.apache.sis.util.Version;
@@ -43,7 +39,7 @@ import org.apache.sis.util.Version;
* @module
*/
@Capabilities(Capability.READ)
-public final class StoreProvider extends DataStoreProvider {
+public final class StoreProvider extends URIDataStore.Provider {
/**
* The format name.
*/
@@ -55,17 +51,6 @@ public final class StoreProvider extends
public static final String MIME_TYPE = "application/wkt";
/**
- * WKT source.
- */
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new ParameterBuilder().addName(NAME).createGroup(PARAM_LOCATION);
-
- /**
* The object to use for verifying if the first keyword is a WKT one.
* This object contains the set of recognized WKT keywords.
*/
@@ -176,14 +161,6 @@ public final class StoreProvider extends
}
/**
- * {@inheritDoc }
- */
- @Override
- public ParameterDescriptorGroup getOpenParameters() {
- return OPEN_DESCRIPTOR;
- }
-
- /**
* Returns {@link ProbeResult#SUPPORTED} if the given storage appears to
be supported by WKT {@link Store}.
* Returning {@code SUPPORTED} from this method does not guarantee that
reading or writing will succeed,
* only that there appears to be a reasonable chance of success based on a
brief inspection of the storage
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -23,16 +23,13 @@ import java.io.Closeable;
import java.io.Reader;
import java.io.InputStream;
import java.io.IOException;
-import java.net.URI;
import javax.xml.bind.JAXBException;
import javax.xml.transform.stream.StreamSource;
import org.opengis.metadata.Metadata;
import org.opengis.util.FactoryException;
import org.opengis.referencing.ReferenceSystem;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.parameter.ParameterValueGroup;
import org.apache.sis.xml.XML;
-import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.UnsupportedStorageException;
@@ -40,6 +37,7 @@ import org.apache.sis.metadata.iso.Defau
import org.apache.sis.util.logging.WarningListener;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.storage.MetadataBuilder;
import org.apache.sis.internal.referencing.DefinitionVerifier;
import org.apache.sis.setup.OptionKey;
@@ -62,12 +60,11 @@ import org.apache.sis.setup.OptionKey;
* @since 0.4
* @module
*/
-final class Store extends DataStore {
+final class Store extends URIDataStore {
/**
* The input stream or reader, set by the constructor and cleared when no
longer needed.
*/
private StreamSource source;
- private URI sourceUri;
/**
* The unmarshalled object, initialized only when first needed.
@@ -90,11 +87,6 @@ final class Store extends DataStore {
public Store(final StoreProvider provider, final StorageConnector
connector) throws DataStoreException {
super(provider, connector);
final InputStream in = connector.getStorageAs(InputStream.class);
- try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
if (in != null) {
source = new StreamSource(in);
} else {
@@ -219,19 +211,6 @@ final class Store extends DataStore {
}
/**
- * Returns the parameters used to open this data store.
- *
- * @return parameters used for opening this {@code DataStore}, or {@code
null} if not available.
- */
- @Override
- public ParameterValueGroup getOpenParameters() {
- if (sourceUri == null) return null;
- final ParameterValueGroup pg =
StoreProvider.OPEN_DESCRIPTOR.createValue();
- pg.parameter(StoreProvider.LOCATION).setValue(sourceUri);
- return pg;
- }
-
- /**
* Closes this data store and releases any underlying resources.
*
* @throws DataStoreException if an error occurred while closing this data
store.
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/StoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/StoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/StoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/StoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,16 +16,12 @@
*/
package org.apache.sis.internal.storage.xml;
-import java.net.URI;
-import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.ParameterDescriptorGroup;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.internal.storage.Capabilities;
import org.apache.sis.internal.storage.Capability;
-import org.apache.sis.parameter.ParameterBuilder;
/**
@@ -44,17 +40,6 @@ public final class StoreProvider extends
static final String NAME = "XML";
/**
- * XML source.
- */
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new ParameterBuilder().addName(NAME).createGroup(PARAM_LOCATION);
-
- /**
* Creates a new provider.
*/
public StoreProvider() {
@@ -76,14 +61,6 @@ public final class StoreProvider extends
}
/**
- * {@inheritDoc }
- */
- @Override
- public ParameterDescriptorGroup getOpenParameters() {
- return OPEN_DESCRIPTOR;
- }
-
- /**
* Returns a {@link Store} implementation associated with this provider.
*
* @param connector information about the storage (URL, stream,
<i>etc</i>).
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -33,6 +33,13 @@ import org.apache.sis.internal.util.Cita
/**
* Manages a series of features, coverages or sensor data.
+ * Different {@code DataStore} subclasses exist for different formats (netCDF,
GeoTIFF, <i>etc.</i>).
+ * The supported format can be identifier by the {@linkplain #getProvider()
provider}.
+ *
+ * <p>Each data store is itself a {@link Resource}. The data store subclasses
should implement
+ * a more specialized {@code Resource} interface depending on the format
characteristics.
+ * For example a {@code DataStore} for ShapeFiles will implement the {@link
FeatureSet} interface,
+ * while a {@code DataStore} for netCDF files will implement the {@link
Aggregate} interface.</p>
*
* <div class="section">Thread safety policy</div>
* This {@code DataStore} base class is thread-safe. However subclasses do not
need to be thread-safe.
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -144,11 +144,12 @@ public interface FeatureSet extends Data
/**
* Updates all features from this {@code FeatureSet} which matches the
given predicate.
* For each {@link Feature} instance matching the given {@link Predicate},
- * the <code>{@linkplain UnaryOperator#apply
UnaryOperator.apply(Feature)}</code> method
- * will be invoked. Two behaviors are possible:
+ * the <code>{@linkplain UnaryOperator#apply
UnaryOperator.apply(Feature)}</code> method will be invoked.
+ * {@code UnaryOperator}s are free to modify the given {@code Feature}
<i>in-place</i> or to return a
+ * different feature instance. Two behaviors are possible:
* <ul>
* <li>If the operator returns a non-null {@link Feature}, then the
modified feature is stored
- * in replacement of the previous feature. There is no guarantee
that order is preserved.</li>
+ * in replacement of the previous feature (not necessarily at the
same location).</li>
* <li>If the operator returns {@code null}, then the feature will be
removed from the {@code FeatureSet}.</li>
* </ul>
*
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -43,15 +43,18 @@ import org.apache.sis.util.Classes;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.ObjectConverters;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.collection.TreeTable;
import org.apache.sis.util.collection.TableColumn;
import org.apache.sis.util.collection.DefaultTreeTable;
+import org.apache.sis.util.UnconvertibleObjectException;
import org.apache.sis.internal.storage.Resources;
import org.apache.sis.internal.storage.io.IOUtilities;
import org.apache.sis.internal.storage.io.ChannelFactory;
import org.apache.sis.internal.storage.io.ChannelDataInput;
import org.apache.sis.internal.storage.io.ChannelImageInputStream;
import org.apache.sis.internal.storage.io.InputStreamAdapter;
+import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.util.Utilities;
import org.apache.sis.io.InvalidSeekException;
import org.apache.sis.setup.OptionKey;
@@ -159,8 +162,9 @@ public class StorageConnector implements
/**
* List of types recognized by {@link #getStorageAs(Class)}, associated to
the methods for opening stream
* of those types. This map shall contain every types documented in {@link
#getStorageAs(Class)} javadoc.
+ * {@code null} values means to use {@link ObjectConverters} for that
particular type.
*/
- private static final Map<Class<?>, Opener<?>> OPENERS = new
IdentityHashMap<>(12);
+ private static final Map<Class<?>, Opener<?>> OPENERS = new
IdentityHashMap<>(13);
static {
add(String.class, StorageConnector::createString);
add(ByteBuffer.class, StorageConnector::createByteBuffer);
@@ -176,7 +180,15 @@ public class StorageConnector implements
* Caller should have asked for another type (e.g. InputStream) before
to ask for that type.
* Consequently null value for ChannelFactory shall not be cached
since the actual value may
* be computed later.
- */
+ *
+ * Following classes will be converted using ObjectConverters, but
without throwing an
+ * exception if the conversion fail. Instead, getStorageAs(Class) will
return null.
+ * Classes not listed here will let the UnconvertibleObjectException
propagates.
+ */
+ add(java.net.URI.class, null);
+ add(java.net.URL.class, null);
+ add(java.io.File.class, null);
+ add(java.nio.file.Path.class, null);
}
/**
@@ -640,6 +652,15 @@ public class StorageConnector implements
* <li>Otherwise this method returns {@code null}.</li>
* </ul>
* </li>
+ * <li>{@link java.nio.file.Path}, {@link java.net.URI}, {@link
java.net.URL}, {@link java.io.File}:
+ * <ul>
+ * <li>If the {@linkplain #getStorage() storage} object is an
instance of the {@link java.nio.file.Path},
+ * {@link java.io.File}, {@link java.net.URL}, {@link
java.net.URI} or {@link CharSequence} types and
+ * that type can be converted to the requested type, returned
the conversion result.</li>
+ *
+ * <li>Otherwise this method returns {@code null}.</li>
+ * </ul>
+ * </li>
* <li>{@link ByteBuffer}:
* <ul>
* <li>If the {@linkplain #getStorage() storage} object can be
obtained as described in bullet 2 of the
@@ -706,6 +727,14 @@ public class StorageConnector implements
* <li>Otherwise this method returns {@code null}.</li>
* </ul>
* </li>
+ * <li>Any other types:
+ * <ul>
+ * <li>If the storage given at construction time is already an
instance of the requested type,
+ * returns it <i>as-is</i>.</li>
+ *
+ * <li>Otherwise this method throws {@link
IllegalArgumentException}.</li>
+ * </ul>
+ * </li>
* </ul>
*
* Multiple invocations of this method on the same {@code
StorageConnector} instance will try
@@ -776,7 +805,14 @@ public class StorageConnector implements
*/
final Opener<?> method = OPENERS.get(type);
if (method == null) {
- final T view = ObjectConverters.convert(storage, type);
+ T view;
+ try {
+ view = ObjectConverters.convert(storage, type);
+ } catch (UnconvertibleObjectException e) {
+ if (!OPENERS.containsKey(type)) throw e;
+
Logging.recoverableException(Logging.getLogger(Modules.STORAGE),
StorageConnector.class, "getStorageAs", e);
+ view = null;
+ }
addView(type, view);
return view;
}
Modified:
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/StorageConnectorTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/StorageConnectorTest.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/StorageConnectorTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/StorageConnectorTest.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,6 +16,7 @@
*/
package org.apache.sis.storage;
+import java.net.URI;
import java.io.DataInput;
import java.io.InputStream;
import java.io.Reader;
@@ -27,6 +28,7 @@ import javax.imageio.stream.ImageInputSt
import javax.imageio.ImageIO;
import java.sql.Connection;
import org.apache.sis.setup.OptionKey;
+import org.apache.sis.util.UnconvertibleObjectException;
import org.apache.sis.internal.storage.io.ChannelDataInput;
import org.apache.sis.internal.storage.io.ChannelImageInputStream;
import org.apache.sis.internal.storage.io.InputStreamAdapter;
@@ -349,6 +351,28 @@ public final strictfp class StorageConne
connection.closeAllExcept(null);
}
+ /**
+ * Verifies that {@link StorageConnector#getStorageAs(Class)} returns
{@code null} for unavailable
+ * target classes, and throws an exception for illegal target classes.
+ *
+ * @throws DataStoreException if an error occurred while using the storage
connector.
+ */
+ @Test
+ public void testGetInvalidObject() throws DataStoreException {
+ final StorageConnector connection = create(true);
+ assertNotNull("getStorageAs(InputStream.class)",
connection.getStorageAs(InputStream.class));
+ assertNull ("getStorageAs(URI.class)",
connection.getStorageAs(URI.class));
+ assertNull ("getStorageAs(String.class)",
connection.getStorageAs(String.class));
+ try {
+ connection.getStorageAs(Float.class); // Any unconvertible
type.
+ fail("Should not have accepted Float.class");
+ } catch (UnconvertibleObjectException e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains("Float"));
+ }
+ connection.closeAllExcept(null);
+ }
+
/**
* Tests the {@link StorageConnector#closeAllExcept(Object)} method.
*
Modified:
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Store.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Store.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Store.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Store.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -20,7 +20,6 @@ import java.net.URISyntaxException;
import org.opengis.util.NameFactory;
import org.opengis.util.FactoryException;
import org.opengis.geometry.Envelope;
-import org.opengis.parameter.ParameterValueGroup;
import org.opengis.metadata.Metadata;
import org.opengis.metadata.distribution.Format;
import org.apache.sis.storage.FeatureSet;
@@ -182,19 +181,6 @@ public final class Store extends StaxDat
}
/**
- * Returns the parameters used to open this data store.
- *
- * @return parameters used for opening this {@code DataStore}, or {@code
null} if not available.
- */
- @Override
- public ParameterValueGroup getOpenParameters() {
- if (sourceUri == null) return null;
- final ParameterValueGroup pg =
StoreProvider.OPEN_DESCRIPTOR.createValue();
- pg.parameter(StoreProvider.LOCATION).setValue(sourceUri);
- return pg;
- }
-
- /**
* Returns the base type of all GPX types.
*
* @return base type of all GPX types.
Modified:
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/StoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/StoreProvider.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/StoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/StoreProvider.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -16,7 +16,6 @@
*/
package org.apache.sis.internal.storage.gpx;
-import java.net.URI;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.sis.storage.DataStore;
@@ -26,11 +25,7 @@ import org.apache.sis.internal.storage.C
import org.apache.sis.internal.storage.Capabilities;
import org.apache.sis.internal.storage.xml.stream.StaxDataStoreProvider;
import org.apache.sis.measure.Range;
-import org.apache.sis.parameter.ParameterBuilder;
-import static org.apache.sis.storage.DataStoreProvider.LOCATION;
import org.apache.sis.util.Version;
-import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.ParameterDescriptorGroup;
/**
@@ -46,16 +41,6 @@ import org.opengis.parameter.ParameterDe
@Capabilities({Capability.READ, Capability.WRITE})
public final class StoreProvider extends StaxDataStoreProvider {
/**
- * XML source.
- */
- static final ParameterDescriptor<URI> PARAM_LOCATION = new
ParameterBuilder()
- .addName(LOCATION)
- .setRequired(true)
- .create(URI.class, null);
-
- static final ParameterDescriptorGroup OPEN_DESCRIPTOR =
- new ParameterBuilder().addName("GPX").createGroup(PARAM_LOCATION);
- /**
* The "1.0" version.
*/
static final Version V1_0 = Version.valueOf(1,0);
@@ -90,14 +75,6 @@ public final class StoreProvider extends
}
/**
- * {@inheritDoc }
- */
- @Override
- public ParameterDescriptorGroup getOpenParameters() {
- return OPEN_DESCRIPTOR;
- }
-
- /**
* Returns a GPX {@link Store} implementation associated with this
provider.
*
* @param connector information about the storage (URL, stream,
<i>etc</i>).
Modified:
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java?rev=1807614&r1=1807613&r2=1807614&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/xml/stream/StaxDataStore.java
[UTF-8] Thu Sep 7 15:04:44 2017
@@ -23,7 +23,6 @@ import java.util.logging.LogRecord;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.nio.file.Path;
import java.nio.charset.Charset;
import java.nio.file.StandardOpenOption;
@@ -39,6 +38,7 @@ import org.apache.sis.setup.OptionKey;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.internal.storage.io.ChannelFactory;
import org.apache.sis.internal.storage.io.IOUtilities;
import org.apache.sis.internal.storage.io.Markable;
@@ -65,7 +65,7 @@ import org.apache.sis.util.Debug;
* @since 0.8
* @module
*/
-public abstract class StaxDataStore extends DataStore {
+public abstract class StaxDataStore extends URIDataStore {
/**
* The locale to use for locale-sensitive data (<strong>not</strong> for
logging or warning messages),
* or {@code null} if unspecified.
@@ -115,7 +115,6 @@ public abstract class StaxDataStore exte
* @see StorageConnector#getStorage()
*/
private Object storage;
- protected URI sourceUri;
/**
* The underlying stream to close when this {@code StaxDataStore} is
closed, or {@code null} if none.
@@ -232,11 +231,6 @@ public abstract class StaxDataStore exte
stream = (AutoCloseable) storage;
}
channelFactory = connector.getStorageAs(ChannelFactory.class); //
Must be last before 'closeAllExcept'.
- try {
- sourceUri = connector.getStorageAs(URI.class);
- } catch (IllegalArgumentException ex) {
- //open parameters will be null.
- }
connector.closeAllExcept(stream);
/*
* If possible, remember the position where data begin in the stream
in order to allow reading
@@ -379,8 +373,11 @@ public abstract class StaxDataStore exte
/**
* Returns the factory that created this {@code DataStore} instance, or
{@code null} if unspecified.
+ *
+ * @return the factory that created this {@code DataStore} instance, or
{@code null} if unspecified.
*/
- public StaxDataStoreProvider getProvider() {
+ @Override
+ public final StaxDataStoreProvider getProvider() {
return (StaxDataStoreProvider) provider;
}