Modified: 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1490719&r1=1490718&r2=1490719&view=diff
==============================================================================
--- 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
 [UTF-8] (original)
+++ 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
 [UTF-8] Fri Jun  7 16:46:54 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/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java?rev=1490719&r1=1490718&r2=1490719&view=diff
==============================================================================
--- 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
 [UTF-8] (original)
+++ 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
 [UTF-8] Fri Jun  7 16:46:54 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;
 }

Copied: 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
 (from r1490712, 
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java?p2=sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java&p1=sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java&r1=1490712&r2=1490719&rev=1490719&view=diff
==============================================================================
--- 
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
 [UTF-8] (original)
+++ 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
 [UTF-8] Fri Jun  7 16:46:54 2013
@@ -38,6 +38,9 @@ import org.apache.sis.internal.storage.C
 import org.apache.sis.internal.storage.ChannelImageInputStream;
 import org.apache.sis.setup.OptionKey;
 
+// Related to JDK7
+import org.apache.sis.internal.jdk7.JDK7;
+
 
 /**
  * Information for creating a connection to a {@link DataStore} in read and/or 
write mode.
@@ -317,7 +320,7 @@ public class StorageConnector implements
                 return (view != Void.TYPE) ? type.cast(view) : null;
             }
         } else {
-            views = new IdentityHashMap<>();
+            views = new IdentityHashMap<Class<?>, Object>();
         }
         /*
          * Special case for DataInput and ByteBuffer, because those values are 
created together.
@@ -531,27 +534,27 @@ public class StorageConnector implements
          * DataInput and ImageInputStream are often the same instance. We must 
avoid duplicated
          * values because ImageInputStream.close() is not indempotent.
          */
-        final Map<AutoCloseable,Object> toClose = new IdentityHashMap<>(4);
+        final Map<Object,Object> toClose = new 
IdentityHashMap<Object,Object>(4);
         for (final Object value : views.values()) {
-            if (value instanceof AutoCloseable) {
-                toClose.put((AutoCloseable) value, null);
+            if (JDK7.isAutoCloseable(value)) {
+                toClose.put(value, null);
             }
         }
         toClose.remove(view);
         toClose.remove(storage);
         try {
             if (!toClose.isEmpty()) {
-                for (final AutoCloseable value : toClose.keySet()) {
-                    value.close();
+                for (final Object value : toClose.keySet()) {
+                    JDK7.close(value);
                 }
-            } else if (view == null && storage instanceof AutoCloseable) {
+            } else if (view == null && JDK7.isAutoCloseable(storage)) {
                 /*
                  * Close only if we didn't closed a view because closing an 
input stream view
                  * automatically close the 'storage' if the former is a 
wrapper for the later.
                  * Since AutoCloseable.close() is not guaranteed to be 
indempotent, we should
                  * avoid to call it (indirectly) twice.
                  */
-                ((AutoCloseable) storage).close();
+                JDK7.close(storage);
             }
         } catch (Exception e) {
             throw new DataStoreException(e);

Modified: 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java?rev=1490719&r1=1490718&r2=1490719&view=diff
==============================================================================
--- 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
 [UTF-8] (original)
+++ 
sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
 [UTF-8] Fri Jun  7 16:46:54 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)

Copied: 
sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java
 (from r1490712, 
sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java?p2=sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java&p1=sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java&r1=1490712&r2=1490719&rev=1490719&view=diff
==============================================================================
--- 
sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/index/GeoHashCoderTest.java
 [UTF-8] Fri Jun  7 16:46:54 2013
@@ -57,7 +57,7 @@ public final strictfp class GeoHashCoder
      * Returns a map of places with their expected geohash.
      */
     private Map<String, Place> places() {
-        final Map<String, Place> places = new HashMap<>(12);
+        final Map<String, Place> places = new HashMap<String, Place>(12);
         places.put("Empire State Building", new Place(40.748433,  -73.985656, 
"dr5ru6j2c62q"));
         places.put("Statue Of Liberty",     new Place(40.689167,  -74.044444, 
"dr5r7p4rx6kz"));
         places.put("The White House",       new Place(38.897669,  -77.036550, 
"dqcjqcpeq70c"));

Modified: 
sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1490719&r1=1490718&r2=1490719&view=diff
==============================================================================
--- 
sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
 [UTF-8] (original)
+++ 
sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
 [UTF-8] Fri Jun  7 16:46:54 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() {


Reply via email to