Author: jsorel
Date: Mon Feb 19 09:35:56 2018
New Revision: 1824726
URL: http://svn.apache.org/viewvc?rev=1824726&view=rev
Log:
DataStore : add method to find compatible datastore providers for a given input
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java?rev=1824726&r1=1824725&r2=1824726&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
[UTF-8] Mon Feb 19 09:35:56 2018
@@ -16,7 +16,9 @@
*/
package org.apache.sis.storage;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import org.apache.sis.util.Static;
import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.system.SystemListener;
@@ -28,7 +30,8 @@ import org.apache.sis.internal.system.Sy
* but can also be any other objects documented in the {@link
StorageConnector} class.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
* @since 0.4
* @module
*/
@@ -91,6 +94,35 @@ public final class DataStores extends St
}
/**
+ * Returns the list of data store providers capable of opening the given
input.
+ * Any provider causing an exception while probing the input is considered
+ * as unsupported.
+ *
+ * @param input data input, usually a StorageConnector, Path or URI to
test.
+ * @return descriptions of compatible data stores.
+ *
+ * @since 1.0
+ */
+ public static Collection<DataStoreProvider> providers(Object input) {
+ final StorageConnector connector = (input instanceof StorageConnector)
?
+ (StorageConnector) input : new StorageConnector(input);
+
+ final List<DataStoreProvider> providers = new ArrayList<>();
+ for (DataStoreProvider provider : registry().providers()) {
+ try {
+ final ProbeResult result = provider.probeContent(connector);
+ if (result.isSupported()) {
+ providers.add(provider);
+ }
+ } catch (DataStoreException ex) {
+ // could be caused for multiple reasons, we assume it does not
+ // support the given input.
+ }
+ }
+ return providers;
+ }
+
+ /**
* Returns the MIME type of the storage file format, or {@code null} if
unknown or not applicable.
*
* @param storage the input/output object as a URL, file, image input
stream, <i>etc.</i>.