Author: desruisseaux
Date: Wed Jul 31 13:27:09 2013
New Revision: 1508849
URL: http://svn.apache.org/r1508849
Log:
First draft of a DataStores static class creating the DataStore using
ServiceLoader instead than a hard-coded class instantiation.
Added:
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
(with props)
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
(with props)
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
(with props)
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java
(with props)
Modified:
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
sis/branches/JDK7/ide-project/NetBeans/build.xml
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.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/StorageConnector.java
Modified:
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
[UTF-8] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -23,9 +23,9 @@ import javax.xml.bind.JAXBException;
import org.opengis.metadata.Metadata;
import org.apache.sis.metadata.MetadataStandard;
import org.apache.sis.metadata.ValueExistencePolicy;
+import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStores;
import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.storage.StorageConnector;
-import org.apache.sis.storage.netcdf.NetcdfStore;
import org.apache.sis.util.collection.TableColumn;
import org.apache.sis.util.collection.TreeTable;
import org.apache.sis.util.collection.TreeTableFormat;
@@ -80,7 +80,7 @@ final class MetadataSC extends SubComman
return Command.INVALID_ARGUMENT_EXIT_CODE;
}
final Metadata metadata;
- try (NetcdfStore store = new NetcdfStore(new
StorageConnector(files.get(0)))) {
+ try (DataStore store = DataStores.open(files.get(0))) {
metadata = store.getMetadata();
}
/*
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -41,6 +41,11 @@ public final class Modules {
/**
* The {@value} module name.
*/
+ public static final String STORAGE = "org.apache.sis.storage";
+
+ /**
+ * The {@value} module name.
+ */
public static final String NETCDF = "org.apache.sis.storage.netcdf";
/**
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -511,6 +511,11 @@ public final class Errors extends Indexe
public static final int UnknownCommand_1 = 102;
/**
+ * Format of “{0}” is not recognized.
+ */
+ public static final int UnknownFormatFor_1 = 107;
+
+ /**
* Option “{0}” is not recognized.
*/
public static final int UnknownOption_1 = 98;
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Wed Jul 31 13:27:09 2013
@@ -114,6 +114,7 @@ UnexpectedEndOfFile_1 = Unexpe
UnexpectedEndOfString_1 = More characters were expected at the end of
\u201c{0}\u201d.
UnexpectedFileFormat_2 = File \u201c{1}\u201d seems to be encoded in
an other format than {0}.
UnknownCommand_1 = Command \u201c{0}\u201d is not recognized.
+UnknownFormatFor_1 = Format of \u201c{0}\u201d is not recognized.
UnknownOption_1 = Option \u201c{0}\u201d is not recognized.
UnknownType_1 = Type \u2018{0}\u2019 is unknown in this
context.
UnknownTypeForProperty_1 = Type of the \u201c{0}\u201d property is
unknown.
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Wed Jul 31 13:27:09 2013
@@ -103,6 +103,7 @@ UnexpectedEndOfFile_1 = Fin de
UnexpectedEndOfString_1 = D\u2019autres caract\u00e8res \u00e9taient
attendus \u00e0 la fin du texte \u201c{0}\u201d.
UnexpectedFileFormat_2 = Le fichier \u201c{1}\u201d semble \u00eatre
encod\u00e9 dans un autre format que {0}.
UnknownCommand_1 = La commande \u201c{0}\u201d n\u2019est pas
reconnue.
+UnknownFormatFor_1 = Le format de \u201c{0}\u201d n\u2019est pas
reconnu.
UnknownOption_1 = L\u2019option \u201c{0}\u201d n\u2019est pas
reconnue.
UnknownType_1 = Le type \u2018{0}\u2019 n\u2019est pas
reconnu dans ce contexte.
UnknownTypeForProperty_1 = Le type de la propri\u00e9t\u00e9
\u201c{0}\u201d est inconnu.
Modified: sis/branches/JDK7/ide-project/NetBeans/build.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/ide-project/NetBeans/build.xml?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
--- sis/branches/JDK7/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK7/ide-project/NetBeans/build.xml Wed Jul 31 13:27:09 2013
@@ -41,16 +41,33 @@
<!-- Following are classical properties resources files. -->
<copy todir="${build.classes.dir}">
<fileset dir="${project.root}/core/sis-utility/src/main/resources">
- <include name="META-INF/services/*"/>
<include name="**/*.properties"/>
</fileset>
- <fileset dir="${project.root}/core/sis-metadata/src/main/resources">
- <include name="META-INF/services/*"/>
- </fileset>
<fileset
dir="${project.root}/application/sis-console/src/main/resources">
<include name="**/*.properties"/>
</fileset>
</copy>
+
+ <!-- ObjectConverter implementations to be loaded by ServiceLoader. -->
+ <concat
destfile="${build.classes.dir}/META-INF/services/org.apache.sis.util.ObjectConverter"
encoding="UTF-8" fixlastline="yes">
+ <fileset dir="${project.root}">
+ <include
name="*/*/src/main/resources/META-INF/services/org.apache.sis.util.ObjectConverter"/>
+ </fileset>
+ </concat>
+
+ <!-- TypeRegistration implementations to be loaded by ServiceLoader. -->
+ <concat
destfile="${build.classes.dir}/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration"
encoding="UTF-8" fixlastline="yes">
+ <fileset dir="${project.root}">
+ <include
name="*/*/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration"/>
+ </fileset>
+ </concat>
+
+ <!-- DataStoreProvider implementations to be loaded by ServiceLoader. -->
+ <concat
destfile="${build.classes.dir}/META-INF/services/org.apache.sis.storage.DataStoreProvider"
encoding="UTF-8" fixlastline="yes">
+ <fileset dir="${project.root}">
+ <include
name="*/*/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider"/>
+ </fileset>
+ </concat>
</target>
<!--
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=1508849&r1=1508848&r2=1508849&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] Wed Jul 31 13:27:09 2013
@@ -33,6 +33,7 @@ import org.apache.sis.storage.DataStoreP
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.util.logging.WarningListeners;
+import org.apache.sis.util.ThreadSafe;
/**
@@ -49,6 +50,7 @@ import org.apache.sis.util.logging.Warni
*
* @see NetcdfStore
*/
+@ThreadSafe
public class NetcdfStoreProvider extends DataStoreProvider {
/**
* The name of the {@link ucar.nc2.NetcdfFile} class, which is {@value}.
Added:
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider?rev=1508849&view=auto
==============================================================================
---
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
(added)
+++
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -0,0 +1 @@
+org.apache.sis.storage.netcdf.NetcdfStoreProvider
Propchange:
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/storage/sis-netcdf/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1508849&r1=1508848&r2=1508849&view=diff
==============================================================================
---
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] (original)
+++
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -28,6 +28,11 @@ import org.apache.sis.util.logging.Warni
/**
* A storage object which manage a series of features, coverages or sensor
data.
*
+ * {@section Thread safety policy}
+ * This {@code DataStore} base class is thread-safe. However subclasses are
usually not.
+ * Unless otherwise specified by subclasses, users should assume that {@code
DataStore}
+ * instances are not thread-safe.
+ *
* @author Johann Sorel (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
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=1508849&r1=1508848&r2=1508849&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] Wed Jul 31 13:27:09 2013
@@ -16,16 +16,34 @@
*/
package org.apache.sis.storage;
+import org.apache.sis.util.ThreadSafe;
+
/**
* 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.
*
+ * {@section Packaging data stores}
+ * JAR files that provide implementations of this class shall contain an entry
with exactly the following path:
+ *
+ * {@preformat text
+ * META-INF/services/org.apache.sis.storage.DataStoreProvider
+ * }
+ *
+ * The above entry shall contain one line for each {@code DataStoreProvider}
implementation provided in the JAR file,
+ * where each line is the fully qualified name of the implementation class.
+ * See {@link java.util.ServiceLoader} for more general discussion about this
lookup mechanism.
+ *
+ * {@section Thread safety policy}
+ * All {@code DataStoreProvider} implementations shall be thread-safe.
+ * However the {@code DataStore} instances created by the providers do not
need to be thread-safe.
+ *
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
* @version 0.3
* @module
*/
+@ThreadSafe
public abstract class DataStoreProvider {
/**
* Creates a new provider.
Added:
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=1508849&view=auto
==============================================================================
---
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
(added)
+++
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -0,0 +1,116 @@
+/*
+ * 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 java.util.ServiceLoader;
+import org.apache.sis.util.ThreadSafe;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * Creates {@link DataStore} instances for a given storage object by scanning
all providers on the classpath.
+ * Storage objects are typically {@link java.io.File} or {@link
javax.sql.DataSource} instances, but can also
+ * be any other objects documented in the {@link StorageConnector} class.
+ *
+ * {@note This class is package-private for now in order to get more
experience about what could be a good API.
+ * This class may become public in a future SIS version.}
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+@ThreadSafe
+final class DataStoreRegistry {
+ /**
+ * The loader to use for searching for {@link DataStoreProvider}
implementations.
+ * Note that {@code ServiceLoader} are not thread-safe - usage of this
field must
+ * be protected in a synchronized block.
+ */
+ private final ServiceLoader<DataStoreProvider> loader;
+
+ /**
+ * Creates a new registry which will use the current thread
+ * {@linkplain Thread#getContextClassLoader() context class loader}.
+ */
+ public DataStoreRegistry() {
+ loader = ServiceLoader.load(DataStoreProvider.class);
+ }
+
+ /**
+ * Creates a new registry which will use the given class loader.
+ *
+ * @param loader The class loader to use for loading {@link
DataStoreProvider} implementations.
+ */
+ public DataStoreRegistry(final ClassLoader loader) {
+ ArgumentChecks.ensureNonNull("loader", loader);
+ this.loader = ServiceLoader.load(DataStoreProvider.class, loader);
+ }
+
+ /**
+ * Creates a {@link DataStore} for reading the given storage.
+ * The {@code storage} argument can be any of the following types:
+ *
+ * <ul>
+ * <li>A {@link java.nio.file.Path} or a {@link java.io.File} for a file
or a directory.</li>
+ * <li>A {@link java.net.URI} or a {@link java.net.URL} to a distant
resource.</li>
+ * <li>A {@link java.lang.CharSequence} interpreted as a filename or a
URL.</li>
+ * <li>A {@link java.nio.channels.Channel} or a {@link
java.io.DataInput}.</li>
+ * <li>A {@link javax.sql.DataSource} or a {@link java.sql.Connection}
to a JDBC database.</li>
+ * <li>Any other {@code DataStore}-specific object, for example {@link
ucar.nc2.NetcdfFile}.</li>
+ * <li>An existing {@link StorageConnector} instance.</li>
+ * </ul>
+ *
+ * @param storage The input/output object as a URL, file, image input
stream, <i>etc.</i>.
+ * @return The object to use for reading geospatial data from the given
storage.
+ * @throws UnsupportedStorageException if no {@link DataStoreProvider} is
found for a given storage object.
+ * @throws DataStoreException If an error occurred while opening the
storage.
+ */
+ public DataStore open(final Object storage) throws DataStoreException {
+ StorageConnector connector;
+ if (storage instanceof StorageConnector) {
+ connector = (StorageConnector) storage;
+ } else {
+ connector = new StorageConnector(storage);
+ }
+ try {
+ DataStoreProvider provider = null;
+ synchronized (loader) {
+ for (final DataStoreProvider candidate : loader) {
+ final Boolean canOpen = candidate.canOpen(connector);
+ if (canOpen == null) {
+ // TODO: not enough information.
+ } else if (canOpen) {
+ provider = candidate;
+ break;
+ }
+ }
+ }
+ if (provider != null) {
+ final DataStore data = provider.open(connector);
+ connector = null; // For preventing it to be closed.
+ return data;
+ }
+ } finally {
+ if (connector != null && connector != storage) {
+ connector.closeAllExcept(null);
+ }
+ }
+ throw new
UnsupportedStorageException(Errors.format(Errors.Keys.UnknownFormatFor_1,
connector.getStorageName()));
+ }
+}
Propchange:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java?rev=1508849&view=auto
==============================================================================
---
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
(added)
+++
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.util.Static;
+import org.apache.sis.internal.system.Modules;
+import org.apache.sis.internal.system.SystemListener;
+
+
+/**
+ * Creates {@link DataStore} instances from a given storage object.
+ * Storage objects are typically {@link java.io.File} or {@link
javax.sql.DataSource} instances,
+ * but can also be any other objects documented in the {@link
StorageConnector} class.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+public final class DataStores extends Static {
+ /**
+ * The registry to use for searching for {@link DataStoreProvider}
implementations.
+ *
+ * {@section Class loader}
+ * In current implementation, this registry is instantiated when first
needed using the
+ * {@linkplain Thread#getContextClassLoader() context class loader}. This
means that the set of
+ * available formats may depend on the first thread that invoked a {@code
DataStores} method.
+ */
+ private static volatile DataStoreRegistry registry;
+
+ /*
+ * Forces a reload of all providers when the classpath changes. Note that
invoking
+ * ServiceLoader.reload() is not sufficient because the ClassLoader may
also change
+ * in OSGi context.
+ */
+ static {
+ SystemListener.add(new SystemListener(Modules.STORAGE) {
+ @Override protected void classpathChanged() {
+ registry = null;
+ }
+ });
+ }
+
+ /**
+ * Do not allow instantiation of this class.
+ */
+ private DataStores() {
+ }
+
+ /**
+ * Creates a {@link DataStore} for reading the given storage.
+ * The {@code storage} argument can be any of the following types:
+ *
+ * <ul>
+ * <li>A {@link java.nio.file.Path} or a {@link java.io.File} for a file
or a directory.</li>
+ * <li>A {@link java.net.URI} or a {@link java.net.URL} to a distant
resource.</li>
+ * <li>A {@link java.lang.CharSequence} interpreted as a filename or a
URL.</li>
+ * <li>A {@link java.nio.channels.Channel} or a {@link
java.io.DataInput}.</li>
+ * <li>A {@link javax.sql.DataSource} or a {@link java.sql.Connection}
to a JDBC database.</li>
+ * <li>Any other {@code DataStore}-specific object, for example {@link
ucar.nc2.NetcdfFile}.</li>
+ * <li>An existing {@link StorageConnector} instance.</li>
+ * </ul>
+ *
+ * @param storage The input/output object as a URL, file, image input
stream, <i>etc.</i>.
+ * @return The object to use for reading geospatial data from the given
storage.
+ * @throws UnsupportedStorageException if no {@link DataStoreProvider} is
found for a given storage object.
+ * @throws DataStoreException If an error occurred while opening the
storage.
+ */
+ public static DataStore open(final Object storage) throws
DataStoreException {
+ DataStoreRegistry r = registry;
+ if (r == null) {
+ synchronized (DataStores.class) {
+ r = registry;
+ if (r == null) {
+ registry = r = new DataStoreRegistry();
+ }
+ }
+ }
+ return r.open(storage);
+ }
+}
Propchange:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
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=1508849&r1=1508848&r2=1508849&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] Wed Jul 31 13:27:09 2013
@@ -45,7 +45,7 @@ import org.apache.sis.setup.OptionKey;
* {@code StorageConnector} wraps an input {@link Object}, which can be any of
the following types:
*
* <ul>
- * <li>A {@link java.nio.file.Path} or a {@link java.io.File} or file or a
directory in a file system.</li>
+ * <li>A {@link java.nio.file.Path} or a {@link java.io.File} for a file or
a directory.</li>
* <li>A {@link java.net.URI} or a {@link java.net.URL} to a distant
resource.</li>
* <li>A {@link CharSequence} interpreted as a filename or a URL.</li>
* <li>A {@link java.nio.channels.Channel} or a {@link DataInput}.</li>
Added:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java?rev=1508849&view=auto
==============================================================================
---
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java
(added)
+++
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java
[UTF-8] Wed Jul 31 13:27:09 2013
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+
+/**
+ * Thrown when no {@link DataStoreProvider} is found for a given storage
object.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+public class UnsupportedStorageException extends DataStoreException {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = -8754573140979570187L;
+
+ /**
+ * Creates an exception with no cause and no details message.
+ */
+ public UnsupportedStorageException() {
+ super();
+ }
+
+ /**
+ * Creates an exception with the specified details message.
+ *
+ * @param message The detail message.
+ */
+ public UnsupportedStorageException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Creates an exception with the specified cause and no details message.
+ *
+ * @param cause The cause for this exception.
+ */
+ public UnsupportedStorageException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates an exception with the specified details message and cause.
+ *
+ * @param message The detail message.
+ * @param cause The cause for this exception.
+ */
+ public UnsupportedStorageException(final String message, final Throwable
cause) {
+ super(message, cause);
+ }
+}
Propchange:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/UnsupportedStorageException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8