Author: jsorel
Date: Wed Sep  6 13:36:22 2017
New Revision: 1807482

URL: http://svn.apache.org/viewvc?rev=1807482&view=rev
Log:
DataStore : review DataStore API, add Resource creation methods on Aggregate

Added:
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java
Removed:
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/FeatureAccess.java
    
sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/FeatureAccess.java
Modified:
    
sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatStore.java
    
sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
    
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.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/csv/Store.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/xml/Store.java
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataSet.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/Resource.java
    
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreMock.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/test/java/org/apache/sis/internal/storage/gpx/ReaderTest.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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -141,18 +141,6 @@ public class LandsatStore extends DataSt
     }
 
     /**
-     * Current implementation does not provide any resource yet.
-     * Future versions may return an aggregate of all raster data in the 
GeoTIFF files associated with this metadata.
-     *
-     * @return the starting point of all resources in this data store.
-     * @throws DataStoreException if an error occurred while reading the data.
-     */
-    @Override
-    public Resource getRootResource() throws DataStoreException {
-        return null;
-    }
-
-    /**
      * Closes this Landsat store and releases any underlying resources.
      *
      * @throws DataStoreException if an error occurred while closing the 
Landsat file.

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -153,18 +153,6 @@ public class GeoTiffStore extends DataSt
     }
 
     /**
-     * Current implementation does not provide any resource yet.
-     * A future version will return the raster data in a coverage resource.
-     *
-     * @return the starting point of all resources in this data store.
-     * @throws DataStoreException if an error occurred while reading the data.
-     */
-    @Override
-    public Resource getRootResource() throws DataStoreException {
-        return null;
-    }
-
-    /**
      * Returns the reader if it is not closed, or thrown an exception 
otherwise.
      */
     private Reader reader() throws DataStoreException {

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -138,17 +138,6 @@ public class NetcdfStore extends DataSto
     }
 
     /**
-     * This implementation does not provide any resource yet.
-     *
-     * @return currently {@code null} (will be implemented in future Apache 
SIS version).
-     * @throws DataStoreException if an error occurred while reading the data.
-     */
-    @Override
-    public Resource getRootResource() throws DataStoreException {
-        return null;
-    }
-
-    /**
      * Returns the version number of the Climate and Forecast (CF) conventions 
used in the NetCDF file.
      * The use of CF convention is mandated by the OGC 11-165r2 standard
      * (<cite>CF-netCDF3 Data Model Extension standard</cite>).

Added: 
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=1807482&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractDataSet.java
 Wed Sep  6 13:36:22 2017
@@ -0,0 +1,86 @@
+/*
+ * 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 org.apache.sis.geometry.GeneralEnvelope;
+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;
+import org.opengis.geometry.Envelope;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.metadata.identification.Identification;
+
+/**
+ * Base implementation of data sets contained in data stores.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+public abstract class AbstractDataSet extends AbstractResource implements 
DataSet {
+ /**
+     * 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.
+     */
+    protected AbstractDataSet(final DataStore store, final 
WarningListeners<DataStore> listeners) {
+        super(store, listeners);
+    }
+
+    /**
+     * Returns the spatio-temporal envelope of this resource.
+     * The default implementation computes the union of all {@link 
GeographicBoundingBox} in the resource metadata,
+     * assuming the {@linkplain 
org.apache.sis.referencing.CommonCRS#defaultGeographic() default geographic CRS}
+     * (usually WGS 84).
+     *
+     * @return the spatio-temporal resource extent.
+     * @throws DataStoreException if an error occurred while reading or 
computing the envelope.
+     */
+    @Override
+    public Envelope getEnvelope() throws DataStoreException {
+        final Metadata metadata = getMetadata();
+        GeneralEnvelope bounds = null;
+        if (metadata != null) {
+            for (final Identification identification : 
metadata.getIdentificationInfo()) {
+                if (identification != null) {                                  
             // Paranoiac check.
+                    for (final Extent extent : identification.getExtents()) {
+                        if (extent != null) {                                  
             // Paranoiac check.
+                            for (final GeographicExtent ge : 
extent.getGeographicElements()) {
+                                if (ge instanceof GeographicBoundingBox) {
+                                    final GeneralEnvelope env = new 
GeneralEnvelope((GeographicBoundingBox) ge);
+                                    if (bounds == null) {
+                                        bounds = env;
+                                    } else {
+                                        bounds.add(env);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return bounds;
+    }
+
+}

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -31,7 +31,7 @@ import org.apache.sis.util.logging.Warni
  *
  * @todo this class may be removed if we refactor {@link FeatureSet} as an 
abstract class.
  */
-public abstract class AbstractFeatureSet extends AbstractResource implements 
FeatureSet {
+public abstract class AbstractFeatureSet extends AbstractDataSet implements 
FeatureSet {
     /**
      * Creates a new resource.
      *

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -16,16 +16,8 @@
  */
 package org.apache.sis.internal.storage;
 
-import org.opengis.geometry.Envelope;
-import org.opengis.metadata.Metadata;
-import org.opengis.metadata.extent.Extent;
-import org.opengis.metadata.extent.GeographicExtent;
-import org.opengis.metadata.extent.GeographicBoundingBox;
-import org.opengis.metadata.identification.Identification;
 import org.apache.sis.storage.Resource;
 import org.apache.sis.storage.DataStore;
-import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.geometry.GeneralEnvelope;
 import org.apache.sis.util.logging.WarningListeners;
 
 
@@ -65,42 +57,6 @@ public abstract class AbstractResource i
     }
 
     /**
-     * Returns the spatio-temporal envelope of this resource.
-     * The default implementation computes the union of all {@link 
GeographicBoundingBox} in the resource metadata,
-     * assuming the {@linkplain 
org.apache.sis.referencing.CommonCRS#defaultGeographic() default geographic CRS}
-     * (usually WGS 84).
-     *
-     * @return the spatio-temporal resource extent.
-     * @throws DataStoreException if an error occurred while reading or 
computing the envelope.
-     */
-    @Override
-    public Envelope getEnvelope() throws DataStoreException {
-        final Metadata metadata = getMetadata();
-        GeneralEnvelope bounds = null;
-        if (metadata != null) {
-            for (final Identification identification : 
metadata.getIdentificationInfo()) {
-                if (identification != null) {                                  
             // Paranoiac check.
-                    for (final Extent extent : identification.getExtents()) {
-                        if (extent != null) {                                  
             // Paranoiac check.
-                            for (final GeographicExtent ge : 
extent.getGeographicElements()) {
-                                if (ge instanceof GeographicBoundingBox) {
-                                    final GeneralEnvelope env = new 
GeneralEnvelope((GeographicBoundingBox) ge);
-                                    if (bounds == null) {
-                                        bounds = env;
-                                    } else {
-                                        bounds.add(env);
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return bounds;
-    }
-
-    /**
      * The set of registered warning listeners for the data store.
      *
      * @return the registered warning listeners for the data store.

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -52,7 +52,6 @@ import org.apache.sis.internal.storage.R
 import org.apache.sis.geometry.GeneralEnvelope;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.metadata.sql.MetadataStoreException;
-import org.apache.sis.storage.Resource;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.DataStoreContentException;
@@ -71,10 +70,13 @@ import java.time.Instant;
 import java.time.DateTimeException;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
+import org.apache.sis.geometry.ImmutableEnvelope;
+import org.apache.sis.storage.FeatureSet;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
 import org.opengis.feature.PropertyType;
 import org.opengis.feature.AttributeType;
+import org.opengis.geometry.Envelope;
 
 
 /**
@@ -86,7 +88,7 @@ import org.opengis.feature.AttributeType
  * @since   0.7
  * @module
  */
-public final class Store extends DataStore {
+public final class Store extends DataStore 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.
@@ -632,6 +634,14 @@ public final class Store extends DataSto
      * {@inheritDoc }
      */
     @Override
+    public Envelope getEnvelope() throws DataStoreException {
+        return new ImmutableEnvelope(envelope);
+    }
+
+    /**
+     * {@inheritDoc }
+     */
+    @Override
     public ParameterValueGroup getOpenParameters() {
         if (sourceUri==null) return null;
         final Parameters parameters = 
Parameters.castOrWrap(StoreProvider.OPEN_DESCRIPTOR.createValue());
@@ -640,13 +650,21 @@ public final class Store extends DataSto
     }
 
     /**
-     * Returns the {@code FeatureSet} from which all features in this data 
store can be accessed.
+     * 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):
      *
-     * @return the starting point of all features in this data store.
+     * <blockquote>
+     * {@link #getMetadata()} /
+     * {@link org.apache.sis.metadata.iso.DefaultMetadata#getContentInfo() 
contentInfo} /
+     * {@link 
org.apache.sis.metadata.iso.content.DefaultFeatureCatalogueDescription#getFeatureTypeInfo()
 featureTypes} /
+     * {@link 
org.apache.sis.metadata.iso.content.DefaultFeatureTypeInfo#getFeatureTypeName() 
featureTypeName}
+     * </blockquote>
+     *
+     * @return type of features in the CSV file.
      */
     @Override
-    public Resource getRootResource() {
-        return new FeatureAccess(this, listeners);
+    public FeatureType getType() {
+        return featureType;
     }
 
     /**
@@ -659,7 +677,8 @@ public final class Store extends DataSto
      * @todo Needs to reset the position when doing another pass on the 
features.
      * @todo If sequential order, publish Feature as soon as identifier 
changed.
      */
-    final synchronized Stream<Feature> features(final boolean parallel) throws 
DataStoreException {
+    @Override
+    public final synchronized Stream<Feature> features(final boolean parallel) 
throws DataStoreException {
         /*
          * If the user asks for one feature instance per line, then we can 
return a FeatureIter instance directly.
          * Since each feature is fully constructed from a single line and each 
line are read atomically, we can

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -216,15 +216,6 @@ final class Store extends DataStore {
     }
 
     /**
-     * There is currently no resource associated to Well Known Text format 
since we parse only CRS.
-     * Future versions may return resources if we parse also geometries.
-     */
-    @Override
-    public Resource getRootResource() throws DataStoreException {
-        return null;
-    }
-
-    /**
      * 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/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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -232,15 +232,6 @@ final class Store extends DataStore {
     }
 
     /**
-     * Current implementation does not provide any resource since it is only 
about metadata.
-     * Futures versions may return resources if Apache SIS provides a wider 
GML support.
-     */
-    @Override
-    public Resource getRootResource() throws DataStoreException {
-        return null;
-    }
-
-    /**
      * 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/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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -17,6 +17,9 @@
 package org.apache.sis.storage;
 
 import java.util.Collection;
+import org.apache.sis.internal.storage.Resources;
+import org.opengis.metadata.Metadata;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 
 /**
@@ -82,4 +85,48 @@ public interface Aggregate extends Resou
      * @throws DataStoreException if an error occurred while fetching the 
components.
      */
     Collection<Resource> components() throws DataStoreException;
+
+    /**
+     * Add a new {@link Resource} in this {@link Aggregate}.
+     * The given {@link Resource} will be copied and the newly created one
+     * returned.
+     *
+     * <p>It is important to be warned that copying informations between stores
+     * may produce differences on many aspects, the range of changes depends
+     * both on the original {@link Resource} format and the target {@link 
Resource} format.
+     * If the differences are too great, then this {@link Aggregate} may throw
+     * an exception.
+     * </p>
+     *
+     * The possible changes may include the followings but not only :
+     * <ul>
+     *  <li>types and properties names</li>
+     *  <li>{@link CoordinateReferenceSystem}</li>
+     *  <li>{@link Metadata}</li>
+     * </ul>
+     *
+     *
+     * @param resource {@link Resource} to copy in this {@link Aggregate}
+     * @return newly created resource
+     * @throws DataStoreException if given resource can not be stored in this 
{@link Aggregate} or the copy operation failed.
+     * @throws ReadOnlyDataStoreException if this instance does not support 
writing operations
+     */
+    default Resource add(Resource resource) throws DataStoreException, 
ReadOnlyDataStoreException {
+        throw new ReadOnlyDataStoreException(null, 
Resources.Keys.StoreIsReadOnly);
+    }
+
+    /**
+     * Remove a {@link Resource} from this {@link Aggregate}.
+     *
+     * <p>This operation is destructive, the {@link Resource} and it's related
+     * datas will be removed.</p>
+     *
+     * @param resource child {@link Resource} to remove, should not be null
+     * @throws DataStoreException if the {@link Resource} could not be removed
+     * @throws ReadOnlyDataStoreException if this instance does not support 
writing operations
+     */
+    default void remove(Resource resource) throws DataStoreException, 
ReadOnlyDataStoreException {
+        throw new ReadOnlyDataStoreException(null, 
Resources.Keys.StoreIsReadOnly);
+    }
+
 }

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataSet.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataSet.java?rev=1807482&r1=1807481&r2=1807482&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataSet.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataSet.java
 [UTF-8] Wed Sep  6 13:36:22 2017
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.storage;
 
+import org.opengis.geometry.Envelope;
+
 
 /**
  * Collection of features that share a common set of attributes or properties.
@@ -45,4 +47,30 @@ package org.apache.sis.storage;
  * @module
  */
 public interface DataSet extends Resource {
+
+    /**
+     * Returns the spatio-temporal extent of this resource in its most natural 
coordinate reference system.
+     * The following relationship to {@linkplain #getMetadata()} should hold:
+     *
+     * <ul>
+     *   <li>The envelope should be contained in the union of all geographic, 
vertical or temporal extents
+     *       described by {@code metadata} /
+     *       {@link 
org.apache.sis.metadata.iso.DefaultMetadata#getIdentificationInfo() 
identificationInfo} /
+     *       {@link 
org.apache.sis.metadata.iso.identification.AbstractIdentification#getExtents() 
extent}.</li>
+     *   <li>The coordinate reference system should be one of the instances 
returned by
+     *       {@link 
org.apache.sis.metadata.iso.DefaultMetadata#getReferenceSystemInfo() 
referenceSystemInfo}.</li>
+     * </ul>
+     *
+     * The envelope should use the coordinate reference system (CRS)
+     * that most closely matches the geometry of the resource storage. It is 
often a
+     * {@linkplain org.apache.sis.referencing.crs.DefaultProjectedCRS 
projected CRS}, but other types like
+     * {@linkplain org.apache.sis.referencing.crs.DefaultEngineeringCRS 
engineering CRS} are also allowed.
+     * If this resource uses many different CRS with none of them covering all 
data, then the envelope should use a
+     * global system (typically a {@linkplain 
org.apache.sis.referencing.crs.DefaultGeocentricCRS geographic CRS}).
+     *
+     * @return the spatio-temporal resource extent. Should not be {@code null}.
+     * @throws DataStoreException if an error occurred while reading or 
computing the envelope.
+     */
+    Envelope getEnvelope() throws DataStoreException;
+
 }

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -47,7 +47,7 @@ import org.apache.sis.internal.util.Cita
  * @since 0.3
  * @module
  */
-public abstract class DataStore implements Localized, AutoCloseable {
+public abstract class DataStore implements Resource, Localized, AutoCloseable {
     /**
      * The factory that created this {@code DataStore} instance, or {@code 
null} if unspecified.
      * This information can be useful for fetching information common to all 
{@code DataStore}
@@ -220,22 +220,10 @@ public abstract class DataStore implemen
      *
      * @see Resource#getMetadata()
      */
+    @Override
     public abstract Metadata getMetadata() throws DataStoreException;
 
     /**
-     * Returns the starting point from which all resources in this data store 
can be accessed.
-     * A resource can be for example a air temperature map or the set of all 
bridges in a city.
-     * If this data store contains only one resource, then that resource is 
returned directly.
-     * Otherwise if this data store contains more than one resource, then this 
method returns
-     * an {@link Aggregate} from which other resources can be accessed.
-     *
-     * @return the starting point of all resources in this data store,
-     *         or {@code null} if this data store does not contain any 
resources.
-     * @throws DataStoreException if an error occurred while reading the data.
-     */
-    public abstract Resource getRootResource() throws DataStoreException;
-
-    /**
      * Searches for a resource identified by the given identifier.
      * The given identifier should match the following metadata element of a 
resource:
      *
@@ -260,7 +248,7 @@ public abstract class DataStore implemen
      */
     public Resource findResource(final String identifier) throws 
DataStoreException {
         ArgumentChecks.ensureNonEmpty("identifier", identifier);
-        final Resource resource = findResource(identifier, getRootResource(), 
new IdentityHashMap<>());
+        final Resource resource = findResource(identifier, this, new 
IdentityHashMap<>());
         if (resource != null) {
             return resource;
         }

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java?rev=1807482&r1=1807481&r2=1807482&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java
 [UTF-8] Wed Sep  6 13:36:22 2017
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.storage;
 
-import org.opengis.geometry.Envelope;
 import org.opengis.metadata.Metadata;
 
 
@@ -108,28 +107,4 @@ public interface Resource {
      */
     Metadata getMetadata() throws DataStoreException;
 
-    /**
-     * Returns the spatio-temporal extent of this resource in its most natural 
coordinate reference system.
-     * The following relationship to {@linkplain #getMetadata()} should hold:
-     *
-     * <ul>
-     *   <li>The envelope should be contained in the union of all geographic, 
vertical or temporal extents
-     *       described by {@code metadata} /
-     *       {@link 
org.apache.sis.metadata.iso.DefaultMetadata#getIdentificationInfo() 
identificationInfo} /
-     *       {@link 
org.apache.sis.metadata.iso.identification.AbstractIdentification#getExtents() 
extent}.</li>
-     *   <li>The coordinate reference system should be one of the instances 
returned by
-     *       {@link 
org.apache.sis.metadata.iso.DefaultMetadata#getReferenceSystemInfo() 
referenceSystemInfo}.</li>
-     * </ul>
-     *
-     * The envelope should use the coordinate reference system (CRS)
-     * that most closely matches the geometry of the resource storage. It is 
often a
-     * {@linkplain org.apache.sis.referencing.crs.DefaultProjectedCRS 
projected CRS}, but other types like
-     * {@linkplain org.apache.sis.referencing.crs.DefaultEngineeringCRS 
engineering CRS} are also allowed.
-     * If this resource uses many different CRS with none of them covering all 
data, then the envelope should use a
-     * global system (typically a {@linkplain 
org.apache.sis.referencing.crs.DefaultGeocentricCRS geographic CRS}).
-     *
-     * @return the spatio-temporal resource extent. Should not be {@code null}.
-     * @throws DataStoreException if an error occurred while reading or 
computing the envelope.
-     */
-    Envelope getEnvelope() throws DataStoreException;
 }

Modified: 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreMock.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreMock.java?rev=1807482&r1=1807481&r2=1807482&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreMock.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreMock.java
 [UTF-8] Wed Sep  6 13:36:22 2017
@@ -60,11 +60,6 @@ final strictfp class DataStoreMock exten
     }
 
     @Override
-    public Resource getRootResource() throws DataStoreException {
-        return null;
-    }
-
-    @Override
     public void close() {
     }
 }

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=1807482&r1=1807481&r2=1807482&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] Wed Sep  6 13:36:22 2017
@@ -21,7 +21,6 @@ import org.opengis.util.NameFactory;
 import org.opengis.util.FactoryException;
 import org.opengis.metadata.Metadata;
 import org.opengis.metadata.distribution.Format;
-import org.apache.sis.storage.Resource;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.DataStoreContentException;
@@ -43,9 +42,16 @@ import org.apache.sis.metadata.iso.distr
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 import java.io.UncheckedIOException;
+import org.apache.sis.geometry.GeneralEnvelope;
 import org.apache.sis.parameter.Parameters;
+import org.apache.sis.storage.FeatureSet;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
+import org.opengis.geometry.Envelope;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.metadata.identification.Identification;
 import org.opengis.parameter.ParameterValueGroup;
 
 
@@ -58,7 +64,7 @@ import org.opengis.parameter.ParameterVa
  * @since   0.8
  * @module
  */
-public final class Store extends StaxDataStore {
+public final class Store extends StaxDataStore implements FeatureSet {
     /**
      * Version of the GPX file, or {@code null} if unknown.
      */
@@ -170,6 +176,42 @@ public final class Store extends StaxDat
     }
 
     /**
+     * Returns the spatio-temporal envelope of this resource.
+     * The default implementation computes the union of all {@link 
GeographicBoundingBox} in the resource metadata,
+     * assuming the {@linkplain 
org.apache.sis.referencing.CommonCRS#defaultGeographic() default geographic CRS}
+     * (usually WGS 84).
+     *
+     * @return the spatio-temporal resource extent.
+     * @throws DataStoreException if an error occurred while reading or 
computing the envelope.
+     */
+    @Override
+    public Envelope getEnvelope() throws DataStoreException {
+        final Metadata metadata = getMetadata();
+        GeneralEnvelope bounds = null;
+        if (metadata != null) {
+            for (final Identification identification : 
metadata.getIdentificationInfo()) {
+                if (identification != null) {                                  
             // Paranoiac check.
+                    for (final Extent extent : identification.getExtents()) {
+                        if (extent != null) {                                  
             // Paranoiac check.
+                            for (final GeographicExtent ge : 
extent.getGeographicElements()) {
+                                if (ge instanceof GeographicBoundingBox) {
+                                    final GeneralEnvelope env = new 
GeneralEnvelope((GeographicBoundingBox) ge);
+                                    if (bounds == null) {
+                                        bounds = env;
+                                    } else {
+                                        bounds.add(env);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return bounds;
+    }
+
+    /**
      * {@inheritDoc }
      */
     @Override
@@ -181,13 +223,13 @@ public final class Store extends StaxDat
     }
 
     /**
-     * Returns the {@code FeatureSet} from which all features in this data 
store can be accessed.
+     * Returns the base type of all GPX types.
      *
-     * @return the starting point of all features in this data store.
+     * @return base type of all GPX types.
      */
     @Override
-    public Resource getRootResource() {
-        return new FeatureAccess(this, listeners);
+    public FeatureType getType() {
+        return types.parent;
     }
 
     /**
@@ -212,7 +254,7 @@ public final class Store extends StaxDat
      * @return a stream over all features in the XML file.
      * @throws DataStoreException if an error occurred while creating the 
feature stream.
      */
-    final synchronized Stream<Feature> features() throws DataStoreException {
+    public final synchronized Stream<Feature> features(boolean parallel) 
throws DataStoreException {
         Reader r = reader;
         reader = null;
         if (r == null) try {

Modified: 
sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/storage/gpx/ReaderTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/storage/gpx/ReaderTest.java?rev=1807482&r1=1807481&r2=1807482&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/storage/gpx/ReaderTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/storage/gpx/ReaderTest.java
 [UTF-8] Wed Sep  6 13:36:22 2017
@@ -224,7 +224,7 @@ public final strictfp class ReaderTest e
         try (Store reader = create("1.0/waypoint.xml")) {
             verifyAlmostEmptyMetadata((Metadata) reader.getMetadata());
             assertEquals("version", StoreProvider.V1_0, reader.getVersion());
-            try (Stream<Feature> features = reader.features()) {
+            try (Stream<Feature> features = reader.features(false)) {
                 final Iterator<Feature> it = features.iterator();
                 verifyPoint(it.next(), 0, false);
                 verifyPoint(it.next(), 1, false);
@@ -245,7 +245,7 @@ public final strictfp class ReaderTest e
         try (Store reader = create("1.1/waypoint.xml")) {
             verifyAlmostEmptyMetadata((Metadata) reader.getMetadata());
             assertEquals("version", StoreProvider.V1_1, reader.getVersion());
-            try (Stream<Feature> features = reader.features()) {
+            try (Stream<Feature> features = reader.features(false)) {
                 final Iterator<Feature> it = features.iterator();
                 verifyPoint(it.next(), 0, true);
                 verifyPoint(it.next(), 1, true);
@@ -266,7 +266,7 @@ public final strictfp class ReaderTest e
         try (Store reader = create("1.0/route.xml")) {
             verifyAlmostEmptyMetadata((Metadata) reader.getMetadata());
             assertEquals("version", StoreProvider.V1_0, reader.getVersion());
-            try (Stream<Feature> features = reader.features()) {
+            try (Stream<Feature> features = reader.features(false)) {
                 final Iterator<Feature> it = features.iterator();
                 verifyRoute(it.next(), false, 1);
                 verifyEmpty(it.next(), "rtept");
@@ -295,7 +295,7 @@ public final strictfp class ReaderTest e
      * This verification is shared by {@link #testRoute110()} and {@link 
#testSequentialReads()}.
      */
     static void verifyRoute110(final Store reader) throws DataStoreException {
-        try (Stream<Feature> features = reader.features()) {
+        try (Stream<Feature> features = reader.features(false)) {
             final Iterator<Feature> it = features.iterator();
             verifyRoute(it.next(), true, 3);
             verifyEmpty(it.next(), "rtept");
@@ -373,7 +373,7 @@ public final strictfp class ReaderTest e
         try (Store reader = create("1.0/track.xml")) {
             verifyAlmostEmptyMetadata((Metadata) reader.getMetadata());
             assertEquals("version", StoreProvider.V1_0, reader.getVersion());
-            try (Stream<Feature> features = reader.features()) {
+            try (Stream<Feature> features = reader.features(false)) {
                 final Iterator<Feature> it = features.iterator();
                 verifyTrack(it.next(), false, 1);
                 verifyEmpty(it.next(), "trkseg");
@@ -393,7 +393,7 @@ public final strictfp class ReaderTest e
         try (Store reader = create("1.1/track.xml")) {
             verifyAlmostEmptyMetadata((Metadata) reader.getMetadata());
             assertEquals("version", StoreProvider.V1_1, reader.getVersion());
-            try (Stream<Feature> features = reader.features()) {
+            try (Stream<Feature> features = reader.features(false)) {
                 final Iterator<Feature> it = features.iterator();
                 verifyTrack(it.next(), true, 3);
                 verifyEmpty(it.next(), "trkseg");
@@ -610,13 +610,13 @@ public final strictfp class ReaderTest e
     @DependsOnMethod("testSequentialReads")
     public void testConcurrentReads() throws DataStoreException {
         try (Store reader = createFromURL()) {
-            final Stream<Feature>   f1 = reader.features();
+            final Stream<Feature>   f1 = reader.features(false);
             final Iterator<Feature> i1 = f1.iterator();
             verifyRoute(i1.next(), true, 3);
-            final Stream<Feature>   f2 = reader.features();
+            final Stream<Feature>   f2 = reader.features(false);
             final Iterator<Feature> i2 = f2.iterator();
             verifyEmpty(i1.next(), "rtept");
-            final Stream<Feature>   f3 = reader.features();
+            final Stream<Feature>   f3 = reader.features(false);
             final Iterator<Feature> i3 = f3.iterator();
             verifyRoute(i2.next(), true, 3);
             verifyRoute(i3.next(), true, 3);


Reply via email to