sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1777193 - in /sis/branches/JDK8/storage: sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/ sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ sis-storage/src/main/java/org/apache/sis/internal/storage/ sis-...
Date Tue, 03 Jan 2017 17:59:18 GMT
Author: desruisseaux
Date: Tue Jan  3 17:59:18 2017
New Revision: 1777193

URL: http://svn.apache.org/viewvc?rev=1777193&view=rev
Log:
First draft of a helper method for DataStore that work like a FeatureCatalog.

Added:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java
  (with props)
Modified:
    sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Reader.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Store.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Types.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Writer.java

Modified: sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java?rev=1777193&r1=1777192&r2=1777193&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -446,7 +446,7 @@ final class LandsatReader {
             case "ORIGIN": {
                 final Matcher m = CREDIT.matcher(value);
                 if (m.find()) {
-                    metadata.newParty(MetadataBuilder.ORGANISATION);
+                    metadata.newParty(MetadataBuilder.PartyType.ORGANISATION);
                     metadata.addAuthor(value.substring(m.end()));
                 }
                 metadata.addCredits(value);
@@ -889,7 +889,7 @@ final class LandsatReader {
      * @throws FactoryException if an error occurred while creating the Coordinate Reference
System.
      */
     final Metadata getMetadata() throws FactoryException {
-        metadata.add(Locale.ENGLISH);
+        metadata.add(Locale.ENGLISH, MetadataBuilder.Scope.METADATA);
         metadata.add(ScopeCode.COVERAGE);
         try {
             flushSceneTime();

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=1777193&r1=1777192&r2=1777193&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] Tue Jan  3 17:59:18 2017
@@ -110,7 +110,7 @@ public class GeoTiffStore extends DataSt
             } catch (MetadataStoreException e) {
                 warning(null, e);
             }
-            builder.add(encoding);
+            builder.add(encoding, MetadataBuilder.Scope.METADATA);
             builder.add(ScopeCode.COVERAGE);
             final Locale locale = getLocale();
             int n = 0;

Added: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java?rev=1777193&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java
(added)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -0,0 +1,84 @@
+/*
+ * 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.opengis.util.GenericName;
+import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.FeatureNaming;
+import org.apache.sis.storage.IllegalNameException;
+import org.apache.sis.metadata.iso.DefaultMetadata;
+
+// Branch-dependent imports
+import org.opengis.feature.FeatureType;
+
+
+/**
+ * Helper methods for the feature metadata created by {@code DataStore} implementations.
+ * This is a convenience class for chaining {@link #add(FeatureType, Integer)} method calls
+ * with {@link FeatureNaming#add(DataStore, GenericName, Object)}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ *
+ * @see org.apache.sis.metadata.iso.content.DefaultFeatureCatalogueDescription
+ */
+public class FeatureCatalogBuilder extends MetadataBuilder {
+    /**
+     * The data store for which the metadata will be created, or {@code null} if unknown.
+     * This is used for producing error message if an exception is thrown.
+     */
+    private final DataStore store;
+
+    /**
+     * The feature types created by the {@code FeatureCatalogBuilder}.
+     * {@code DataStore} implementations can keep the reference to this {@code FeatureNaming}
+     * after the {@link #build(boolean)} method has been invoked.
+     */
+    public final FeatureNaming<FeatureType> features;
+
+    /**
+     * Creates a new builder for the given data store.
+     *
+     * @param  store  the data store for which the metadata will be created, or {@code null}
if unknown.
+     */
+    public FeatureCatalogBuilder(final DataStore store) {
+        this.store = store;
+        features = new FeatureNaming<>();
+    }
+
+    /**
+     * Adds descriptions for the given feature in both the {@link DefaultMetadata} and {@link
FeatureNaming} instances.
+     * Invoking this method is equivalent to executing the following code (omitting {@code
null} checks for brevity):
+     *
+     * {@preformat java
+     *     features.add(store, add(type, null), type);
+     * }
+     *
+     * @param  type  the feature type to add, or {@code null}.
+     * @throws IllegalNameException if a feature of the same name has already been added.
+     *
+     * @see #add(FeatureType, Integer)
+     */
+    public final void define(final FeatureType type) throws IllegalNameException {
+        final GenericName name = add(type, null);
+        if (name != null) {
+            features.add(store, name, type);
+        }
+    }
+}

Propchange: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureCatalogBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1777193&r1=1777192&r2=1777193&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.nio.charset.Charset;
+import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Role;
@@ -76,6 +77,7 @@ import org.apache.sis.metadata.iso.linea
 import org.apache.sis.metadata.iso.lineage.DefaultProcessing;
 import org.apache.sis.metadata.sql.MetadataStoreException;
 import org.apache.sis.metadata.sql.MetadataSource;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.iso.Types;
 
@@ -101,24 +103,6 @@ import org.opengis.feature.FeatureType;
  */
 public class MetadataBuilder {
     /**
-     * Instructs {@link #newParty(byte)} that the next party to create should be an instance
of
-     * {@link DefaultIndividual}.
-     *
-     * @see #partyType
-     * @see #newParty(byte)
-     */
-    public static final byte INDIVIDUAL = 1;
-
-    /**
-     * Instructs {@link #newParty(byte)} that the next party to create should be an instance
of
-     * {@link DefaultOrganisation}.
-     *
-     * @see #partyType
-     * @see #newParty(byte)
-     */
-    public static final byte ORGANISATION = 2;
-
-    /**
      * The metadata created by this reader, or {@code null} if none.
      */
     private DefaultMetadata metadata;
@@ -215,14 +199,10 @@ public class MetadataBuilder {
 
     /**
      * Whether the next party to create should be an instance of {@link DefaultIndividual}
or {@link DefaultOrganisation}.
-     * Value can be {@link #INDIVIDUAL}, {@link #ORGANISATION} or 0 if unknown, in which
case an {@link AbstractParty}
-     * will be created.
      *
-     * @see #INDIVIDUAL
-     * @see #ORGANISATION
-     * @see #newParty(byte)
+     * @see #newParty(PartyType)
      */
-    private byte partyType;
+    private PartyType partyType = PartyType.UNKNOWN;
 
     /**
      * {@code true} if the next {@code CoverageDescription} to create will be a description
of measurements
@@ -264,6 +244,28 @@ public class MetadataBuilder {
     }
 
     /**
+     * The type of party to create (individual, organization or unknown).
+     */
+    public static enum PartyType {
+        /**
+         * Instructs {@link #newParty(PartyType)} that the next party to create should be
an instance of
+         * {@link DefaultIndividual}.
+         */
+        INDIVIDUAL,
+
+        /**
+         * Instructs {@link #newParty(PartyType)} that the next party to create should be
an instance of
+         * {@link DefaultOrganisation}.
+         */
+        ORGANISATION,
+
+        /**
+         * Instructs {@link #newParty(PartyType)} that the next party to create if of unknown
type.
+         */
+        UNKNOWN
+    }
+
+    /**
      * Commits all pending information under the "responsible party" node (author, address,
<i>etc</i>).
      * If there is no pending party information, then invoking this method has no effect
      * except setting the {@code type} flag.
@@ -272,9 +274,10 @@ public class MetadataBuilder {
      * <p>This method does not need to be invoked unless a new "responsible party"
node,
      * separated from the previous one, is desired.</p>
      *
-     * @param  type  {@link #INDIVIDUAL}, {@link #ORGANISATION} or 0 if unknown.
+     * @param  type  whether the party to create is an individual or an organization.
      */
-    public final void newParty(final byte type) {
+    public final void newParty(final PartyType type) {
+        ArgumentChecks.ensureNonNull("type", type);
         if (party != null) {
             addIfNotPresent(responsibility().getParties(), party);
             party = null;
@@ -294,7 +297,7 @@ public class MetadataBuilder {
         /*
          * Construction shall be ordered from children to parents.
          */
-        newParty((byte) 0);
+        newParty(PartyType.UNKNOWN);
         if (responsibility != null) {
             addIfNotPresent(citation().getCitedResponsibleParties(), responsibility);
             responsibility = null;
@@ -484,9 +487,10 @@ public class MetadataBuilder {
     private AbstractParty party() {
         if (party == null) {
             switch (partyType) {
+                case UNKNOWN:      party = new AbstractParty();       break;
                 case INDIVIDUAL:   party = new DefaultIndividual();   break;
                 case ORGANISATION: party = new DefaultOrganisation(); break;
-                default:           party = new AbstractParty();       break;
+                default:           throw new AssertionError(partyType);
             }
         }
         return party;
@@ -653,32 +657,64 @@ public class MetadataBuilder {
     }
 
     /**
-     * Adds a language used for documenting metadata.
-     * Storage location is:
+     * Specify if an information apply to data, to metadata or to both.
+     */
+    public static enum Scope {
+        /**
+         * Information applies only to data.
+         */
+        DATA,
+
+        /**
+         * Information applies only to metadata.
+         */
+        METADATA,
+
+        /**
+         * Information applies to both data and metadata.
+         */
+        ALL
+    }
+
+    /**
+     * Adds a language used for documenting data and/or metadata.
+     * Storage locations are:
      *
-     * <pre>metadata/language</pre>
+     * <table class="compact" summary="Storage locations.">
+     * <tr><td>Metadata</td> <td>{@code metadata/language}</td></tr>
+     * <tr><td>Data</td>     <td>{@code metadata/identificationInfo/language}</td></tr>
+     * </table>
      *
-     * @param  language  a language used for documenting metadata.
+     * @param  language  a language used for documenting data and/or metadata.
+     * @param  scope     whether the language applies to data, to metadata or to both.
      */
-    public final void add(final Locale language) {
+    public final void add(final Locale language, final Scope scope) {
+        ArgumentChecks.ensureNonNull("scope", scope);
         if (language != null) {
             // No need to use 'addIfNotPresent(…)' because Locale collection is a Set by
default.
-            metadata().getLanguages().add(language);
+            if (scope != Scope.DATA)           metadata().getLanguages().add(language);
+            if (scope != Scope.METADATA) identification().getLanguages().add(language);
         }
     }
 
     /**
-     * Adds the given character encoding to the metadata.
-     * Storage location is:
+     * Adds a character set used for encoding the data and/or metadata.
+     * Storage locations are:
      *
-     * <pre>metadata/characterSet</pre>
+     * <table class="compact" summary="Storage locations.">
+     * <tr><td>Metadata</td> <td>{@code metadata/characterSet}</td></tr>
+     * <tr><td>Data</td>     <td>{@code metadata/identificationInfo/characterSet}</td></tr>
+     * </table>
      *
-     * @param  encoding  the character encoding to add.
+     * @param  encoding  the character set used for encoding data and/or metadata.
+     * @param  scope     whether the encoding applies to data, to metadata or to both.
      */
-    public final void add(final Charset encoding) {
+    public final void add(final Charset encoding, final Scope scope) {
+        ArgumentChecks.ensureNonNull("scope", scope);
         if (encoding != null) {
             // No need to use 'addIfNotPresent(…)' because Charset collection is a Set
by default.
-            metadata().getCharacterSets().add(encoding);
+            if (scope != Scope.DATA)           metadata().getCharacterSets().add(encoding);
+            if (scope != Scope.METADATA) identification().getCharacterSets().add(encoding);
         }
     }
 
@@ -703,17 +739,29 @@ public class MetadataBuilder {
      *
      * <pre>metadata/contentInfo/featureTypes/featureTypeName</pre>
      *
+     * This method returns the feature name for more convenient chaining with
+     * {@link org.apache.sis.storage.FeatureNaming#add FeatureNaming.add(…)}.
+     * Note that the {@link FeatureCatalogBuilder} subclasses can also be used for that chaining.
+     *
      * @param  type         the feature type to add, or {@code null}.
-     * @param  occurrences  number of instances of the given features, or {@code null} if
unknown.
+     * @param  occurrences  number of instances of the given feature type, or {@code null}
if unknown.
+     * @return the name of the added feature, or {@code null} if none.
+     *
+     * @see FeatureCatalogBuilder#define(FeatureType)
      */
-    public final void add(final FeatureType type, final Integer occurrences) {
+    public final GenericName add(final FeatureType type, final Integer occurrences) {
         if (type != null) {
-            final DefaultFeatureTypeInfo info = new DefaultFeatureTypeInfo(type.getName());
-            if (occurrences != null) {
-                info.setFeatureInstanceCount(shared(occurrences));
+            final GenericName name = type.getName();
+            if (name != null) {
+                final DefaultFeatureTypeInfo info = new DefaultFeatureTypeInfo(name);
+                if (occurrences != null) {
+                    info.setFeatureInstanceCount(shared(occurrences));
+                }
+                addIfNotPresent(featureDescription().getFeatureTypeInfo(), info);
+                return name;
             }
-            addIfNotPresent(featureDescription().getFeatureTypeInfo(), info);
         }
+        return null;
     }
 
     /**
@@ -1564,7 +1612,7 @@ parse:      for (int i = 0; i < length;)
      * If {@code freeze} is {@code true}, then the returned metadata instance can not be
modified.
      *
      * @param  freeze  {@code true} if this method should {@linkplain DefaultMetadata#freeze()
freeze}
-     *         the metadata instance before to return it.
+     *                 the metadata instance before to return it.
      * @return the metadata, or {@code null} if none.
      */
     public final DefaultMetadata build(final boolean freeze) {

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=1777193&r1=1777192&r2=1777193&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] Tue Jan  3 17:59:18 2017
@@ -493,7 +493,7 @@ public final class Store extends Feature
             } catch (MetadataStoreException e) {
                 listeners.warning(null, e);
             }
-            builder.add(encoding);
+            builder.add(encoding, MetadataBuilder.Scope.ALL);
             builder.add(ScopeCode.DATASET);
             try {
                 builder.addExtent(envelope);

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Reader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Reader.java?rev=1777193&r1=1777192&r2=1777193&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Reader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Reader.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -62,13 +62,6 @@ import org.opengis.feature.Feature;
  */
 final class Reader extends StaxStreamReader {
     /**
-     * The {@link org.opengis.feature.FeatureType} for routes, tracks, way points, <i>etc</i>.
-     * Currently always {@link Types#DEFAULT}, but we use a field for keeping {@code Reader}
-     * ready to handle profiles or extensions.
-     */
-    private final Types types;
-
-    /**
      * The namespace, which should be either {@link Tags#NAMESPACE_V10} or {@link Tags#NAMESPACE_V11}.
      * We store this information for identifying the closing {@code <gpx>} tag.
      */
@@ -108,7 +101,6 @@ final class Reader extends StaxStreamRea
      */
     public Reader(final Store owner) throws DataStoreException, XMLStreamException, IOException
{
         super(owner);
-        types = Types.DEFAULT;
     }
 
     /**
@@ -410,7 +402,7 @@ parse:  while (reader.hasNext()) {
             throw new DataStoreContentException(errors().getString(Errors.Keys.MandatoryAttribute_2,
                     (lat == null) ? Attributes.LATITUDE : Attributes.LONGITUDE, tagName));
         }
-        final Feature feature = types.wayPoint.newInstance();
+        final Feature feature = ((Store) owner).types.wayPoint.newInstance();
         feature.setPropertyValue("@identifier", index);
         feature.setPropertyValue("@geometry", new Point(parseDouble(lon), parseDouble(lat)));
         List<Link> links = null;
@@ -475,7 +467,7 @@ parse:  while (reader.hasNext()) {
      */
     private Feature parseRoute(final int index) throws Exception {
         assert reader.isStartElement() && Tags.ROUTES.equals(reader.getLocalName());
-        final Feature feature = types.route.newInstance();
+        final Feature feature = ((Store) owner).types.route.newInstance();
         feature.setPropertyValue("@identifier", index);
         List<Feature> wayPoints = null;
         List<Link> links = null;
@@ -531,7 +523,7 @@ parse:  while (reader.hasNext()) {
      */
     private Feature parseTrackSegment(final int index) throws Exception {
         assert reader.isStartElement() && Tags.TRACK_SEGMENTS.equals(reader.getLocalName());
-        final Feature feature = types.trackSegment.newInstance();
+        final Feature feature = ((Store) owner).types.trackSegment.newInstance();
         feature.setPropertyValue("@identifier", index);
         List<Feature> wayPoints = null;
         while (true) {
@@ -574,7 +566,7 @@ parse:  while (reader.hasNext()) {
      */
     private Feature parseTrack(final int index) throws Exception {
         assert reader.isStartElement() && Tags.TRACKS.equals(reader.getLocalName());
-        final Feature feature = types.track.newInstance();
+        final Feature feature = ((Store) owner).types.track.newInstance();
         feature.setPropertyValue("@identifier", index);
         List<Feature> segments = null;
         List<Link> links = null;

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Store.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Store.java?rev=1777193&r1=1777192&r2=1777193&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Store.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Store.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -81,6 +81,13 @@ public final class Store extends StaxDat
     private Reader reader;
 
     /**
+     * The {@link org.opengis.feature.FeatureType} for routes, tracks, way points, <i>etc</i>.
+     * Currently always {@link Types#DEFAULT}, but we use a field for keeping {@code Reader}
+     * and {@code Writer} ready to handle profiles or extensions.
+     */
+    final Types types;
+
+    /**
      * Creates a new GPX store from the given file, URL or stream object.
      * This constructor invokes {@link StorageConnector#closeAllExcept(Object)},
      * keeping open only the needed resource.
@@ -91,6 +98,7 @@ public final class Store extends StaxDat
      */
     public Store(final StoreProvider provider, final StorageConnector connector) throws DataStoreException
{
         super(provider, connector);
+        types = Types.DEFAULT;
     }
 
     /**
@@ -157,8 +165,8 @@ public final class Store extends StaxDat
      * @throws IllegalNameException if the given name was not found or is ambiguous.
      */
     @Override
-    public FeatureType getFeatureType(String name) throws IllegalNameException {
-        throw new UnsupportedOperationException();  // TODO
+    public FeatureType getFeatureType(final String name) throws IllegalNameException {
+        return types.names.get(this, name);
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Types.java?rev=1777193&r1=1777192&r2=1777193&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Types.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Types.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -19,24 +19,28 @@ package org.apache.sis.internal.gpx;
 import java.util.Collections;
 import java.util.Locale;
 import java.util.Map;
-import java.time.temporal.Temporal;
 import com.esri.core.geometry.Point;
 import org.opengis.util.LocalName;
 import org.opengis.util.NameFactory;
 import org.opengis.util.FactoryException;
+import org.opengis.metadata.Metadata;
 import org.opengis.metadata.citation.OnlineResource;
 import org.apache.sis.storage.gps.Fix;
+import org.apache.sis.storage.FeatureNaming;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.feature.AbstractIdentifiedType;
 import org.apache.sis.feature.FeatureOperations;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.feature.builder.AttributeRole;
 import org.apache.sis.internal.feature.AttributeConvention;
+import org.apache.sis.internal.storage.FeatureCatalogBuilder;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.util.iso.DefaultNameFactory;
 import org.apache.sis.util.Static;
 
 // Branch-dependent imports
+import java.time.temporal.Temporal;
+import org.apache.sis.storage.IllegalNameException;
 import org.opengis.feature.FeatureType;
 
 
@@ -52,19 +56,19 @@ import org.opengis.feature.FeatureType;
  */
 final class Types extends Static {
     /**
-     * Waypoint GPX feature type.
+     * Way point GPX feature type.
      */
     final FeatureType wayPoint;
 
     /**
-     * Track GPX feature type.
+     * Route GPX feature type.
      */
-    final FeatureType track;
+    final FeatureType route;
 
     /**
-     * Route GPX feature type.
+     * Track GPX feature type.
      */
-    final FeatureType route;
+    final FeatureType track;
 
     /**
      * Track segment GPX feature type.
@@ -72,6 +76,17 @@ final class Types extends Static {
     final FeatureType trackSegment;
 
     /**
+     * The metadata to use as a template, including the list of feature types.
+     */
+    private final Metadata metadata;
+
+    /**
+     * Binding from names to feature type instances.
+     * Shall not be modified after construction.
+     */
+    final FeatureNaming<FeatureType> names;
+
+    /**
      * A system-wide instance for {@code FeatureType} instances created using the {@link
DefaultNameFactory}.
      * This is normally the only instance used in an application.
      */
@@ -79,7 +94,7 @@ final class Types extends Static {
     static {
         try {
             DEFAULT = new Types(DefaultFactories.forBuildin(NameFactory.class, DefaultNameFactory.class),
null);
-        } catch (FactoryException e) {
+        } catch (FactoryException | IllegalNameException e) {
             throw new AssertionError(e);        // Should never happen with DefaultNameFactory
implementation.
         }
     }
@@ -91,7 +106,7 @@ final class Types extends Static {
      * @param  locale    the locale to use for formatting error messages, or {@code null}
for the default locale.
      * @throws FactoryException if an error occurred while creating an "envelope bounds"
operation.
      */
-    Types(final NameFactory factory, final Locale locale) throws FactoryException {
+    Types(final NameFactory factory, final Locale locale) throws FactoryException, IllegalNameException
{
         final LocalName     geomName = AttributeConvention.GEOMETRY_PROPERTY;
         final Map<String,?> geomInfo = Collections.singletonMap(AbstractIdentifiedType.NAME_KEY,
geomName);
         final Map<String,?> envpInfo = Collections.singletonMap(AbstractIdentifiedType.NAME_KEY,
AttributeConvention.ENVELOPE_PROPERTY);
@@ -249,5 +264,12 @@ final class Types extends Static {
         builder.addProperty(route.getProperty(Tags.TYPE));
         builder.addAssociation(trackSegment).setName(Tags.TRACK_SEGMENTS).setMaximumOccurs(Integer.MAX_VALUE);
         track = builder.build();
+
+        final FeatureCatalogBuilder fc = new FeatureCatalogBuilder(null);
+        fc.define(wayPoint);
+        fc.define(route);
+        fc.define(track);
+        metadata = fc.build(true);
+        names = fc.features;
     }
 }

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Writer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Writer.java?rev=1777193&r1=1777192&r2=1777193&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Writer.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/Writer.java
[UTF-8] Tue Jan  3 17:59:18 2017
@@ -43,13 +43,6 @@ import org.opengis.feature.FeatureType;
  */
 final class Writer extends StaxStreamWriter {
     /**
-     * The {@link org.opengis.feature.FeatureType} for routes, tracks, way points, <i>etc</i>.
-     * Currently always {@link Types#DEFAULT}, but we use a field for keeping {@code Writer}
-     * ready to handle profiles or extensions.
-     */
-    private final Types types;
-
-    /**
      * The GPX file version: 0 for GPX 1.0 or 1 for GPX 1.1.
      */
     private final int version;
@@ -72,7 +65,6 @@ final class Writer extends StaxStreamWri
             throws DataStoreException, XMLStreamException, IOException
     {
         super(owner);
-        types = Types.DEFAULT;
         this.metadata = metadata;
         final Version ver = owner.version;
         if (ver != null && ver.compareTo(Store.V1_0, 2) <= 0) {
@@ -150,6 +142,7 @@ final class Writer extends StaxStreamWri
     @Override
     public void write(final Feature feature) throws DataStoreException, XMLStreamException,
JAXBException {
         if (feature != null) {
+            final Types types = ((Store) owner).types;
             final FeatureType type = feature.getType();
             if (types.wayPoint.isAssignableFrom(type)) {
                 writeWayPoint(feature, Tags.WAY_POINT);



Mime
View raw message