You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2017/09/08 14:31:31 UTC
svn commit: r1807768 - in /sis/branches/JDK8:
core/sis-feature/src/main/java/org/apache/sis/internal/feature/
storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/
storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/
storage...
Author: desruisseaux
Date: Fri Sep 8 14:31:31 2017
New Revision: 1807768
URL: http://svn.apache.org/viewvc?rev=1807768&view=rev
Log:
Allows to configure the library to use for geometric objects.
Modified:
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/DiscreteSampling.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/FeaturesWrapper.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-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java
sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderAggregate.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -93,7 +93,7 @@ public abstract class Geometries<G> {
this.pointClass = pointClass;
this.polylineClass = polylineClass;
this.polygonClass = polygonClass;
- fallback = implementation;
+ this.fallback = implementation;
}
/**
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -24,6 +24,7 @@ import java.io.IOException;
import javax.measure.Unit;
import javax.measure.format.ParserException;
import org.apache.sis.measure.Units;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.util.logging.WarningListeners;
@@ -42,6 +43,13 @@ import org.apache.sis.util.logging.Warni
*/
public abstract class Decoder implements Closeable {
/**
+ * The library for geometric objects, or {@code null} for the default.
+ * This will be used only if there is geometric objects to create.
+ * If the netCDF file contains only raster data, this value is ignored.
+ */
+ public final GeometryLibrary geomlib;
+
+ /**
* Where to send the warnings.
*/
public final WarningListeners<DataStore> listeners;
@@ -55,10 +63,12 @@ public abstract class Decoder implements
/**
* Creates a new decoder.
*
+ * @param geomlib the library for geometric objects, or {@code null} for the default.
* @param listeners where to send the warnings.
*/
- protected Decoder(final WarningListeners<DataStore> listeners) {
+ protected Decoder(final GeometryLibrary geomlib, final WarningListeners<DataStore> listeners) {
Objects.requireNonNull(listeners);
+ this.geomlib = geomlib;
this.listeners = listeners;
}
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/DiscreteSampling.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/DiscreteSampling.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/DiscreteSampling.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/DiscreteSampling.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -16,6 +16,9 @@
*/
package org.apache.sis.internal.netcdf;
+import org.apache.sis.setup.GeometryLibrary;
+import org.apache.sis.internal.feature.Geometries;
+
// Branch-dependent imports
import java.util.stream.Stream;
import org.opengis.feature.Feature;
@@ -34,9 +37,18 @@ import org.opengis.feature.Feature;
*/
public abstract class DiscreteSampling {
/**
+ * The factory to use for creating geometries.
+ */
+ protected final Geometries<?> factory;
+
+ /**
* Creates a new discrete sampling parser.
+ *
+ * @param library the library for geometric objects, or {@code null} for the default.
+ * @throws IllegalArgumentException if the given library is non-null but not available.
*/
- protected DiscreteSampling() {
+ protected DiscreteSampling(final GeometryLibrary library) {
+ factory = Geometries.implementation(library);
}
/**
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -55,6 +55,7 @@ import org.apache.sis.util.resources.Err
import org.apache.sis.util.resources.Vocabulary;
import org.apache.sis.util.logging.WarningListeners;
import org.apache.sis.util.Debug;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.measure.Units;
import ucar.nc2.constants.CF;
@@ -220,15 +221,16 @@ public final class ChannelDecoder extend
* <li>List of variables (see {@link #readVariables(int, Dimension[])})</li>
* </ul>
*
- * @param listeners where to send the warnings.
+ * @param geomlib the library for geometric objects, or {@code null} for the default.
* @param input the channel and the buffer from where data are read.
+ * @param listeners where to send the warnings.
* @throws IOException if an error occurred while reading the channel.
* @throws DataStoreException if the content of the given channel is not a NetCDF file.
*/
- public ChannelDecoder(final WarningListeners<DataStore> listeners, final ChannelDataInput input)
+ public ChannelDecoder(final ChannelDataInput input, final GeometryLibrary geomlib, final WarningListeners<DataStore> listeners)
throws IOException, DataStoreException
{
- super(listeners);
+ super(geomlib, listeners);
this.input = input;
/*
* Check the magic number, which is expected to be exactly 3 bytes forming the "CDF" string.
@@ -769,8 +771,10 @@ public final class ChannelDecoder extend
*/
@Override
public DiscreteSampling[] getDiscreteSampling() throws IOException, DataStoreException {
- if ("trajectory".equalsIgnoreCase(stringValue(CF.FEATURE_TYPE))) {
+ if ("trajectory".equalsIgnoreCase(stringValue(CF.FEATURE_TYPE))) try {
return FeaturesInfo.create(this);
+ } catch (IllegalArgumentException e) {
+ throw new DataStoreException(e.getLocalizedMessage(), e);
}
return new FeaturesInfo[0];
}
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -27,12 +27,12 @@ import org.apache.sis.math.Vector;
import org.apache.sis.internal.netcdf.DataType;
import org.apache.sis.internal.netcdf.DiscreteSampling;
import org.apache.sis.internal.netcdf.Resources;
-import org.apache.sis.internal.feature.Geometries;
import org.apache.sis.internal.feature.MovingFeature;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.feature.DefaultFeatureType;
import org.apache.sis.feature.DefaultAttributeType;
import org.apache.sis.util.collection.BackingStoreException;
+import org.apache.sis.setup.GeometryLibrary;
import ucar.nc2.constants.CF;
// Branch-dependent imports
@@ -88,18 +88,20 @@ final class FeaturesInfo extends Discret
*/
private final FeatureType type;
- private final Geometries<?> factory = Geometries.implementation(null); // TODO: shall be given by the store.
-
/**
* Creates a new discrete sampling parser for features identified by the given variable.
*
* @param counts the count of instances per feature.
* @param identifiers the feature identifiers.
+ * @param library the library for geometric objects, or {@code null} for the default.
+ * @throws IllegalArgumentException if the given library is non-null but not available.
*/
@SuppressWarnings("rawtypes") // Because of generic array creation.
private FeaturesInfo(final Vector counts, final VariableInfo identifiers, final VariableInfo time,
- final Collection<VariableInfo> coordinates, final Collection<VariableInfo> properties)
+ final Collection<VariableInfo> coordinates, final Collection<VariableInfo> properties,
+ final GeometryLibrary library)
{
+ super(library);
this.counts = counts;
this.identifiers = identifiers;
this.coordinates = coordinates.toArray(new VariableInfo[coordinates.size()]);
@@ -154,6 +156,8 @@ final class FeaturesInfo extends Discret
/**
* Creates new discrete sampling parsers from the attribute values found in the given decoder.
+ *
+ * @throws IllegalArgumentException if the geometric object library is not available.
*/
static FeaturesInfo[] create(final ChannelDecoder decoder) throws IOException, DataStoreException {
final List<FeaturesInfo> features = new ArrayList<>(3); // Will usually contain at most one element.
@@ -266,7 +270,8 @@ search: for (final VariableInfo counts :
}
final VariableInfo time = coordinates.remove("T");
if (time != null) {
- features.add(new FeaturesInfo(counts.read().compress(0), identifiers, time, coordinates.values(), properties));
+ features.add(new FeaturesInfo(counts.read().compress(0), identifiers,
+ time, coordinates.values(), properties, decoder.geomlib));
}
}
}
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -45,7 +45,9 @@ import org.apache.sis.internal.netcdf.De
import org.apache.sis.internal.netcdf.Variable;
import org.apache.sis.internal.netcdf.GridGeometry;
import org.apache.sis.internal.netcdf.DiscreteSampling;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStoreException;
/**
@@ -100,24 +102,28 @@ public final class DecoderWrapper extend
* {@link NetcdfFile} instance, the {@link NetcdfDataset} subclass is necessary in order to
* get coordinate system information.
*
- * @param listeners where to send the warnings.
+ * @param geomlib the library for geometric objects, or {@code null} for the default.
* @param file the NetCDF file from which to read data.
+ * @param listeners where to send the warnings.
*/
- public DecoderWrapper(final WarningListeners<DataStore> listeners, final NetcdfFile file) {
- super(listeners);
+ public DecoderWrapper(final NetcdfFile file, final GeometryLibrary geomlib, final WarningListeners<DataStore> listeners) {
+ super(geomlib, listeners);
this.file = file;
}
/**
* Creates a new decoder for the given filename.
*
- * @param listeners where to send the warnings.
+ * @param geomlib the library for geometric objects, or {@code null} for the default.
* @param filename the name of the NetCDF file from which to read data.
+ * @param listeners where to send the warnings.
* @throws IOException if an error occurred while opening the NetCDF file.
*/
@SuppressWarnings("ThisEscapedInObjectConstruction")
- public DecoderWrapper(final WarningListeners<DataStore> listeners, final String filename) throws IOException {
- super(listeners);
+ public DecoderWrapper(final String filename, final GeometryLibrary geomlib, final WarningListeners<DataStore> listeners)
+ throws IOException
+ {
+ super(geomlib, listeners);
file = NetcdfDataset.openDataset(filename, false, this);
}
@@ -358,10 +364,11 @@ public final class DecoderWrapper extend
*
* @return {@inheritDoc}
* @throws IOException if an I/O operation was necessary but failed.
+ * @throws DataStoreException if the library of geometric objects is not available.
*/
@Override
@SuppressWarnings("null")
- public DiscreteSampling[] getDiscreteSampling() throws IOException {
+ public DiscreteSampling[] getDiscreteSampling() throws IOException, DataStoreException {
if (features == null && file instanceof NetcdfDataset) {
features = FeatureDatasetFactoryManager.wrap(null, (NetcdfDataset) file, this,
new Formatter(new LogAdapter(listeners), listeners.getLocale()));
@@ -371,8 +378,12 @@ public final class DecoderWrapper extend
fc = ((FeatureDatasetPoint) features).getPointFeatureCollectionList();
}
final FeaturesWrapper[] wrappers = new FeaturesWrapper[(fc != null) ? fc.size() : 0];
- for (int i=0; i<wrappers.length; i++) {
- wrappers[i] = new FeaturesWrapper(fc.get(i));
+ try {
+ for (int i=0; i<wrappers.length; i++) {
+ wrappers[i] = new FeaturesWrapper(fc.get(i), geomlib);
+ }
+ } catch (IllegalArgumentException e) {
+ throw new DataStoreException(e.getLocalizedMessage(), e);
}
return wrappers;
}
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/FeaturesWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/FeaturesWrapper.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/FeaturesWrapper.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/FeaturesWrapper.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -16,6 +16,7 @@
*/
package org.apache.sis.internal.netcdf.ucar;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.internal.netcdf.DiscreteSampling;
import ucar.nc2.ft.FeatureCollection;
@@ -40,8 +41,12 @@ final class FeaturesWrapper extends Disc
/**
* Creates a new discrete sampling parser.
+ *
+ * @param factory the library for geometric objects, or {@code null} for the default.
+ * @throws IllegalArgumentException if the given library is non-null but not available.
*/
- FeaturesWrapper(final FeatureCollection features) {
+ FeaturesWrapper(final FeatureCollection features, final GeometryLibrary factory) {
+ super(factory);
this.features = features;
}
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=1807768&r1=1807767&r2=1807768&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] Fri Sep 8 14:31:31 2017
@@ -18,6 +18,7 @@ package org.apache.sis.storage.netcdf;
import java.io.IOException;
import java.net.URI;
+import java.util.Collection;
import org.opengis.metadata.Metadata;
import org.opengis.parameter.ParameterValueGroup;
import org.apache.sis.util.Debug;
@@ -25,10 +26,12 @@ import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.Aggregate;
import org.apache.sis.internal.netcdf.Decoder;
import org.apache.sis.internal.storage.URIDataStore;
import org.apache.sis.metadata.ModifiableMetadata;
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;
@@ -46,7 +49,7 @@ import ucar.nc2.constants.CDM;
* @since 0.3
* @module
*/
-public class NetcdfStore extends DataStore {
+public class NetcdfStore extends DataStore implements Aggregate {
/**
* The object to use for decoding the NetCDF file content. There is two different implementations,
* depending on whether we are using the embedded SIS decoder or a wrapper around the UCAR library.
@@ -161,6 +164,19 @@ public class NetcdfStore extends DataSto
}
/**
+ * Returns the resources (features or coverages) in this netCDF file.
+ *
+ * @return children resources that are components of this netCDF.
+ * @throws DataStoreException if an error occurred while fetching the components.
+ *
+ * @since 0.8
+ */
+ @Override
+ public Collection<Resource> components() throws DataStoreException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ /**
* Closes this NetCDF store and releases any underlying resources.
*
* @throws DataStoreException if an error occurred while closing the NetCDF file.
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=1807768&r1=1807767&r2=1807768&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] Fri Sep 8 14:31:31 2017
@@ -37,6 +37,8 @@ import org.apache.sis.internal.storage.C
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.setup.GeometryLibrary;
+import org.apache.sis.setup.OptionKey;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.StorageConnector;
@@ -256,34 +258,35 @@ public class NetcdfStoreProvider extends
* {@link StorageConnector#closeAllExcept(Object)} after the decoder has been created.
*
* @param listeners where to send the warnings.
- * @param storage information about the input (file, input stream, <i>etc.</i>)
+ * @param connector information about the input (file, input stream, <i>etc.</i>)
* @return the decoder for the given input, or {@code null} if the input type is not recognized.
* @throws IOException if an error occurred while opening the NetCDF file.
* @throws DataStoreException if a logical error (other than I/O) occurred.
*/
- static Decoder decoder(final WarningListeners<DataStore> listeners, final StorageConnector storage)
+ static Decoder decoder(final WarningListeners<DataStore> listeners, final StorageConnector connector)
throws IOException, DataStoreException
{
+ final GeometryLibrary geomlib = connector.getOption(OptionKey.GEOMETRY_LIBRARY);
Decoder decoder;
Object keepOpen;
- final ChannelDataInput input = storage.getStorageAs(ChannelDataInput.class);
+ final ChannelDataInput input = connector.getStorageAs(ChannelDataInput.class);
if (input != null) try {
- decoder = new ChannelDecoder(listeners, input);
+ decoder = new ChannelDecoder(input, geomlib, listeners);
keepOpen = input;
} catch (DataStoreException e) {
- final String path = storage.getStorageAs(String.class);
+ final String path = connector.getStorageAs(String.class);
if (path != null) try {
- decoder = createByReflection(listeners, path, false);
+ decoder = createByReflection(path, false, geomlib, listeners);
keepOpen = path;
} catch (IOException | DataStoreException s) {
e.addSuppressed(s);
}
throw e;
} else {
- keepOpen = storage.getStorage();
- decoder = createByReflection(listeners, keepOpen, true);
+ keepOpen = connector.getStorage();
+ decoder = createByReflection(keepOpen, true, geomlib, listeners);
}
- storage.closeAllExcept(keepOpen);
+ connector.closeAllExcept(keepOpen);
return decoder;
}
@@ -292,15 +295,17 @@ public class NetcdfStoreProvider extends
* not create our embedded NetCDF decoder. This method uses reflection for creating the wrapper, in order
* to keep the UCAR dependency optional.
*
- * @param listeners where to send the warnings.
* @param input the NetCDF file object of filename string from which to read data.
* @param isUCAR {@code true} if {@code input} is an instance of the UCAR {@link ucar.nc2.NetcdfFile} object,
* or {@code false} if it is the filename as a {@code String}.
+ * @param geomlib the library for geometric objects, or {@code null} for the default.
+ * @param listeners where to send the warnings.
* @return the {@link DecoderWrapper} instance for the given input, or {@code null} if the input type is not recognized.
* @throws IOException if an error occurred while opening the NetCDF file.
* @throws DataStoreException if a logical error (other than I/O) occurred.
*/
- private static Decoder createByReflection(final WarningListeners<DataStore> listeners, final Object input, final boolean isUCAR)
+ private static Decoder createByReflection(final Object input, final boolean isUCAR,
+ final GeometryLibrary geomlib, final WarningListeners<DataStore> listeners)
throws IOException, DataStoreException
{
ensureInitialized(true);
@@ -321,7 +326,7 @@ public class NetcdfStoreProvider extends
return null;
}
try {
- return constructor.newInstance(listeners, input);
+ return constructor.newInstance(input, geomlib, listeners);
} catch (InvocationTargetException e) {
final Throwable cause = e.getCause();
if (cause instanceof IOException) throw (IOException) cause;
@@ -360,9 +365,9 @@ public class NetcdfStoreProvider extends
*/
final Class<? extends Decoder> wrapper =
Class.forName("org.apache.sis.internal.netcdf.ucar.DecoderWrapper").asSubclass(Decoder.class);
- final Class<?>[] parameterTypes = new Class<?>[] {WarningListeners.class, netcdfFileClass};
+ final Class<?>[] parameterTypes = new Class<?>[] {netcdfFileClass, GeometryLibrary.class, WarningListeners.class};
createFromUCAR = wrapper.getConstructor(parameterTypes);
- parameterTypes[1] = String.class;
+ parameterTypes[0] = String.class;
createFromPath = wrapper.getConstructor(parameterTypes);
return; // Success
}
Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -27,6 +27,7 @@ import org.apache.sis.storage.DataStoreE
import org.apache.sis.util.logging.EmptyWarningListeners;
import org.apache.sis.internal.netcdf.ucar.DecoderWrapper;
import org.apache.sis.internal.system.Modules;
+import org.apache.sis.setup.GeometryLibrary;
import org.opengis.wrapper.netcdf.IOTestCase;
import ucar.nc2.dataset.NetcdfDataset;
import org.junit.AfterClass;
@@ -108,7 +109,7 @@ public abstract strictfp class TestCase
* @throws DataStoreException if a logical error occurred.
*/
protected Decoder createDecoder(final String name) throws IOException, DataStoreException {
- return new DecoderWrapper(LISTENERS, new NetcdfDataset(open(name)));
+ return new DecoderWrapper(new NetcdfDataset(open(name)), GeometryLibrary.JAVA2D, LISTENERS);
}
/**
Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -25,6 +25,7 @@ import org.apache.sis.internal.netcdf.De
import org.apache.sis.internal.netcdf.DecoderTest;
import org.apache.sis.internal.storage.io.ChannelDataInput;
import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.test.DependsOn;
import static org.junit.Assert.*;
@@ -75,7 +76,7 @@ public final strictfp class ChannelDecod
assertNotNull(name, in);
final ChannelDataInput input = new ChannelDataInput(name,
Channels.newChannel(in), ByteBuffer.allocate(4096), false);
- return new ChannelDecoder(LISTENERS, input);
+ return new ChannelDecoder(input, GeometryLibrary.JAVA2D, LISTENERS);
}
/**
Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -31,6 +31,7 @@ import org.apache.sis.internal.netcdf.De
import org.apache.sis.internal.netcdf.ucar.DecoderWrapper;
import org.apache.sis.internal.netcdf.TestCase;
import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestUtilities;
import org.junit.Test;
@@ -68,7 +69,7 @@ public final strictfp class ConformanceT
*/
@Override
protected Metadata wrap(final NetcdfFile file) throws IOException {
- final Decoder decoder = new DecoderWrapper(TestCase.LISTENERS, file);
+ final Decoder decoder = new DecoderWrapper(file, GeometryLibrary.JAVA2D, TestCase.LISTENERS);
final MetadataReader ncISO = new MetadataReader(decoder);
try {
return ncISO.read();
Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -26,6 +26,7 @@ import org.apache.sis.internal.netcdf.uc
import org.apache.sis.internal.netcdf.impl.ChannelDecoderTest;
import org.apache.sis.metadata.iso.DefaultMetadata;
import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.test.DependsOn;
import org.junit.Test;
@@ -82,7 +83,7 @@ public final strictfp class MetadataRead
@Test
public void testUCAR() throws IOException, DataStoreException {
final Metadata metadata;
- try (Decoder input = new DecoderWrapper(TestCase.LISTENERS, new NetcdfDataset(open(NCEP)))) {
+ try (Decoder input = new DecoderWrapper(new NetcdfDataset(open(NCEP)), GeometryLibrary.JAVA2D, TestCase.LISTENERS)) {
metadata = new MetadataReader(input).read();
}
compareToExpected(metadata);
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -26,7 +26,6 @@ import org.apache.sis.geometry.GeneralEn
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.DataSet;
import org.apache.sis.storage.DataStore;
-import org.apache.sis.util.logging.WarningListeners;
/**
@@ -41,11 +40,10 @@ public abstract class AbstractDataSet ex
/**
* Creates a new resource.
*
- * @param store the data store which contains this resource.
- * @param listeners the set of registered warning listeners for the data store.
+ * @param store the data store which contains this resource.
*/
- protected AbstractDataSet(final DataStore store, final WarningListeners<DataStore> listeners) {
- super(store, listeners);
+ protected AbstractDataSet(final DataStore store) {
+ super(store);
}
/**
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -18,7 +18,6 @@ package org.apache.sis.internal.storage;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.FeatureSet;
-import org.apache.sis.util.logging.WarningListeners;
/**
@@ -33,10 +32,9 @@ public abstract class AbstractFeatureSet
/**
* Creates a new resource.
*
- * @param store the data store which contains this resource.
- * @param listeners the set of registered warning listeners for the data store.
+ * @param store the data store which contains this resource.
*/
- protected AbstractFeatureSet(final DataStore store, final WarningListeners<DataStore> listeners) {
- super(store, listeners);
+ protected AbstractFeatureSet(final DataStore store) {
+ super(store);
}
}
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -16,6 +16,7 @@
*/
package org.apache.sis.internal.storage;
+import java.lang.reflect.Field;
import org.apache.sis.storage.Resource;
import org.apache.sis.storage.DataStore;
import org.apache.sis.util.logging.WarningListeners;
@@ -31,35 +32,44 @@ import org.apache.sis.util.logging.Warni
*/
public abstract class AbstractResource implements Resource {
/**
- * The data store which contains this resource.
+ * An accessor to the {@code DataStore.listeners} protected field.
+ * This hack will be removed if we move {@code AbstractResource} to the {@code org.apache.sis.storage} package.
*/
- protected final DataStore store;
+ private static final Field LISTENERS;
+ static {
+ try {
+ LISTENERS = DataStore.class.getDeclaredField("listeners");
+ } catch (NoSuchFieldException e) {
+ throw new AssertionError(e);
+ }
+ LISTENERS.setAccessible(true);
+ }
/**
- * The set of registered warning listeners for the data store.
- *
- * @todo Remove this field if we move {@code AbstractResource} to the {@code org.apache.sis.storage} package,
- * since we would be able to access {@code DataStore.listeners} directly.
+ * The data store which contains this resource.
*/
- private final WarningListeners<DataStore> listeners;
+ protected final DataStore store;
/**
* Creates a new resource.
*
- * @param store the data store which contains this resource.
- * @param listeners the set of registered warning listeners for the data store.
+ * @param store the data store which contains this resource.
*/
- protected AbstractResource(final DataStore store, final WarningListeners<DataStore> listeners) {
- this.store = store;
- this.listeners = listeners;
+ protected AbstractResource(final DataStore store) {
+ this.store = store;
}
/**
- * The set of registered warning listeners for the data store.
+ * Returns the set of registered warning listeners for the data store.
*
* @return the registered warning listeners for the data store.
*/
+ @SuppressWarnings("unchecked")
protected final WarningListeners<DataStore> listeners() {
- return listeners;
+ try {
+ return (WarningListeners<DataStore>) LISTENERS.get(store);
+ } catch (IllegalAccessException e) {
+ throw new AssertionError(e); // Should never happen since we have made the field accessible.
+ }
}
}
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderAggregate.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderAggregate.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderAggregate.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderAggregate.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -80,7 +80,7 @@ class FolderAggregate extends AbstractRe
private List<Resource> resources;
FolderAggregate(FolderStore store, FolderAggregate parent, Path path) {
- super(store, null);
+ super(store);
this.store = store;
this.parent = parent;
this.path = path;
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java?rev=1807768&r1=1807767&r2=1807768&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java [UTF-8] Fri Sep 8 14:31:31 2017
@@ -64,7 +64,7 @@ import org.apache.sis.internal.storage.R
*/
public interface Aggregate extends Resource {
/**
- * Returns the children resources of this aggregate. The returned collection contains at least all
+ * Returns the children resources of this aggregate. The returned collection contains
* the resources listed by their name in the following {@linkplain #getMetadata() metadata} elements.
* The returned collection may contain more resources if the metadata are incomplete,
* and the resources do not need to be in the same order: