Author: jsorel
Date: Tue Feb 20 10:42:19 2018
New Revision: 1824845

URL: http://svn.apache.org/viewvc?rev=1824845&view=rev
Log:
DataStore : improve findResource DataStore method to handle namespace and not 
only the code

Modified:
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1824845&r1=1824844&r2=1824845&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
 [UTF-8] Tue Feb 20 10:42:19 2018
@@ -16,10 +16,12 @@
  */
 package org.apache.sis.storage;
 
+import java.util.Collection;
 import java.util.Locale;
 import java.util.Map;
 import java.util.IdentityHashMap;
 import java.util.NoSuchElementException;
+import org.apache.sis.internal.metadata.NameToIdentifier;
 import org.opengis.metadata.Metadata;
 import org.opengis.metadata.identification.Identification;
 import org.opengis.parameter.ParameterValueGroup;
@@ -28,7 +30,9 @@ import org.apache.sis.util.ArgumentCheck
 import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.util.logging.WarningListeners;
 import org.apache.sis.internal.storage.Resources;
-import org.apache.sis.internal.util.Citations;
+import static org.apache.sis.internal.util.Citations.titleMatches;
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.citation.Citation;
 
 
 /**
@@ -308,7 +312,7 @@ public abstract class DataStore implemen
             if (metadata != null) {
                 for (final Identification identification : 
metadata.getIdentificationInfo()) {
                     if (identification != null) {                              
                     // Paranoiac check.
-                        if 
(Citations.identifierMatches(identification.getCitation(), null, identifier)) {
+                        if (identifierMatches(identification.getCitation(), 
identifier)) {
                             return candidate;
                         }
                     }
@@ -334,6 +338,26 @@ public abstract class DataStore implemen
     }
 
     /**
+     * Search a citation title and identifiers for a possible matches against
+     * an identifier.
+     *
+     * @param citation   identification citation to compare.
+     * @param identifier identifier of the resource to compare.
+     * @return true if identifiers matches
+     */
+    private static boolean identifierMatches(final Citation citation, final 
String identifier) {
+        if (citation != null && identifier != null) {
+            final Collection<? extends Identifier> identifiers = 
citation.getIdentifiers();
+            if (identifiers == null || identifiers.isEmpty()) {
+                return titleMatches(citation, identifier);
+            } else {
+                return 
NameToIdentifier.isHeuristicMatchForIdentifier(identifiers, identifier);
+            }
+        }
+        return false;
+    }
+
+    /**
      * Adds a listener to be notified when a warning occurred while reading 
from or writing to the storage.
      * When a warning occurs, there is a choice:
      *


Reply via email to