sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1514733 - in /sis/branches/JDK7: core/sis-utility/src/main/java/org/apache/sis/internal/util/ core/sis-utility/src/test/java/org/apache/sis/internal/util/ storage/sis-storage/src/main/java/org/apache/sis/storage/ storage/sis-storage/src/te...
Date Fri, 16 Aug 2013 14:36:57 GMT
Author: desruisseaux
Date: Fri Aug 16 14:36:57 2013
New Revision: 1514733

URL: http://svn.apache.org/r1514733
Log:
Changed 'ProbeResult' type from enum to class, in order to allow implementors
to specify additional information like MIME type and format version number.

Added:
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1514733&r1=1514732&r2=1514733&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -19,6 +19,7 @@ package org.apache.sis.internal.util;
 import java.util.Formatter;
 import java.util.FormattableFlags;
 import org.apache.sis.util.Static;
+import org.apache.sis.util.Classes;
 import org.apache.sis.util.CharSequences;
 
 import static java.lang.Math.abs;
@@ -30,7 +31,7 @@ import static java.lang.Math.max;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final class Utilities extends Static {
@@ -117,6 +118,37 @@ public final class Utilities extends Sta
     }
 
     /**
+     * Returns a string representation of an instance of the given class having the given
properties.
+     * This is a convenience method for implementation of {@link Object#toString()} methods
that are
+     * used mostly for debugging purpose.
+     *
+     * @param  classe     The class to format.
+     * @param  properties The (<var>key</var>=</var>value</var>)
pairs.
+     * @return A string representation of an instance of the given class having the given
properties.
+     *
+     * @since 0.4
+     */
+    public static String toString(final Class<?> classe, final Object... properties)
{
+        final StringBuffer buffer = new StringBuffer(32).append(Classes.getShortName(classe)).append('[');
+        boolean isNext = false;
+        for (int i=0; i<properties.length; i++) {
+            final Object value = properties[++i];
+            if (value != null) {
+                if (isNext) {
+                    buffer.append(", ");
+                }
+                buffer.append(properties[i-1]).append('=');
+                final boolean isText = (value instanceof CharSequence);
+                if (isText) buffer.append('“');
+                buffer.append(value);
+                if (isText) buffer.append('”');
+                isNext = true;
+            }
+        }
+        return buffer.append(']').toString();
+    }
+
+    /**
      * Formats the given character sequence to the given formatter. This method takes in
account
      * the {@link FormattableFlags#UPPERCASE} and {@link FormattableFlags#LEFT_JUSTIFY} flags.
      *

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java?rev=1514733&r1=1514732&r2=1514733&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -31,7 +31,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final strictfp class UtilitiesTest extends TestCase {
@@ -51,4 +51,12 @@ public final strictfp class UtilitiesTes
         assertTrue (epsilonEqual(-100, -100 + COMPARISON_THRESHOLD * 50));
         assertFalse(epsilonEqual( 100,  100 + COMPARISON_THRESHOLD * 150));
     }
+
+    /**
+     * Tests the {@link Utilities#toString(Class, Object[])} method.
+     */
+    @Test
+    public void testToString() {
+        assertEquals("Number[base=“decimal”, value=20]", Utilities.toString(Number.class,
"base", "decimal", "value", 20));
+    }
 }

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java?rev=1514733&r1=1514732&r2=1514733&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.storage;
 
-import java.util.Set;
 import org.apache.sis.util.ThreadSafe;
 
 
@@ -71,7 +70,7 @@ public abstract class DataStoreProvider 
      *       supported by this {@code DataStoreProvider}.</li>
      * </ul>
      *
-     * Note that the {@code SUPPORTED_FORMAT} value does not guarantee that reading or writing
will succeed,
+     * Note that the {@code SUPPORTED} value does not guarantee that reading or writing will
succeed,
      * only that there appears to be a reasonable chance of success based on a brief inspection
