Author: desruisseaux
Date: Fri Feb 23 17:59:08 2018
New Revision: 1825148
URL: http://svn.apache.org/viewvc?rev=1825148&view=rev
Log:
Review tests.
Added:
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/crs.prj
- copied, changed from r1825147,
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/proj.prj
Removed:
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/proj.prj
Modified:
sis/branches/JDK8/ide-project/NetBeans/build.xml
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderStoreProvider.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/WritableStore.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/folder/StoreTest.java
Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Fri Feb 23 17:59:08 2018
@@ -235,6 +235,7 @@
</fileset>
<fileset dir="${project.root}/storage/sis-storage/src/test/resources">
<include name="**/*.txt"/>
+ <include name="**/*.prj"/>
<include name="**/*.xml"/>
</fileset>
<fileset dir="${project.root}/storage/sis-xmlstore/src/test/resources">
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -866,6 +866,25 @@ public class MetadataBuilder {
}
/**
+ * Adds a data and/or metadata identifier. This method performs the same
work than
+ * {@link #addIdentifier(CharSequence, String, Scope)} for situations
where the
+ * identifier instance is already available.
+ *
+ * @param id the identifier, or {@code null} if none.
+ * @param scope whether the date applies to data, to metadata or to both.
+ *
+ * @see #addIdentifier(CharSequence, String, Scope)
+ */
+ public final void addIdentifier(Identifier id, final Scope scope) {
+ ArgumentChecks.ensureNonNull("scope", scope);
+ if (id != null) {
+ id = (Identifier) sharedValues.getOrDefault(id, id);
+ if (scope != Scope.RESOURCE) metadata().setMetadataIdentifier(id);
+ if (scope != Scope.METADATA)
addIfNotPresent(citation().getIdentifiers(), id);
+ }
+ }
+
+ /**
* Adds a resource (data) identifier, a metadata identifier, or both as
they are often the same.
* The identifier is added only if {@code code} is non-null, regardless
other argument values.
* Empty strings (ignoring spaces) are ignored.
@@ -882,6 +901,7 @@ public class MetadataBuilder {
*
* @see #addTitle(CharSequence)
* @see #addTitleOrIdentifier(String, Scope)
+ * @see #addIdentifier(Identifier, Scope)
*/
public final void addIdentifier(final CharSequence authority, String code,
final Scope scope) {
ArgumentChecks.ensureNonNull("scope", scope);
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -27,10 +27,13 @@ import org.apache.sis.util.Static;
import org.apache.sis.storage.FeatureSet;
import org.apache.sis.storage.Resource;
import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStores;
import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.WritableFeatureSet;
+import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.internal.util.Citations;
+import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.Classes;
// Branch-dependent imports
@@ -39,7 +42,7 @@ import org.opengis.feature.Feature;
/**
* Utility methods related to {@link DataStore}s, {@link DataStoreProvider}s
and {@link Resource}s.
- * This is not a commit API; any method in this class may change in any future
Apache SIS version.
+ * This is not a committed API; any method in this class may change in any
future Apache SIS version.
* Some methods may also move in public API if we feel confident enough.
*
* @author Martin Desruisseaux (Geomatys)
@@ -209,6 +212,44 @@ public final class StoreUtilities extend
}
/**
+ * Returns a provider for the given format name.
+ *
+ * @param format name of the format for which to get a provider.
+ * @return first provider found for the given format name.
+ * @throws UnsupportedStorageException if no provider is found for the
specified format.
+ */
+ public static DataStoreProvider providerByFormatName(final String format)
throws UnsupportedStorageException {
+ for (DataStoreProvider provider : DataStores.providers()) {
+ if (format.equalsIgnoreCase(getIdentifier(provider))) {
+ return provider;
+ }
+ }
+ throw new
UnsupportedStorageException(Errors.format(Errors.Keys.UnsupportedFormat_1,
format));
+ }
+
+ /**
+ * Returns whether the given store has write capability.
+ * In case of doubt, this method returns {@code null}.
+ *
+ * @param store class of the store for which to determine if it has
write capability, or {@code null}.
+ * @return whether the data store has write capability, or {@code null} if
it can not be determined.
+ */
+ public static Boolean canWrite(final Class<? extends DataStoreProvider>
store) {
+ if (store != null) {
+ Capabilities caps = store.getAnnotation(Capabilities.class);
+ if (caps != null) {
+ for (Capability c : caps.value()) {
+ if (Capability.WRITE.equals(c)) {
+ return Boolean.TRUE;
+ }
+ }
+ return Boolean.FALSE;
+ }
+ }
+ return null;
+ }
+
+ /**
* Copies all feature from the given source to the given target.
* We use this method as central point where such copy occur, in case we
want to implement
* a more efficient algorithm in some future Apache SIS version. For
example we could copy
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/URIDataStore.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -214,6 +214,8 @@ public abstract class URIDataStore exten
/**
* Creates a storage connector initialized to the location declared in
given parameters.
* This convenience method does not set any other parameters.
+ * In particular, reading (or ignoring) the {@value #CREATE} parameter
is left to callers,
+ * because not all implementations may create data stores with {@link
java.nio.file.StandardOpenOption}.
*
* @param provider the provider for which to create a storage
connector (for error messages).
* @param parameters the parameters to use for creating a storage
connector.
@@ -224,7 +226,7 @@ public abstract class URIDataStore exten
throws IllegalOpenParameterException
{
ParameterNotFoundException cause = null;
- try {
+ if (parameters != null) try {
final Object location =
parameters.parameter(LOCATION).getValue();
if (location != null) {
return new StorageConnector(location);
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderStoreProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderStoreProvider.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderStoreProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/FolderStoreProvider.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -43,6 +43,7 @@ import org.apache.sis.util.logging.Loggi
import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.storage.Resources;
import org.apache.sis.internal.storage.URIDataStore;
+import org.apache.sis.internal.storage.StoreUtilities;
import org.apache.sis.setup.OptionKey;
@@ -179,14 +180,31 @@ public final class FolderStoreProvider e
/**
* Shared implementation of public {@code open(…)} methods.
+ * Note that this method may modify the given {@code options} set for its
own purpose.
*
* @param connector information about the storage (URL, path,
<i>etc</i>).
- * @param format format name, or {@code null} if unspecified.
+ * @param format format name for directory content, or {@code null}
if unspecified.
* @param options whether to create a new directory, overwrite
existing content, <i>etc</i>.
*/
private DataStore open(final StorageConnector connector, final String
format, final EnumSet<StandardOpenOption> options)
throws DataStoreException
{
+ /*
+ * Determine now the provider to use for directory content. We do that
for determining if the component
+ * has write capability. If not, then the WRITE, CREATE and related
options will be ignored. If we can
+ * not determine whether the component store has write capabilities
(i.e. if canWrite(…) returns null),
+ * assume that the answer is "yes".
+ */
+ final DataStoreProvider componentProvider;
+ if (format != null) {
+ componentProvider =
StoreUtilities.providerByFormatName(format.trim());
+ if
(Boolean.FALSE.equals(StoreUtilities.canWrite(componentProvider.getClass()))) {
+ options.clear(); // No write capability.
+ }
+ } else {
+ componentProvider = null;
+ options.clear(); // Can not write if we don't know
the components format.
+ }
Path path = null;
final Store store;
try {
@@ -202,11 +220,10 @@ public final class FolderStoreProvider e
Files.createDirectory(path); //
IOException if the directory already exists.
}
}
- // TODO: check also if @Capabilities.values().contains(WRITE).
if (options.contains(StandardOpenOption.WRITE)) {
- store = new WritableStore(this, connector, format); // May
throw NoSuchFileException.
+ store = new WritableStore(this, connector, componentProvider);
// May throw NoSuchFileException.
} else {
- store = new Store(this, connector, format); // May
throw NoSuchFileException.
+ store = new Store(this, connector, componentProvider);
// May throw NoSuchFileException.
}
/*
* If there is a destructive operation to perform
(TRUNCATE_EXISTING), do it last only
@@ -257,12 +274,11 @@ public final class FolderStoreProvider e
connector.setOption(OptionKey.LOCALE, pg.getValue(LOCALE));
connector.setOption(OptionKey.TIMEZONE, pg.getValue(TIMEZONE));
connector.setOption(OptionKey.ENCODING, pg.getValue(ENCODING));
- final String format = pg.getValue(FORMAT);
- final EnumSet<StandardOpenOption> options =
EnumSet.noneOf(StandardOpenOption.class);
- if (format != null &&
Boolean.TRUE.equals(pg.getValue(URIDataStore.Provider.CREATE_PARAM))) {
- options.add(StandardOpenOption.WRITE);
+ final EnumSet<StandardOpenOption> options =
EnumSet.of(StandardOpenOption.WRITE);
+ if
(Boolean.TRUE.equals(pg.getValue(URIDataStore.Provider.CREATE_PARAM))) {
+ options.add(StandardOpenOption.CREATE);
}
- return open(connector, format, options);
+ return open(connector, pg.getValue(FORMAT), options);
}
/**
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -48,7 +48,6 @@ import org.apache.sis.internal.util.Unmo
import org.apache.sis.internal.storage.MetadataBuilder;
import org.apache.sis.internal.storage.StoreUtilities;
import org.apache.sis.internal.storage.Resources;
-import org.apache.sis.util.resources.Errors;
/**
@@ -130,18 +129,18 @@ class Store extends DataStore implements
/**
* Creates a new folder store from the given file, path or URI.
* The folder store will attempt to open only the files of the given
format, if non-null.
- * If a null format name is specified, then the folder store will attempt
to open any file
+ * If a null format is specified, then the folder store will attempt to
open any file
* found in the directory (this may produce confusing results).
*
* @param provider the factory that created this {@code DataStore}
instance, or {@code null} if unspecified.
* @param connector information about the storage (URL, stream,
<i>etc</i>).
- * @param format name of the format to use for reading or writing the
directory content, or {@code null}.
+ * @param format format to use for reading or writing the directory
content, or {@code null}.
* @throws UnsupportedStorageException if the given format name is unknown.
* @throws DataStoreException if an error occurred while fetching the
directory {@link Path}.
* @throws IOException if an error occurred while using the directory
{@code Path}.
*/
- @SuppressWarnings("ThisEscapedInObjectConstruction") // Okay because
'folders' does not escape.
- Store(final DataStoreProvider provider, final StorageConnector connector,
String format)
+ @SuppressWarnings("ThisEscapedInObjectConstruction") // Okay because
'children' does not escape.
+ Store(final DataStoreProvider provider, final StorageConnector connector,
final DataStoreProvider format)
throws DataStoreException, IOException
{
super(provider, connector);
@@ -151,18 +150,7 @@ class Store extends DataStore implements
encoding = connector.getOption(OptionKey.ENCODING);
children = new ConcurrentHashMap<>();
children.put(location.toRealPath(), this);
- if (format == null) {
- componentProvider = null;
- } else {
- format = format.trim();
- for (DataStoreProvider cp : DataStores.providers()) {
- if (format.equalsIgnoreCase(StoreUtilities.getIdentifier(cp)))
{
- componentProvider = cp;
- return;
- }
- }
- throw new
UnsupportedStorageException(Errors.getResources(super.getLocale()).getString(Errors.Keys.UnsupportedFormat_1,
format));
- }
+ componentProvider = format;
}
/**
@@ -335,12 +323,19 @@ class Store extends DataStore implements
}
/**
+ * Returns the resource bundle to use for error message in exceptions.
+ */
+ final Resources messages() {
+ return Resources.forLocale(getLocale());
+ }
+
+ /**
* Returns a localized string for the given key and value.
*
* @param key one of the {@link Resources.Keys} constants ending with
{@code _1} suffix.
*/
final String message(final short key, final Object value) {
- return Resources.forLocale(getLocale()).getString(key, value);
+ return messages().getString(key, value);
}
/**
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/WritableStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/WritableStore.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/WritableStore.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/WritableStore.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -38,6 +38,7 @@ import org.apache.sis.internal.storage.R
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.internal.storage.ResourceOnFileSystem;
import org.apache.sis.internal.storage.URIDataStore;
+import org.apache.sis.storage.ReadOnlyStorageException;
/**
@@ -53,10 +54,18 @@ import org.apache.sis.internal.storage.U
*/
final class WritableStore extends Store implements WritableAggregate {
/**
+ * {@code false} if this data store is capable to write {@link FeatureSet}.
+ * We currently have no easy way to determine that from the provider only,
+ * so this flag may be set after the first attempt to add a new resource.
+ */
+ private boolean isReadOnly;
+
+ /**
* Creates a new folder store from the given file, path or URI.
* Contrarily to the {@link Store} parent class, the {@code format} is
mandatory for writable stores.
+ * This is not verified by this constructor; it should be verified by
{@link FolderStoreProvider} instead.
*/
- WritableStore(final DataStoreProvider provider, final StorageConnector
connector, final String format)
+ WritableStore(DataStoreProvider provider, StorageConnector connector,
DataStoreProvider format)
throws DataStoreException, IOException
{
super(provider, connector, format);
@@ -64,7 +73,7 @@ final class WritableStore extends Store
/**
* Create a new file for the given resource.
- * This implementation uses the provider specified by the format name
given at creation time.
+ * This implementation uses the provider specified at creation time.
*/
@Override
public synchronized Resource add(final Resource resource) throws
DataStoreException {
@@ -75,6 +84,13 @@ final class WritableStore extends Store
}));
}
/*
+ * If we determined in a previous method invocation that the given
provider can not write feature set,
+ * we are better to fail now instead than polluting the directory with
files that we can not use.
+ */
+ if (isReadOnly) {
+ throw new
ReadOnlyStorageException(messages().getString(Resources.Keys.StoreIsReadOnly));
+ }
+ /*
* Infer a filename from the resource identifier, if one can be found.
* A suffix is added to the filename if available (some formats may
have no suffix at all).
*/
@@ -116,33 +132,18 @@ final class WritableStore extends Store
}
/*
* If the data store is not a WritableFeatureSet, current
implementation can not use it.
- * Delete the file that the store may have created.
- *
- * TODO: we should set a flag for blocking next attempts to
add a resources, since they are likely
- * to fail as well. Maybe we should not delete any files
since we are not sure to delete the
- * right ones. For example store.getComponentPaths() may
return a path outside the directory
- * managed by this folder store.
+ * Files created by this failed attempt may remain; instead of
trying to delete them with
+ * uncertain consequences, we set a flag for avoiding to
pollute further the directory.
*/
- final DataStoreException ex = new
DataStoreException(Resources.format(
- Resources.Keys.NotAWritableFeatureSet_1,
store.getDisplayName()));
- store.close();
- try {
- if (store instanceof Store) {
- deleteRecursively(((Store) store).location, true);
- } else if (store instanceof ResourceOnFileSystem) {
- for (Path c : ((ResourceOnFileSystem)
store).getComponentFiles()) {
- Files.delete(c);
- }
- }
- } catch (IOException e) {
- ex.addSuppressed(e);
- }
+ isReadOnly = true;
children.remove(path, store);
- throw ex;
+ final String name = store.getDisplayName();
+ store.close();
+ throw new
DataStoreException(message(Resources.Keys.NotAWritableFeatureSet_1, name));
}
store.close();
}
- throw new
DataStoreException(Resources.format(Resources.Keys.ResourceAlreadyExists_1,
path));
+ throw new
DataStoreException(message(Resources.Keys.ResourceAlreadyExists_1, path));
}
/**
@@ -165,8 +166,15 @@ final class WritableStore extends Store
}
} else if (resource instanceof ResourceOnFileSystem) {
final Path[] componentPaths = ((ResourceOnFileSystem)
resource).getComponentFiles().clone();
- for (final Path root : componentPaths) {
- if (Files.isSameFile(root.getParent(), location)) {
+ for (Path root : componentPaths) {
+ root = root.getParent();
+ if (Files.isSameFile(root, location)) {
+ /*
+ * If we enter in this block, we have determined that
at least one file is located in the
+ * directory managed by this store - NOT in a
subdirectory since they could be managed by
+ * different folder stores. We assume that this root
file is the "main" file. Other files
+ * could be in subdirectories, but we need to verify -
we do not delete files outside.
+ */
for (final Path path : componentPaths) {
if (path.startsWith(root)) {
Files.delete(path);
@@ -179,10 +187,10 @@ final class WritableStore extends Store
}
}
} catch (IOException e) {
- throw new
DataStoreException(Resources.format(Resources.Keys.CanNotRemoveResource_2,
+ throw new
DataStoreException(messages().getString(Resources.Keys.CanNotRemoveResource_2,
getDisplayName(), ((DataStore)
resource).getDisplayName()), e);
}
- throw new
DataStoreException(Resources.format(Resources.Keys.NoSuchResourceInAggregate_2,
+ throw new
DataStoreException(messages().getString(Resources.Keys.NoSuchResourceInAggregate_2,
getDisplayName(), StoreUtilities.getLabel(resource)));
}
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -19,7 +19,6 @@ package org.apache.sis.internal.storage.
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
-import java.util.logging.LogRecord;
import java.io.Reader;
import java.io.IOException;
import java.text.ParsePosition;
@@ -27,13 +26,13 @@ import java.text.ParseException;
import org.opengis.metadata.Metadata;
import org.opengis.referencing.ReferenceSystem;
import org.apache.sis.internal.storage.Resources;
-import org.apache.sis.internal.system.Loggers;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.DataStoreContentException;
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.internal.storage.MetadataBuilder;
import org.apache.sis.internal.storage.URIDataStore;
+import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.setup.OptionKey;
import org.apache.sis.util.CharSequences;
@@ -43,7 +42,7 @@ import org.apache.sis.util.CharSequences
* A data store which creates data objects from a WKT definition.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
* @since 0.7
* @module
*/
@@ -144,19 +143,10 @@ final class Store extends URIDataStore {
}
/**
- * Reports a warning.
- */
- private void log(final LogRecord record) {
- record.setSourceClassName(Store.class.getName());
- record.setSourceMethodName("getMetadata"); // Public facade
for the parse() method.
- record.setLoggerName(Loggers.WKT);
- listeners.warning(record);
- }
-
- /**
* Returns the metadata associated to the parsed objects, or {@code null}
if none.
* The current implementation retains only instances of {@link
ReferenceSystem}
- * and ignore other objects.
+ * and ignore other objects. The identification information {@code
Citation} is
+ * set to the CRS name and identifier, unless there is ambiguity.
*
* @return the metadata associated to the parsed object, or {@code null}
if none.
* @throws DataStoreException if an error occurred during the parsing
process.
@@ -166,13 +156,22 @@ final class Store extends URIDataStore {
if (metadata == null) {
parse();
final MetadataBuilder builder = new MetadataBuilder();
- builder.addTitle(getDisplayName());
+ String name = null;
+ int count = 0;
for (final Object object : objects) {
if (object instanceof ReferenceSystem) {
- builder.addReferenceSystem((ReferenceSystem) object);
+ final ReferenceSystem rs = (ReferenceSystem) object;
+ builder.addReferenceSystem(rs);
+ name = IdentifiedObjects.getName(rs, null);
+ count++;
+ builder.addIdentifier(IdentifiedObjects.getIdentifier(rs,
null), MetadataBuilder.Scope.RESOURCE);
}
}
- addTitleOrIdentifier(builder);
+ if (count == 1) { // Set the citation title only
if non-ambiguous.
+ builder.addTitle(name);
+ } else {
+ addTitleOrIdentifier(builder);
+ }
metadata = builder.build(true);
}
return metadata;
Modified:
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/folder/StoreTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/folder/StoreTest.java?rev=1825148&r1=1825147&r2=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/folder/StoreTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/folder/StoreTest.java
[UTF-8] Fri Feb 23 17:59:08 2018
@@ -24,9 +24,9 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
+import org.opengis.parameter.ParameterValueGroup;
import org.opengis.metadata.identification.Identification;
import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.parameter.Parameters;
import org.apache.sis.storage.Aggregate;
import org.apache.sis.storage.Resource;
import org.apache.sis.storage.DataStoreException;
@@ -69,9 +69,9 @@ public final strictfp class StoreTest ex
*/
@Test
public void testComponents() throws URISyntaxException,
DataStoreException, IOException {
- final Set<String> identifiers = new HashSet<>(Arrays.asList("proj",
"Sample 1", "Sample 2", "Sample 3", "data4"));
+ final Set<String> identifiers = new
HashSet<>(Arrays.asList("EPSG:4326", "Sample 1", "Sample 2", "Sample 3",
"data4"));
try (Store store = new Store(null, new
StorageConnector(testDirectory()), null)) {
- assertEquals("Expected three data stores.", 4,
store.components().size());
+ assertEquals("Wrong number of data stores.", 4,
store.components().size());
verifyContent(store, identifiers);
}
if (!identifiers.isEmpty()) {
@@ -80,7 +80,7 @@ public final strictfp class StoreTest ex
}
/**
- * Verify that the restricting provider parameter is used.
+ * Verifies that specifying a format effectively restricts the number of
resources to be found.
*
* @throws URISyntaxException if the URL to test data can not be converted
to a path of the file system.
* @throws DataStoreException if an error occurred while reading the
resources.
@@ -89,11 +89,11 @@ public final strictfp class StoreTest ex
@Test
public void testSearchProviderParameter() throws URISyntaxException,
DataStoreException, IOException {
final Set<String> identifiers = new HashSet<>(Arrays.asList("Sample
1", "Sample 2", "Sample 3", "data4"));
- final Parameters params =
Parameters.castOrWrap(FolderStoreProvider.PARAMETERS.createValue());
+ final ParameterValueGroup params =
FolderStoreProvider.PARAMETERS.createValue();
params.parameter("location").setValue(testDirectory());
params.parameter("format").setValue("XML");
try (Store store = (Store) FolderStoreProvider.INSTANCE.open(params)) {
- assertEquals("Expected three data stores.", 3,
store.components().size());
+ assertEquals("Expected one less data store.", 3,
store.components().size());
verifyContent(store, identifiers);
}
if (!identifiers.isEmpty()) {
Copied:
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/crs.prj
(from r1825147,
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/proj.prj)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/crs.prj?p2=sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/crs.prj&p1=sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/proj.prj&r1=1825147&r2=1825148&rev=1825148&view=diff
==============================================================================
---
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/proj.prj
(original)
+++
sis/branches/JDK8/storage/sis-storage/src/test/resources/org/apache/sis/internal/storage/folder/test-data/crs.prj
Fri Feb 23 17:59:08 2018
@@ -1 +1,8 @@
-GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]]
\ No newline at end of file
+GeodeticCRS["WGS 84",
+ DATUM["World Geodetic System 1984",
+ ELLIPSOID["WGS 84", 6378137, 298.257223563, UNIT["metre", 1]]],
+ CS[ellipsoidal, 2],
+ AXIS["latitude", north],
+ AXIS["longitude", east],
+ UNIT["degree", 0.01745329252],
+ ID["EPSG",4326]]