sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1490723 [2/2] - in /sis/trunk: ./ core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/ core/sis-build-helper/src/site/apt/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/main/java/org/apache/s...
Date Fri, 07 Jun 2013 16:54:17 GMT
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1490723&r1=1490722&r2=1490723&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java [UTF-8]
(original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java [UTF-8]
Fri Jun  7 16:54:16 2013
@@ -16,9 +16,13 @@
  */
 package org.apache.sis.storage;
 
+import java.util.Locale;
 import java.util.NoSuchElementException;
 import org.opengis.metadata.Metadata;
+import org.apache.sis.util.Localized;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.util.logging.WarningListeners;
 
 // Related to JDK7
 import org.apache.sis.internal.jdk7.AutoCloseable;
@@ -33,7 +37,49 @@ import org.apache.sis.internal.jdk7.Auto
  * @version 0.3
  * @module
  */
-public interface DataStore extends AutoCloseable {
+public abstract class DataStore implements Localized, AutoCloseable {
+    /**
+     * The locale to use for formatting warnings.
+     *
+     * @see #getLocale()
+     * @see #setLocale(Locale)
+     */
+    private Locale locale;
+
+    /**
+     * The set of registered {@link WarningListener}s for this data store.
+     */
+    protected final WarningListeners<DataStore> listeners;
+
+    /**
+     * Creates a new instance with initially no listener.
+     */
+    protected DataStore() {
+        locale = Locale.getDefault();
+        listeners = new WarningListeners<DataStore>(this);
+    }
+
+    /**
+     * The locale to use for formatting warnings and other messages. This locale if for user
interfaces
+     * only - it has no effect on the data to be read or written from/to the data store.
+     *
+     * <p>The default value is the {@linkplain Locale#getDefault() system default locale}.</p>
+     */
+    @Override
+    public synchronized Locale getLocale() {
+        return locale;
+    }
+
+    /**
+     * Sets the locale to use for formatting warnings and other messages.
+     *
+     * @param locale The new locale to use.
+     */
+    public synchronized void setLocale(final Locale locale) {
+        ArgumentChecks.ensureNonNull("locale", locale);
+        this.locale = locale;
+    }
+
     /**
      * Returns information about the dataset as a whole. The returned metadata object, if
any, can contain
      * information such as the spatiotemporal extent of the dataset, contact information
about the creator
@@ -42,7 +88,7 @@ public interface DataStore extends AutoC
      * @return Information about the dataset, or {@code null} if none.
      * @throws DataStoreException If an error occurred while reading the data.
      */
-    Metadata getMetadata() throws DataStoreException;
+    public abstract Metadata getMetadata() throws DataStoreException;
 
     /**
      * Adds a listener to be notified when a warning occurred while reading from or writing
to the storage.
@@ -70,7 +116,11 @@ public interface DataStore extends AutoC
      * @param  listener The listener to add.
      * @throws IllegalArgumentException If the given listener is already registered in this
data store.
      */
-    void addWarningListener(WarningListener<? super DataStore> listener) throws IllegalArgumentException;
+    public void addWarningListener(final WarningListener<? super DataStore> listener)
+            throws IllegalArgumentException
+    {
+        listeners.addWarningListener(listener);
+    }
 
     /**
      * Removes a previously registered listener.
@@ -78,7 +128,11 @@ public interface DataStore extends AutoC
      * @param  listener The listener to remove.
      * @throws NoSuchElementException If the given listener is not registered in this data
store.
      */
-    void removeWarningListener(WarningListener<? super DataStore> listener) throws
NoSuchElementException;
+    public void removeWarningListener(final WarningListener<? super DataStore> listener)
+            throws NoSuchElementException
+    {
+        listeners.removeWarningListener(listener);
+    }
 
     /**
      * Closes this data store and releases any underlying resources.
@@ -86,5 +140,5 @@ public interface DataStore extends AutoC
      * @throws DataStoreException If an error occurred while closing this data store.
      */
     @Override
-    void close() throws DataStoreException;
+    public abstract void close() throws DataStoreException;
 }

Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java?rev=1490723&r1=1490722&r2=1490723&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
[UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
[UTF-8] Fri Jun  7 16:54:16 2013
@@ -18,7 +18,7 @@ package org.apache.sis.storage;
 
 
 /**
- * Creates {@link DataStore} instances for a specific format from a given {@link DataStoreConnection}
input.
+ * Creates {@link DataStore} instances for a specific format from a given {@link StorageConnector}
input.
  * There is typically a different {@code DataStoreProvider} instance for each format provided
by a library.
  *
  * @author  Martin Desruisseaux (Geomatys)
@@ -37,7 +37,7 @@ public abstract class DataStoreProvider 
      * Returns {@code TRUE} if the given storage appears to be supported by the {@code DataStore}.
      * Returning {@code TRUE} from this method 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 DataStoreConnection#getStorage() storage object} or contents.
+     * {@linkplain StorageConnector#getStorage() storage object} or contents.
      *
      * <p>Implementations will typically check the first bytes of the stream for a
"magic number"
      * associated with the format, as in the following example:</p>
@@ -45,9 +45,9 @@ public abstract class DataStoreProvider 
      * {@preformat java
      *     final ByteBuffer buffer = storage.getStorageAs(ByteBuffer.class);
      *     if (buffer == null) {
-     *         // If DataStoreConnection can not provide a ByteBuffer, then the storage is
probably
-     *         // not a File, URL, URI, InputStream neither a ReadableChannel. In this example,
our
-     *         // provider can not handle such unknown source.
+     *         // If StorageConnector can not provide a ByteBuffer, then the storage is probably
+     *         // not a File, URL, URI, InputStream neither a ReadableChannel. In this example,
+     *         // our provider can not handle such unknown source.
      *         return Boolean.FALSE;
      *     }
      *     if (buffer.remaining() < Integer.SIZE / Byte.SIZE) {
@@ -73,18 +73,18 @@ 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 Boolean canOpen(DataStoreConnection storage) throws DataStoreException;
+    public abstract Boolean canOpen(StorageConnector storage) throws DataStoreException;
 
     /**
      * Returns a data store implementation associated with this provider.
      *
      * <p><b>Implementation note:</b>
-     * Implementors shall invoke {@link DataStoreConnection#closeAllExcept(Object)} after
{@code DataStore}
+     * Implementors shall invoke {@link StorageConnector#closeAllExcept(Object)} after {@code
DataStore}
      * creation, keeping open only the needed resource.</p>
      *
      * @param  storage Information about the storage (URL, stream, JDBC connection, <i>etc</i>).
      * @return A data store implementation associated with this provider for the given storage.
      * @throws DataStoreException if an error occurred while creating the data store instance.
      */
-    public abstract DataStore open(DataStoreConnection storage) throws DataStoreException;
+    public abstract DataStore open(StorageConnector storage) throws DataStoreException;
 }

Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java?rev=1490723&r1=1490722&r2=1490723&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java [UTF-8]
(original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java [UTF-8]
Fri Jun  7 16:54:16 2013
@@ -19,6 +19,20 @@
  * {@linkplain org.apache.sis.storage.DataStore Data store} base types for retrieving and
saving geospatial data
  * in various storage formats.
  *
+ * <p>Different {@code DataStore} implementations will want different kind of input/output
objects. Some examples are
+ * {@link java.lang.String}, {@link java.nio.file.Path}, {@link java.io.File}, {@link java.net.URI},
{@link java.net.URL},
+ * {@link java.io.InputStream}, {@link javax.imageio.stream.ImageInputStream}, {@link java.nio.channels.ReadableChannel},
+ * JDBC {@link java.sql.Connection} or {@link javax.sql.DataSource}, or even
+ * datastore-specific objects like {@link ucar.nc2.NetcdfFile}.
+ * Because of this variety, SIS does not know which kind of object to accept before the appropriate
{@code DataStore}
+ * instance has been found. For this reason, storages are represented by arbitrary {@link
java.lang.Object} encapsulated
+ * in {@link org.apache.sis.storage.StorageConnector}. The later can open the object in various
ways, for example
+ * as {@link java.io.DataInput} or as {@link java.nio.ByteBuffer}, depending on {@code DataStore
needs}.
+ * Future versions may contain additional information like login/password.</p>
+ *
+ * <p>{@code StorageConnector} is used only for the "discovery" phase, and discarded
once the actual
+ * {@code DataStore} instance has been created.</p>
+ *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.10)

Modified: sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1490723&r1=1490722&r2=1490723&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] Fri Jun  7 16:54:16 2013
@@ -33,12 +33,13 @@ 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.DataStoreConnectionTest.class
+    org.apache.sis.storage.StorageConnectorTest.class,
+    org.apache.sis.index.GeoHashCoderTest.class
 })
 public final strictfp class StorageTestSuite extends TestSuite {
     /**
      * Verifies the list of tests before to run the suite.
-     * See {@link #verifyTestList(Class, Class<?>[])} for more information.
+     * See {@link #verifyTestList(Class, Class[])} for more information.
      */
     @BeforeClass
     public static void verifyTestList() {



Mime
View raw message