28
28
29
29
import org .apache .commons .logging .Log ;
30
30
import org .apache .commons .logging .LogFactory ;
31
+
31
32
import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
32
33
import org .springframework .core .io .UrlResource ;
33
34
import org .springframework .util .Assert ;
60
61
*/
61
62
public abstract class SpringFactoriesLoader {
62
63
63
- private static final Log logger = LogFactory .getLog (SpringFactoriesLoader .class );
64
-
65
- private static Map <ClassLoader , MultiValueMap <String , String >> cache = new ConcurrentReferenceHashMap <>();
66
-
67
64
/**
68
65
* The location to look for factories.
69
66
* <p>Can be present in multiple JAR files.
70
67
*/
71
68
public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories" ;
72
69
73
70
71
+ private static final Log logger = LogFactory .getLog (SpringFactoriesLoader .class );
72
+
73
+ private static final Map <ClassLoader , MultiValueMap <String , String >> cache = new ConcurrentReferenceHashMap <>();
74
+
75
+
74
76
/**
75
77
* Load and instantiate the factory implementations of the given type from
76
78
* {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader.
77
- * <p>The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}.
79
+ * <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}.
78
80
* <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames}
79
81
* to obtain all registered factory names.
80
82
* @param factoryClass the interface or abstract class representing the factory
@@ -113,19 +115,17 @@ public static <T> List<T> loadFactories(Class<T> factoryClass, ClassLoader class
113
115
*/
114
116
public static List <String > loadFactoryNames (Class <?> factoryClass , ClassLoader classLoader ) {
115
117
String factoryClassName = factoryClass .getName ();
116
- return loadSpringFactories (classLoader ).getOrDefault (factoryClassName ,
117
- Collections .emptyList ());
118
+ return loadSpringFactories (classLoader ).getOrDefault (factoryClassName , Collections .emptyList ());
118
119
}
119
120
120
- private static Map <String , List <String >> loadSpringFactories (
121
- ClassLoader classLoader ) {
121
+ private static Map <String , List <String >> loadSpringFactories (ClassLoader classLoader ) {
122
122
MultiValueMap <String , String > result = cache .get (classLoader );
123
123
if (result != null )
124
124
return result ;
125
125
try {
126
- Enumeration <URL > urls = (classLoader != null
127
- ? classLoader .getResources (FACTORIES_RESOURCE_LOCATION )
128
- : ClassLoader .getSystemResources (FACTORIES_RESOURCE_LOCATION ));
126
+ Enumeration <URL > urls = (classLoader != null ?
127
+ classLoader .getResources (FACTORIES_RESOURCE_LOCATION ) :
128
+ ClassLoader .getSystemResources (FACTORIES_RESOURCE_LOCATION ));
129
129
result = new LinkedMultiValueMap <>();
130
130
while (urls .hasMoreElements ()) {
131
131
URL url = urls .nextElement ();
@@ -141,8 +141,8 @@ private static Map<String, List<String>> loadSpringFactories(
141
141
return result ;
142
142
}
143
143
catch (IOException ex ) {
144
- throw new IllegalArgumentException ("Unable to load factories from location ["
145
- + FACTORIES_RESOURCE_LOCATION + "]" , ex );
144
+ throw new IllegalArgumentException ("Unable to load factories from location [" +
145
+ FACTORIES_RESOURCE_LOCATION + "]" , ex );
146
146
}
147
147
}
148
148
0 commit comments