of the
      * {@linkplain StorageConnector#getStorage() storage object} or contents.
      *

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java?rev=1514733&r1=1514732&r2=1514733&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -51,7 +51,7 @@ final class DataStoreRegistry {
      * Creates a new registry which will use the current thread
      * {@linkplain Thread#getContextClassLoader() context class loader}.
      */
-    public DataStoreRegistry() {
+    DataStoreRegistry() {
         loader = ServiceLoader.load(DataStoreProvider.class);
     }
 
@@ -60,7 +60,7 @@ final class DataStoreRegistry {
      *
      * @param loader The class loader to use for loading {@link DataStoreProvider} implementations.
      */
-    public DataStoreRegistry(final ClassLoader loader) {
+    DataStoreRegistry(final ClassLoader loader) {
         ArgumentChecks.ensureNonNull("loader", loader);
         this.loader = ServiceLoader.load(DataStoreProvider.class, loader);
     }
@@ -106,29 +106,28 @@ final class DataStoreRegistry {
                 providers = loader.iterator();
                 candidate = providers.hasNext() ? providers.next() : null;
             }
-search:     while (candidate != null) {
-                switch (candidate.canOpen(connector)) {
+            while (candidate != null) {
+                final ProbeResult probe = candidate.canOpen(connector);
+                if (probe.isSupported()) {
                     /*
                      * Stop at the first provider claiming to be able to read the storage.
                      * Do not iterate over the list of deferred providers (if any).
                      */
-                    case SUPPORTED: {
-                        provider = candidate;
-                        deferred = null;
-                        break search;
-                    }
+                    provider = candidate;
+                    deferred = null;
+                    break;
+                }
+                if (ProbeResult.INSUFFICIENT_BYTES.equals(probe)) {
                     /*
                      * If a provider doesn't have enough bytes for answering the question,
                      * try again after this loop with more bytes in the buffer, unless we
                      * found an other provider.
                      */
-                    case INSUFFICIENT_BYTES: {
-                        if (deferred == null) {
-                            deferred = new LinkedList<>();
-                        }
-                        deferred.add(candidate);
-                        break;
+                    if (deferred == null) {
+                        deferred = new LinkedList<>();
                     }
+                    deferred.add(candidate);
+                } else if (ProbeResult.UNDETERMINED.equals(probe)) {
                     /*
                      * If a provider doesn't know whether it can open the given storage,
                      * we will try it only if we find no provider retuning SUPPORTED.
@@ -137,10 +136,7 @@ search:     while (candidate != null) {
                      *       provider.open(connector) in a try … catch block because it
may leave
                      *       the StorageConnector in an invalid state in case of failure.
                      */
-                    case UNDETERMINED: {
-                        provider = candidate;
-                        break;
-                    }
+                    provider = candidate;
                 }
                 synchronized (loader) {
                     candidate = providers.hasNext() ? providers.next() : null;
@@ -155,12 +151,17 @@ search:     while (candidate != null) {
 search:         while (!deferred.isEmpty() && connector.prefetch()) {
                     for (final Iterator<DataStoreProvider> it=deferred.iterator();
it.hasNext();) {
                         candidate = it.next();
-                        switch (candidate.canOpen(connector)) {
-                            case SUPPORTED:          provider = candidate; break search;
-                            case UNDETERMINED:       provider = candidate; break;
-                            case INSUFFICIENT_BYTES: continue; // Will try again in next
iteration.
+                        final ProbeResult probe = candidate.canOpen(connector);
+                        if (probe.isSupported()) {
+                            provider = candidate;
+                            break search;
+                        }
+                        if (!ProbeResult.INSUFFICIENT_BYTES.equals(probe)) {
+                            if (ProbeResult.UNDETERMINED.equals(probe)) {
+                                provider = candidate; // To be used only if we don't find
a better match.
+                            }
+                            it.remove(); // UNSUPPORTED_* or UNDETERMINED: do not try again
those providers.
                         }
-                        it.remove(); // UNSUPPORTED_* or UNDETERMINED: do not try again those
providers.
                     }
                 }
             }

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java?rev=1514733&r1=1514732&r2=1514733&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -16,25 +16,37 @@
  */
 package org.apache.sis.storage;
 
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import org.apache.sis.util.Debug;
+import org.apache.sis.util.Version;
+import org.apache.sis.internal.util.Utilities;
+
+// Related to JDK7
+import java.util.Objects;
+
 
 /**
  * Tells whether a storage (file, database) appears to be supported by a {@code DataStore}.
- * There is three categories of values in this enumeration:
- *
- * <ul>
- *   <li>{@link #SUPPORTED} indicates that the storage can be read and eventually written.</li>
- *   <li>{@code UNSUPPORTED_*} indicate that the storage can not be opened. The actual
enumeration value gives
- *       the reason (e.g. unsupported format or {@linkplain #UNSUPPORTED_VERSION unsupported
version}).</li>
- *   <li>{@link #INSUFFICIENT_BYTES} or {@link #UNDETERMINED} indicate that the provider
does not have enough
- *       information for telling whether the storage can be opened. SIS will try to use such
provider last,
- *       if no better suited provider is found.</li>
- * </ul>
+ * {@code ProbeResult} may also provide additional information, like file MIME type and the
+ * format version.
  *
+ * {@section Usage}
  * When a {@link DataStores#open DataStores.open(…)} method is invoked, SIS will iterate
over the list of known
  * providers and invoke the {@link DataStoreProvider#canOpen(StorageConnector)} method for
each of them.
  * The {@code ProbeResult} value returned by {@code canOpen(…)} tells to SIS whether a
particular
  * {@code DataStoreProvider} instance has reasonable chances to be able to handle the given
storage.
  *
+ * <p>Whether a storage appears to be supported or not is given by the {@link #isSupported()}
property.
+ * Other properties like {@link #getVersion()} are sometime available for both supported
and unsupported storages.
+ * For example a file may be encoded in a known format, but may be using an unsupported version
of that format.</p>
+ *
+ * {@section Special values}
+ * In addition to the supported/unsupported information, {@code ProbeResult} defines two
constants having
+ * a special meaning: {@link #INSUFFICIENT_BYTES} and {@link #UNDETERMINED} indicate that
the provider does
+ * not have enough information for telling whether the storage can be opened.
+ * SIS will try to use such provider last, if no better suited provider is found.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4
@@ -42,36 +54,46 @@ package org.apache.sis.storage;
  *
  * @see DataStoreProvider#canOpen(StorageConnector)
  */
-public enum ProbeResult {
+public class ProbeResult implements Serializable {
     /**
-     * The {@code DataStoreProvider} recognizes the given storage.
-     * {@code DataStore} instances created by that provider are likely (but not guaranteed)
-     * to be able to read from - and eventually write to - the given storage.
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -4977853847503500550L;
+
+    /**
+     * The {@code DataStoreProvider} recognizes the given storage, but has no additional
information.
+     * The {@link #isSupported()} method returns {@code true}, but the {@linkplain #getMimeType()
MIME type}
+     * and {@linkplain #getVersion() version} properties are {@code null}.
+     *
+     * <p>{@link DataStoreProvider#canOpen(StorageConnector)} implementations should
consider returning a
+     * {@linkplain #ProbeResult(boolean, String, Version) new instance} instead than this
constant
+     * if they can provide the file MIME type or the format version number.</p>
      */
-    SUPPORTED,
+    public static final ProbeResult SUPPORTED = new Constant(true, "SUPPORTED");
 
     /**
      * The {@code DataStoreProvider} does not recognize the given storage object, file format
or database schema.
-     * Examples:
+     * No other information is available: the {@link #isSupported()} method returns {@code
false}, and the
+     * {@linkplain #getMimeType() MIME type} and {@linkplain #getVersion() version} properties
are {@code null}.
      *
+     * <p>Examples:</p>
      * <ul>
      *   <li>The storage is a file while the provider expected a database connection
(or conversely).</li>
      *   <li>The file does not contains the expected magic number.</li>
      *   <li>The database schema does not contain the expected tables.</li>
      * </ul>
-     */
-    UNSUPPORTED_STORAGE,
-
-    /**
-     * The {@code DataStoreProvider} recognizes the given storage, but the data are structured
+     *
+     * {@link DataStoreProvider#canOpen(StorageConnector)} implementations should consider
returning a
+     * {@linkplain #ProbeResult(boolean, String, Version) new instance} instead than this
constant
+     * if the {@code DataStoreProvider} recognizes the given storage, but the data are structured
      * according a file or schema version not yet supported by the current implementation.
      */
-    UNSUPPORTED_VERSION,
+    public static final ProbeResult UNSUPPORTED_STORAGE = new Constant(false, "UNSUPPORTED_STORAGE");
 
     /**
      * The open capability can not be determined because the {@link ByteBuffer} contains
an insufficient
-     * amount of bytes. This value may be returned by {@link DataStoreProvider#canOpen(StorageConnector)}
-     * implementations similar to the following:
+     * amount of bytes. This value can be returned by {@link DataStoreProvider#canOpen(StorageConnector)}
+     * implementations as below:
      *
      * {@preformat java
      *     public ProbeResult canOpen(StorageConnector storage) throws DataStoreException
{
@@ -86,21 +108,215 @@ public enum ProbeResult {
      *     }
      * }
      *
-     * When some {@code DataStoreProvider} return this value, SIS will first continue the
search for a provider that
-     * can answer the {@code canOpen(…)} question using only the available bytes. Only
if no provider is found,
-     * then SIS will fetch more bytes and try again the providers that returned {@code INSUFFICIENT_BYTES}.
+     * When searching for a provider capable to read a given file,
+     * if at least one {@code DataStoreProvider} returns {@code INSUFFICIENT_BYTES}, then:
+     *
+     * <ol>
+     *   <li>SIS will continue to search for an other provider that can answer the
{@code canOpen(…)}
+     *       question using only the available bytes.</li>
+     *   <li>Only if no such provider can be found, then SIS will fetch more bytes
and query again
+     *       the providers that returned {@code INSUFFICIENT_BYTES} in the previous iteration.</li>
+     * </ol>
+     *
      * SIS tries to work with available bytes before to ask more in order to reduce latencies
on network connections.
      */
-    INSUFFICIENT_BYTES,
+    public static final ProbeResult INSUFFICIENT_BYTES = new Constant(false, "INSUFFICIENT_BYTES");
 
     /**
      * The open capability can not be determined.
      * This value may be returned by {@code DataStore} implementations that could potentially
open anything,
-     * as for example of the RAW image format.
+     * for example the RAW image format.
      *
      * <p><strong>This is a last resort value!</strong> {@code canOpen(…)}
implementations are strongly encouraged
      * to return a more accurate enumeration value for allowing {@link DataStores#open(Object)}
to perform a better
-     * choice. Generally, this value should be used only by the RAW image format.</p>
+     * choice. Generally, this value should be returned only by the RAW image format.</p>
      */
-    UNDETERMINED
+    public static final ProbeResult UNDETERMINED = new Constant(false, "UNDETERMINED");
+
+    /**
+     * {@code true} if the storage is supported by the {@link DataStoreProvider}.
+     *
+     * @see #isSupported()
+     */
+    private final boolean isSupported;
+
+    /**
+     * The storage MIME type, or {@code null} if unknown or irrelevant.
+     *
+     * @see #getMimeType()
+     */
+    private final String mimeType;
+
+    /**
+     * The version of file format or database schema used by the storage, or {@code null}
if unknown or irrelevant.
+     *
+     * @see #getVersion()
+     */
+    private final Version version;
+
+    /**
+     * Creates a new {@code ProbeResult} with the given support status, MIME type and version
number.
+     *
+     * @param isSupported {@code true} if the storage is supported by the {@link DataStoreProvider}.
+     * @param mimeType    The storage MIME type, or {@code null} if unknown or irrelevant.
+     * @param version     The version of file format or database schema used by the storage,
+     *                    or {@code null} if unknown or irrelevant.
+     */
+    public ProbeResult(final boolean isSupported, final String mimeType, final Version version)
{
+        this.isSupported = isSupported;
+        this.mimeType    = mimeType;
+        this.version     = version;
+    }
+
+    /**
+     * Returns {@code true} if the storage is supported by the {@code DataStoreProvider}.
+     * {@code DataStore} instances created by that provider are likely (but not guaranteed)
+     * to be able to read from - and eventually write to - the given storage.
+     *
+     * @return {@code true} if the storage is supported by the {@link DataStoreProvider}.
+     */
+    public boolean isSupported() {
+        return isSupported;
+    }
+
+    /**
+     * Returns the MIME type of the storage file format, or {@code null} if unknown or irrelevant.
+     * The {@link DataStoreProvider} may (at implementation choice) inspect the storage content
for
+     * determining a more accurate MIME type.
+     *
+     * {@example a generic MIME type for XML documents is <code>"application/xml"</code>.
+     * However many other MIME types exist for XML documents compliant to some particular
shema:
+     *
+     * <table class="sis">
+     *   <tr><th>MIME type</th> <th>Description</th></tr>
+     *   <tr><td><code>"application/gml+xml"</code></td>  
                             <td>Official mime type for OGC GML</td></tr>
+     *   <tr><td><code>"application/vnd.eu.europa.ec.inspire.resource+xml"</code></td>
 <td>Official mime type for INSPIRE Resources</td></tr>
+     *   <tr><td><code>"application/vnd.iso.19139+xml"</code></td>
                     <td>Unofficial mime type for ISO 19139 metadata</td></tr>
+     *   <tr><td><code>"application/vnd.ogc.wms_xml"</code></td>
                       <td>Unofficial mime type for OGC WMS</td></tr>
+     *   <tr><td><code>"application/vnd.ogc.wfs_xml"</code></td>
                       <td>Unofficial mime type for OGC WFS </td></tr>
+     *   <tr><td><code>"application/vnd.ogc.csw_xml"</code></td>
                       <td>Unofficial mime type for OGC CSW</td></tr>
+     *   <tr><td><code>"application/vnd.google-earth.kml+xml"</code></td>
              <td></td></tr>
+     *   <tr><td><code>"application/rdf+xml"</code></td>  
                             <td></td></tr>
+     *   <tr><td><code>"application/soap+xml"</code></td> 
                             <td></td></tr>
+     * </table>
+     *
+     * Consequently, a XML data store provider may need to read the root element of a XML
document in order
+     * to determine the document MIME type.}
+     *
+     * @return The storage MIME type, or {@code null} if unknown or irrelevant.
+     */
+    public String getMimeType() {
+        return mimeType;
+    }
+
+    /**
+     * Returns the version of file format or database schema used by the storage,
+     * or {@code null} if unknown or irrelevant.
+     *
+     * @return The version of file format or database schema used by the storage,
+     *         or {@code null} if unknown or irrelevant.
+     */
+    public Version getVersion() {
+        return version;
+    }
+
+    /**
+     * Returns a hash code value for this instance.
+     */
+    @Override
+    public int hashCode() {
+        return Objects.hash(isSupported, mimeType, version) ^ (int) serialVersionUID;
+    }
+
+    /**
+     * Compares this {@code ProbeResult} with the given object for equality.
+     * Two {@code ProbeResult}s are equal if they are instances of the same class
+     * and all their properties are equal.
+     *
+     * @param  object The object to compare with this {@code ProbeResult}.
+     * @return {@code true} if the two objects are equal.
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (object != null && object.getClass() == getClass()) {
+            final ProbeResult other = (ProbeResult) object;
+            return isSupported == other.isSupported &&
+                    Objects.equals(mimeType, other.mimeType) &&
+                    Objects.equals(version,  other.version);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a string representation of this {@code ProbeResult} for debugging purpose.
+     */
+    @Debug
+    @Override
+    public String toString() {
+        return Utilities.toString(getClass(), "isSupported", isSupported, "mimeType", mimeType,
"version", version);
+    }
+
+    /**
+     * Implementation of static constants defined in {@link ProbeResult}.
+     * We need a special implementation class in order to resolve deserialized instances
to their unique instance.
+     */
+    private static final class Constant extends ProbeResult {
+        /**
+         * For cross-version compatibility.
+         */
+        private static final long serialVersionUID = -5239064423134309133L;
+
+        /**
+         * The name of the public static field constant.
+         * Each name shall be unique.
+         */
+        private final String name;
+
+        /**
+         * Creates a new constant for a public static field of the given name.
+         */
+        Constant(final boolean isSupported, final String name) {
+            super(isSupported, null, null);
+            this.name = name;
+        }
+
+        /**
+         * Invoked on deserialization for fetching the unique instance, if possible.
+         * If we fail to resolve (which may happen if the instance has been serialized
+         * by a more recent SIS version), returns the instance unchanged. It should be
+         * okay if all comparisons are performed by the {@code equals} method instead
+         * than the {@code ==} operator.
+         */
+        Object readResolve() throws ObjectStreamException {
+            try {
+                return ProbeResult.class.getField(name).get(null);
+            } catch (ReflectiveOperationException e) {
+                return this; // See javadoc
+            }
+        }
+
+        /**
+         * Compares the name, which is okay since each name are unique.
+         */
+        @Override
+        public boolean equals(final Object object) {
+            return (object instanceof Constant) && name.equals(((Constant) object).name);
+        }
+
+        /**
+         * Returns a hash code derived from the name, which is okay since each name are unique.
+         */
+        @Override
+        public int hashCode() {
+            return name.hashCode() ^ (int) serialVersionUID;
+        }
+
+        /**
+         * Returns the constant name for debugging purpose.
+         */
+        @Override
+        public String toString() {
+            return "ProbeResult[" + name + ']';
+        }
+    }
 }

Added: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java?rev=1514733&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.storage;
+
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.storage.ProbeResult.*;
+
+
+/**
+ * Tests {@link ProbeResult}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.4
+ * @module
+ */
+public final strictfp class ProbeResultTest extends TestCase {
+    /**
+     * Tests serialization of pre-defined constants.
+     */
+    @Test
+    public void testConstantSerialization() {
+        assertSame("SUPPORTED",           SUPPORTED,           assertSerializedEquals(SUPPORTED));
+        assertSame("UNSUPPORTED_STORAGE", UNSUPPORTED_STORAGE, assertSerializedEquals(UNSUPPORTED_STORAGE));
+        assertSame("INSUFFICIENT_BYTES",  INSUFFICIENT_BYTES,  assertSerializedEquals(INSUFFICIENT_BYTES));
+        assertSame("UNDETERMINED",        UNDETERMINED,        assertSerializedEquals(UNDETERMINED));
+    }
+}

Propchange: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/ProbeResultTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1514733&r1=1514732&r2=1514733&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] Fri Aug 16 14:36:57 2013
@@ -33,6 +33,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.storage.IOUtilitiesTest.class,
     org.apache.sis.internal.storage.ChannelDataInputTest.class,
     org.apache.sis.internal.storage.ChannelImageInputStreamTest.class,
+    org.apache.sis.storage.ProbeResultTest.class,
     org.apache.sis.storage.StorageConnectorTest.class,
     org.apache.sis.internal.storage.xml.XMLStoreProviderTest.class,
     org.apache.sis.internal.storage.xml.XMLStoreTest.class,



Mime
View raw message