sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1727313 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-referencing/src/main/java/org/apache/sis/referencing/factory/
Date Thu, 28 Jan 2016 11:53:36 GMT
Author: desruisseaux
Date: Thu Jan 28 11:53:36 2016
New Revision: 1727313

URL: http://svn.apache.org/viewvc?rev=1727313&view=rev
Log:
The RecordSchema used for reporting operation accuracy needs to be serializable.

Added:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/RecordSchemaSIS.java
      - copied, changed from r1727153, sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java

Copied: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/RecordSchemaSIS.java
(from r1727153, sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/RecordSchemaSIS.java?p2=sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/RecordSchemaSIS.java&p1=sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java&r1=1727153&r2=1727313&rev=1727313&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/RecordSchemaSIS.java
[UTF-8] Thu Jan 28 11:53:36 2016
@@ -16,87 +16,54 @@
  */
 package org.apache.sis.internal.metadata;
 
-import java.util.Collections;
-import javax.measure.unit.SI;
-import org.opengis.util.RecordType;
-import org.opengis.util.InternationalString;
-import org.opengis.metadata.quality.PositionalAccuracy;
-import org.opengis.metadata.quality.EvaluationMethodType;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
 import org.apache.sis.internal.util.Constants;
-import org.apache.sis.metadata.iso.quality.DefaultQuantitativeResult;
-import org.apache.sis.metadata.iso.quality.DefaultAbsoluteExternalPositionalAccuracy;
-import org.apache.sis.util.collection.WeakValueHashMap;
 import org.apache.sis.util.iso.DefaultRecordSchema;
-import org.apache.sis.util.iso.DefaultRecord;
-import org.apache.sis.util.resources.Vocabulary;
-import org.apache.sis.util.Static;
 
 
 /**
- * Creates a record reporting coordinate transformation accuracy.
+ * The system-wide schema in the "SIS" namespace.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
  * @version 0.7
  * @module
  */
-public final class TransformationAccuracy extends Static {
+final class RecordSchemaSIS extends DefaultRecordSchema implements Serializable {
     /**
-     * The name for the transformation accuracy metadata.
+     * For cross-version compatibility.
      */
-    private static final InternationalString TRANSFORMATION_ACCURACY =
-            Vocabulary.formatInternational(Vocabulary.Keys.TransformationAccuracy);
+    private static final long serialVersionUID = 2708181165532467516L;
 
     /**
-     * The type of record instances which will hold coordinate transformation accuracy values.
+     * The schema used in SIS for creating records.
      */
-    private static final RecordType TYPE;
-    static {
-        final DefaultRecordSchema schema = new DefaultRecordSchema(null, null, Constants.SIS);
-        TYPE = schema.createRecordType("Real", Collections.<CharSequence,Class<?>>singletonMap(
-                Vocabulary.formatInternational(Vocabulary.Keys.Value), Double.class));
-    }
+    static final DefaultRecordSchema INSTANCE = new RecordSchemaSIS();
 
     /**
-     * Cache the positional accuracies. Most coordinate operation use a small set of accuracy
values.
+     * Creates the unique instance.
      */
-    private static final WeakValueHashMap<Double,PositionalAccuracy> CACHE = new WeakValueHashMap<>(Double.class);
+    private RecordSchemaSIS() {
+        super(null, null, Constants.SIS);
+    }
 
     /**
-     * Do not allow instantiation of this class.
+     * On serialization, returns a proxy which will be resolved as {@link #INSTANCE} on deserialization.
      */
-    private TransformationAccuracy() {
+    Object writeReplace() throws ObjectStreamException {
+        return new Proxy();
     }
 
     /**
-     * Creates a positional accuracy for the given value, in metres.
-     * This method may return a cached value.
-     *
-     * @param accuracy The accuracy in metres.
-     * @return A positional accuracy with the given value.
+     * The object to serialize instead of {@link DefaultRecordSchema}.
+     * This proxy is itself replaced by {@link SerializableRecordSchema#INSTANCE} on deserialization.
      */
-    public static PositionalAccuracy create(final Double accuracy) {
-        PositionalAccuracy p = CACHE.get(accuracy);
-        if (p == null) {
-            final DefaultRecord record = new DefaultRecord(TYPE);
-            record.setAll(accuracy);
-
-            final DefaultQuantitativeResult result = new DefaultQuantitativeResult();
-            result.setValues(Collections.singletonList(record));
-            result.setValueUnit(SI.METRE);              // In metres by definition in the
EPSG database.
-            result.setValueType(TYPE);
-
-            final DefaultAbsoluteExternalPositionalAccuracy element =
-                    new DefaultAbsoluteExternalPositionalAccuracy(result);
-            element.setNamesOfMeasure(Collections.singleton(TRANSFORMATION_ACCURACY));
-            element.setEvaluationMethodType(EvaluationMethodType.DIRECT_EXTERNAL);
-            element.freeze();
-
-            p = CACHE.putIfAbsent(accuracy, element);
-            if (p == null) {
-                p = element;
-            }
+    private static final class Proxy implements Serializable {
+        private static final long serialVersionUID = -4381124182735566127L;
+
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
         }
-        return p;
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java?rev=1727313&r1=1727312&r2=1727313&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/TransformationAccuracy.java
[UTF-8] Thu Jan 28 11:53:36 2016
@@ -22,11 +22,9 @@ import org.opengis.util.RecordType;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.quality.PositionalAccuracy;
 import org.opengis.metadata.quality.EvaluationMethodType;
-import org.apache.sis.internal.util.Constants;
 import org.apache.sis.metadata.iso.quality.DefaultQuantitativeResult;
 import org.apache.sis.metadata.iso.quality.DefaultAbsoluteExternalPositionalAccuracy;
 import org.apache.sis.util.collection.WeakValueHashMap;
-import org.apache.sis.util.iso.DefaultRecordSchema;
 import org.apache.sis.util.iso.DefaultRecord;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.Static;
@@ -50,12 +48,9 @@ public final class TransformationAccurac
     /**
      * The type of record instances which will hold coordinate transformation accuracy values.
      */
-    private static final RecordType TYPE;
-    static {
-        final DefaultRecordSchema schema = new DefaultRecordSchema(null, null, Constants.SIS);
-        TYPE = schema.createRecordType("Real", Collections.<CharSequence,Class<?>>singletonMap(
-                Vocabulary.formatInternational(Vocabulary.Keys.Value), Double.class));
-    }
+    private static final RecordType TYPE = RecordSchemaSIS.INSTANCE.createRecordType("Real",
+            Collections.<CharSequence,Class<?>>singletonMap(
+                    Vocabulary.formatInternational(Vocabulary.Keys.Value), Double.class));
 
     /**
      * Cache the positional accuracies. Most coordinate operation use a small set of accuracy
values.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java?rev=1727313&r1=1727312&r2=1727313&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
[UTF-8] Thu Jan 28 11:53:36 2016
@@ -733,6 +733,9 @@ public class MultiAuthoritiesFactory ext
         final String[] parameters;
         final DefinitionURI uri = DefinitionURI.parse(code);
         if (uri != null) {
+            if (uri.authority == null) {
+                throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.MissingAuthority_1,
code), null, uri.code, code);
+            }
             final Class<? extends T> type = proxy.type;
             authority  = uri.authority;
             version    = uri.version;



Mime
View raw message