Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,7 @@ public class Problem {
|
||||
|
||||
/**
|
||||
* Create a new instance of the {@link Problem} class.
|
||||
* @param message a message detailing the problem
|
||||
* @param message a message detailing the problem
|
||||
* @param location the location within a bean configuration source that triggered the error
|
||||
*/
|
||||
public Problem(String message, Location location) {
|
||||
@@ -51,7 +51,7 @@ public class Problem {
|
||||
|
||||
/**
|
||||
* Create a new instance of the {@link Problem} class.
|
||||
* @param message a message detailing the problem
|
||||
* @param message a message detailing the problem
|
||||
* @param parseState the {@link ParseState} at the time of the error
|
||||
* @param location the location within a bean configuration source that triggered the error
|
||||
*/
|
||||
@@ -61,8 +61,8 @@ public class Problem {
|
||||
|
||||
/**
|
||||
* Create a new instance of the {@link Problem} class.
|
||||
* @param message a message detailing the problem
|
||||
* @param rootCause the underlying expection that caused the error (may be {@code null})
|
||||
* @param message a message detailing the problem
|
||||
* @param rootCause the underlying exception that caused the error (may be {@code null})
|
||||
* @param parseState the {@link ParseState} at the time of the error
|
||||
* @param location the location within a bean configuration source that triggered the error
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ public class Problem {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying expection that caused the error (may be {@code null}).
|
||||
* Get the underlying exception that caused the error (may be {@code null}).
|
||||
*/
|
||||
public Throwable getRootCause() {
|
||||
return this.rootCause;
|
||||
|
||||
@@ -125,8 +125,10 @@ public abstract class AbstractResource implements Resource {
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns {@link Channels#newChannel(InputStream)} with the result of
|
||||
* {@link #getInputStream()}.
|
||||
* This implementation returns {@link Channels#newChannel(InputStream)}
|
||||
* with the result of {@link #getInputStream()}.
|
||||
* <p>This is the same as in {@link Resource}'s corresponding default method
|
||||
* but mirrored here for efficient JVM-level dispatching in a class hierarchy.
|
||||
*/
|
||||
@Override
|
||||
public ReadableByteChannel readableChannel() throws IOException {
|
||||
@@ -138,7 +140,6 @@ public abstract class AbstractResource implements Resource {
|
||||
* content length. Subclasses will almost always be able to provide
|
||||
* a more optimal version of this, e.g. checking a File length.
|
||||
* @see #getInputStream()
|
||||
* @throws IllegalStateException if {@link #getInputStream()} returns null.
|
||||
*/
|
||||
@Override
|
||||
public long contentLength() throws IOException {
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -60,10 +61,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public abstract class SpringFactoriesLoader {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
|
||||
|
||||
private static Map<ClassLoader, MultiValueMap<String, String>> cache = new ConcurrentReferenceHashMap<>();
|
||||
|
||||
/**
|
||||
* The location to look for factories.
|
||||
* <p>Can be present in multiple JAR files.
|
||||
@@ -71,10 +68,15 @@ public abstract class SpringFactoriesLoader {
|
||||
public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories";
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
|
||||
|
||||
private static final Map<ClassLoader, MultiValueMap<String, String>> cache = new ConcurrentReferenceHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Load and instantiate the factory implementations of the given type from
|
||||
* {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader.
|
||||
* <p>The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}.
|
||||
* <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}.
|
||||
* <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames}
|
||||
* to obtain all registered factory names.
|
||||
* @param factoryClass the interface or abstract class representing the factory
|
||||
@@ -113,19 +115,17 @@ public abstract class SpringFactoriesLoader {
|
||||
*/
|
||||
public static List<String> loadFactoryNames(Class<?> factoryClass, ClassLoader classLoader) {
|
||||
String factoryClassName = factoryClass.getName();
|
||||
return loadSpringFactories(classLoader).getOrDefault(factoryClassName,
|
||||
Collections.emptyList());
|
||||
return loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList());
|
||||
}
|
||||
|
||||
private static Map<String, List<String>> loadSpringFactories(
|
||||
ClassLoader classLoader) {
|
||||
private static Map<String, List<String>> loadSpringFactories(ClassLoader classLoader) {
|
||||
MultiValueMap<String, String> result = cache.get(classLoader);
|
||||
if (result != null)
|
||||
return result;
|
||||
try {
|
||||
Enumeration<URL> urls = (classLoader != null
|
||||
? classLoader.getResources(FACTORIES_RESOURCE_LOCATION)
|
||||
: ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
|
||||
Enumeration<URL> urls = (classLoader != null ?
|
||||
classLoader.getResources(FACTORIES_RESOURCE_LOCATION) :
|
||||
ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
|
||||
result = new LinkedMultiValueMap<>();
|
||||
while (urls.hasMoreElements()) {
|
||||
URL url = urls.nextElement();
|
||||
@@ -141,8 +141,8 @@ public abstract class SpringFactoriesLoader {
|
||||
return result;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalArgumentException("Unable to load factories from location ["
|
||||
+ FACTORIES_RESOURCE_LOCATION + "]", ex);
|
||||
throw new IllegalArgumentException("Unable to load factories from location [" +
|
||||
FACTORIES_RESOURCE_LOCATION + "]", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user