sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1674801 - /sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
Date Mon, 20 Apr 2015 11:26:58 GMT
Author: desruisseaux
Date: Mon Apr 20 11:26:58 2015
New Revision: 1674801

URL: http://svn.apache.org/r1674801
Log:
Needs to accept non-SIS factory implementations since the port from Geotk is not yet completed.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1674801&r1=1674800&r2=1674801&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Mon Apr 20 11:26:58 2015
@@ -59,7 +59,7 @@ public final class DefaultFactories exte
 
     /**
      * Return the default factory implementing the given interface.
-     * This method returns only Apache SIS implementation of factories, and ignore all other.
+     * This method gives preference to Apache SIS implementation of factories if present.
      * This is a temporary mechanism while we are waiting for a real dependency injection
mechanism.
      *
      * @param  <T>  The interface type.
@@ -69,6 +69,7 @@ public final class DefaultFactories exte
     public static synchronized <T> T forClass(final Class<T> type) {
         T factory = type.cast(FACTORIES.get(type));
         if (factory == null && !FACTORIES.containsKey(type)) {
+            T fallback = null;
             for (final T candidate : ServiceLoader.load(type)) {
                 final Class<?> ct = candidate.getClass();
                 if (ct.getName().startsWith("org.apache.sis.")) {
@@ -76,9 +77,13 @@ public final class DefaultFactories exte
                         throw new ServiceConfigurationError("Found two implementations of
" + type);
                     }
                     factory = candidate;
-                    break;
+                } else if (fallback == null) {
+                    fallback = candidate;
                 }
             }
+            if (factory == null) {
+                factory = fallback;
+            }
             FACTORIES.put(type, factory);
         }
         return factory;



Mime
View raw message