sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1514744 - in /sis/branches/JDK7/storage: sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/ sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ sis-storage/src/main/java/org/apache/sis/internal/storage/xml/ sis-storage/src/main/ja...
Date Fri, 16 Aug 2013 14:54:20 GMT
Author: desruisseaux
Date: Fri Aug 16 14:54:20 2013
New Revision: 1514744

URL: http://svn.apache.org/r1514744
Log:
Renamed 'canOpen' as 'probeContent'. As a side-effect, this change allow us to restore
the 'canOpen' method that existed in SIS 0.3 as a deprecated method, to be removed in
SIS 0.5. Note that SIS 0.3 javadoc clearly stated that the 'canOpen' method was going
to change.

Modified:
    sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
    sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.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/main/java/org/apache/sis/storage/StorageConnector.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java

Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java?rev=1514744&r1=1514743&r2=1514744&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] Fri Aug 16 14:54:20 2013
@@ -112,7 +112,7 @@ public class NetcdfStoreProvider extends
      * @throws DataStoreException if an I/O error occurred.
      */
     @Override
-    public ProbeResult canOpen(StorageConnector storage) throws DataStoreException {
+    public ProbeResult probeContent(StorageConnector storage) throws DataStoreException {
         final ByteBuffer buffer = storage.getStorageAs(ByteBuffer.class);
         if (buffer != null) {
             if (buffer.remaining() < Integer.SIZE / Byte.SIZE) {

Modified: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java?rev=1514744&r1=1514743&r2=1514744&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java
[UTF-8] Fri Aug 16 14:54:20 2013
@@ -46,31 +46,31 @@ import static org.opengis.test.Assert.*;
 })
 public final strictfp class NetcdfStoreProviderTest extends IOTestCase {
     /**
-     * Tests {@link NetcdfStoreProvider#canOpen(StorageConnector)} for an input stream which
shall
+     * Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for an input stream
which shall
      * be recognized as a classic NetCDF file.
      *
      * @throws DataStoreException Should never happen.
      */
     @Test
-    public void testCanOpenFromStream() throws DataStoreException {
+    public void testProbeContentFromStream() throws DataStoreException {
         final StorageConnector c = new StorageConnector(IOTestCase.class.getResourceAsStream(NCEP));
         final NetcdfStoreProvider provider = new NetcdfStoreProvider();
-        assertEquals(ProbeResult.SUPPORTED, provider.canOpen(c));
+        assertEquals(ProbeResult.SUPPORTED, provider.probeContent(c));
         c.closeAllExcept(null);
     }
 
     /**
-     * Tests {@link NetcdfStoreProvider#canOpen(StorageConnector)} for a UCAR {@link NetcdfFile}
object.
+     * Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for a UCAR {@link
NetcdfFile} object.
      *
      * @throws IOException If an error occurred while opening the NetCDF file.
      * @throws DataStoreException Should never happen.
      */
     @Test
-    public void testCanOpenFromUCAR() throws IOException, DataStoreException {
+    public void testProbeContentFromUCAR() throws IOException, DataStoreException {
         final NetcdfFile file = open(NCEP);
         final StorageConnector c = new StorageConnector(file);
         final NetcdfStoreProvider provider = new NetcdfStoreProvider();
-        assertEquals(ProbeResult.SUPPORTED, provider.canOpen(c));
+        assertEquals(ProbeResult.SUPPORTED, provider.probeContent(c));
         file.close();
     }
 

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java?rev=1514744&r1=1514743&r2=1514744&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
[UTF-8] Fri Aug 16 14:54:20 2013
@@ -54,7 +54,7 @@ public class XMLStoreProvider extends Da
      * header.
      */
     @Override
-    public ProbeResult canOpen(final StorageConnector storage) throws DataStoreException
{
+    public ProbeResult probeContent(final StorageConnector storage) throws DataStoreException
{
         /*
          * Usual case. This include InputStream, DataInput, File, Path, URL, URI.
          */

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=1514744&r1=1514743&r2=1514744&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:54:20 2013
@@ -84,7 +84,7 @@ public abstract class DataStoreProvider 
      * with the format, as in the following example:
      *
      * {@preformat java
-     *     public ProbeResult canOpen(StorageConnector storage) throws DataStoreException
{
+     *     public ProbeResult probeContent(StorageConnector storage) throws DataStoreException
{
      *         final ByteBuffer buffer = storage.getStorageAs(ByteBuffer.class);
      *         if (buffer == null) {
      *             // If StorageConnector can not provide a ByteBuffer, then the storage
is
@@ -112,7 +112,7 @@ public abstract class DataStoreProvider 
      * @throws DataStoreException if an I/O or SQL error occurred. The error shall be unrelated
to the logical
      *         structure of the storage.
      */
-    public abstract ProbeResult canOpen(StorageConnector storage) throws DataStoreException;
+    public abstract ProbeResult probeContent(StorageConnector storage) throws DataStoreException;
 
     /**
      * Returns a data store implementation associated with this provider.
@@ -129,4 +129,25 @@ public abstract class DataStoreProvider 
      * @see DataStores#open(Object)
      */
     public abstract DataStore open(StorageConnector storage) throws DataStoreException;
+
+    /**
+     * Returns {@code TRUE} if the given storage appears to be supported by the {@code DataStore}.
+     *
+     * @param  storage Information about the storage (URL, stream, JDBC connection, <i>etc</i>).
+     * @return {@link Boolean#TRUE} if the given storage seems to be usable by the {@code
DataStore} instances
+     *         create by this provider, {@link Boolean#FALSE} if the {@code DataStore} will
not be able to use
+     *         the given storage, or {@code null} if this method does not have enough information.
+     * @throws DataStoreException if an I/O or SQL error occurred. The error shall be unrelated
to the logical
+     *         structure of the storage.
+     *
+     * @deprecated Replaced by {@link #probeContent(StorageConnector)}.
+     */
+    @Deprecated
+    public Boolean canOpen(final StorageConnector storage) throws DataStoreException {
+        final ProbeResult probe = probeContent(storage);
+        if (ProbeResult.INSUFFICIENT_BYTES.equals(probe) || ProbeResult.UNDETERMINED.equals(probe))
{
+            return null;
+        }
+        return probe.isSupported();
+    }
 }

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=1514744&r1=1514743&r2=1514744&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:54:20 2013
@@ -98,7 +98,7 @@ final class DataStoreRegistry {
             /*
              * All usages of 'loader' and its 'providers' iterator must be protected in a
synchronized block,
              * because ServiceLoader is not thread-safe. We try to keep the synhronization
block as small as
-             * possible for less contention. In particular, the canOpen(connector) method
call may be costly.
+             * possible for less contention. In particular, the probeContent(connector) method
call may be costly.
              */
             final Iterator<DataStoreProvider> providers;
             DataStoreProvider candidate;
@@ -107,7 +107,7 @@ final class DataStoreRegistry {
                 candidate = providers.hasNext() ? providers.next() : null;
             }
             while (candidate != null) {
-                final ProbeResult probe = candidate.canOpen(connector);
+                final ProbeResult probe = candidate.probeContent(connector);
                 if (probe.isSupported()) {
                     /*
                      * Stop at the first provider claiming to be able to read the storage.
@@ -143,7 +143,7 @@ final class DataStoreRegistry {
                 }
             }
             /*
-             * If any provider did not had enough bytes for answering the 'canOpen(…)'
question,
+             * If any provider did not had enough bytes for answering the 'probeContent(…)'
question,
              * get more bytes and try again. We try to prefetch more bytes only if we have
no choice
              * in order to avoid latency on network connection.
              */
@@ -151,7 +151,7 @@ final class DataStoreRegistry {
 search:         while (!deferred.isEmpty() && connector.prefetch()) {
                     for (final Iterator<DataStoreProvider> it=deferred.iterator();
it.hasNext();) {
                         candidate = it.next();
-                        final ProbeResult probe = candidate.canOpen(connector);
+                        final ProbeResult probe = candidate.probeContent(connector);
                         if (probe.isSupported()) {
                             provider = candidate;
                             break search;

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=1514744&r1=1514743&r2=1514744&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:54:20 2013
@@ -33,8 +33,8 @@ import java.util.Objects;
  *
  * {@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
+ * providers and invoke the {@link DataStoreProvider#probeContent(StorageConnector)} method
for each of them.
+ * The {@code ProbeResult} value returned by {@code probeContent(…)} 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.
@@ -52,7 +52,7 @@ import java.util.Objects;
  * @version 0.4
  * @module
  *
- * @see DataStoreProvider#canOpen(StorageConnector)
+ * @see DataStoreProvider#probeContent(StorageConnector)
  */
 public class ProbeResult implements Serializable {
     /**
@@ -65,7 +65,7 @@ public class ProbeResult implements Seri
      * 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
+     * <p>{@link DataStoreProvider#probeContent(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>
      */
@@ -83,7 +83,7 @@ public class ProbeResult implements Seri
      *   <li>The database schema does not contain the expected tables.</li>
      * </ul>
      *
-     * {@link DataStoreProvider#canOpen(StorageConnector)} implementations should consider
returning a
+     * {@link DataStoreProvider#probeContent(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.
@@ -92,11 +92,11 @@ public class ProbeResult implements Seri
 
     /**
      * The open capability can not be determined because the {@link ByteBuffer} contains
an insufficient
-     * amount of bytes. This value can be returned by {@link DataStoreProvider#canOpen(StorageConnector)}
+     * amount of bytes. This value can be returned by {@link DataStoreProvider#probeContent(StorageConnector)}
      * implementations as below:
      *
      * {@preformat java
-     *     public ProbeResult canOpen(StorageConnector storage) throws DataStoreException
{
+     *     public ProbeResult probeContent(StorageConnector storage) throws DataStoreException
{
      *         final ByteBuffer buffer = storage.getStorageAs(ByteBuffer.class);
      *         if (buffer == null) {
      *             return ProbeResult.UNSUPPORTED_STORAGE;
@@ -112,8 +112,8 @@ public class ProbeResult implements Seri
      * 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>SIS will continue to search for an other provider for which {@code probeContent(…)}
+     *       declares to support the storage, 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>
@@ -127,7 +127,7 @@ public class ProbeResult implements Seri
      * This value may be returned by {@code DataStore} implementations that could potentially
open anything,
      * for example the RAW image format.
      *
-     * <p><strong>This is a last resort value!</strong> {@code canOpen(…)}
implementations are strongly encouraged
+     * <p><strong>This is a last resort value!</strong> {@code probeContent(…)}
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 returned only by the RAW image format.</p>
      */

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java?rev=1514744&r1=1514743&r2=1514744&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
[UTF-8] Fri Aug 16 14:54:20 2013
@@ -350,8 +350,8 @@ public class StorageConnector implements
      *
      * Multiple invocations of this method on the same {@code StorageConnector} instance
will try
      * to return the same instance on a <cite>best effort</cite> basis. Consequently,
implementations of
-     * {@link DataStoreProvider#canOpen(StorageConnector)} methods shall not close the stream
or
-     * database connection returned by this method. In addition, those {@code canOpen(StorageConnector)}
+     * {@link DataStoreProvider#probeContent(StorageConnector)} methods shall not close the
stream or
+     * database connection returned by this method. In addition, those {@code probeContent(StorageConnector)}
      * methods are responsible for restoring the stream or byte buffer to its original position
on return.
      *
      * @param  <T>  The compile-time type of the {@code type} argument.
@@ -533,7 +533,7 @@ public class StorageConnector implements
      * channel or stream, we have reached the end of stream, or the buffer is full.
      *
      * <p>This method is invoked when the amount of bytes in the buffer appears to
be insufficient
-     * for {@link DataStoreProvider#canOpen(StorageConnector)} purpose.</p>
+     * for {@link DataStoreProvider#probeContent(StorageConnector)} purpose.</p>
      *
      * @return {@code true} on success.
      * @throws DataStoreException If an error occurred while reading more bytes.

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java?rev=1514744&r1=1514743&r2=1514744&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
[UTF-8] Fri Aug 16 14:54:20 2013
@@ -36,15 +36,15 @@ import static org.junit.Assert.*;
  */
 public final strictfp class XMLStoreProviderTest extends TestCase {
     /**
-     * Tests {@link XMLStoreProvider#canOpen(StorageConnector)} method from a {@link Reader}
object.
+     * Tests {@link XMLStoreProvider#probeContent(StorageConnector)} method from a {@link
Reader} object.
      *
      * @throws DataStoreException Should never happen.
      */
     @Test
-    public void testCanOpenFromReader() throws DataStoreException {
+    public void testProbeContentFromReader() throws DataStoreException {
         final XMLStoreProvider p = new XMLStoreProvider();
         final StorageConnector c = new StorageConnector(new StringReader(XMLStoreTest.XML));
-        assertEquals(ProbeResult.SUPPORTED, p.canOpen(c));
+        assertEquals(ProbeResult.SUPPORTED, p.probeContent(c));
         c.closeAllExcept(null);
     }
 }



Mime
View raw message