Polishing

This commit is contained in:
Juergen Hoeller 2019-06-11 23:50:29 +02:00
parent 22aba8bf60
commit 33b5bc2aae
8 changed files with 60 additions and 54 deletions

View File

@ -281,6 +281,40 @@ class BeanDefinitionValueResolver {
return value.resolveTargetType(this.beanFactory.getBeanClassLoader()); return value.resolveTargetType(this.beanFactory.getBeanClassLoader());
} }
/**
* Resolve a reference to another bean in the factory.
*/
@Nullable
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
try {
Object bean;
String refName = ref.getBeanName();
refName = String.valueOf(doEvaluate(refName));
if (ref.isToParent()) {
if (this.beanFactory.getParentBeanFactory() == null) {
throw new BeanCreationException(
this.beanDefinition.getResourceDescription(), this.beanName,
"Can't resolve reference to bean '" + refName +
"' in parent factory: no parent factory available");
}
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
}
else {
bean = this.beanFactory.getBean(refName);
this.beanFactory.registerDependentBean(refName, this.beanName);
}
if (bean instanceof NullBean) {
bean = null;
}
return bean;
}
catch (BeansException ex) {
throw new BeanCreationException(
this.beanDefinition.getResourceDescription(), this.beanName,
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
}
}
/** /**
* Resolve an inner bean definition. * Resolve an inner bean definition.
* @param argName the name of the argument that the inner bean is defined for * @param argName the name of the argument that the inner bean is defined for
@ -345,40 +379,6 @@ class BeanDefinitionValueResolver {
return actualInnerBeanName; return actualInnerBeanName;
} }
/**
* Resolve a reference to another bean in the factory.
*/
@Nullable
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
try {
Object bean;
String refName = ref.getBeanName();
refName = String.valueOf(doEvaluate(refName));
if (ref.isToParent()) {
if (this.beanFactory.getParentBeanFactory() == null) {
throw new BeanCreationException(
this.beanDefinition.getResourceDescription(), this.beanName,
"Can't resolve reference to bean '" + refName +
"' in parent factory: no parent factory available");
}
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
}
else {
bean = this.beanFactory.getBean(refName);
this.beanFactory.registerDependentBean(refName, this.beanName);
}
if (bean instanceof NullBean) {
bean = null;
}
return bean;
}
catch (BeansException ex) {
throw new BeanCreationException(
this.beanDefinition.getResourceDescription(), this.beanName,
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
}
}
/** /**
* For each element in the managed array, resolve reference if necessary. * For each element in the managed array, resolve reference if necessary.
*/ */

View File

@ -130,8 +130,8 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
@Override @Override
public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) { public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {
ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event)); ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));
for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) {
Executor executor = getTaskExecutor(); Executor executor = getTaskExecutor();
for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {
if (executor != null) { if (executor != null) {
executor.execute(() -> invokeListener(listener, event)); executor.execute(() -> invokeListener(listener, event));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -658,6 +658,9 @@ public class MBeanClientInterceptor
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof MethodCacheKey)) {
return false;
}
MethodCacheKey otherKey = (MethodCacheKey) other; MethodCacheKey otherKey = (MethodCacheKey) other;
return (this.name.equals(otherKey.name) && Arrays.equals(this.parameterTypes, otherKey.parameterTypes)); return (this.name.equals(otherKey.name) && Arrays.equals(this.parameterTypes, otherKey.parameterTypes));
} }

View File

@ -35,7 +35,7 @@ final class IntegerToEnumConverterFactory implements ConverterFactory<Integer, E
} }
private class IntegerToEnum<T extends Enum> implements Converter<Integer, T> { private static class IntegerToEnum<T extends Enum> implements Converter<Integer, T> {
private final Class<T> enumType; private final Class<T> enumType;

View File

@ -35,7 +35,7 @@ final class StringToEnumConverterFactory implements ConverterFactory<String, Enu
} }
private class StringToEnum<T extends Enum> implements Converter<String, T> { private static class StringToEnum<T extends Enum> implements Converter<String, T> {
private final Class<T> enumType; private final Class<T> enumType;

View File

@ -26,8 +26,8 @@ import org.springframework.lang.Nullable;
import org.springframework.util.NumberUtils; import org.springframework.util.NumberUtils;
/** /**
* A simple basic {@link TypeComparator} implementation. * A basic {@link TypeComparator} implementation: supports comparison of
* It supports comparison of Numbers and types implementing Comparable. * {@link Number} types as well as types implementing {@link Comparable}.
* *
* @author Andy Clement * @author Andy Clement
* @author Juergen Hoeller * @author Juergen Hoeller
@ -89,10 +89,10 @@ public class StandardTypeComparator implements TypeComparator {
return Integer.compare(leftNumber.intValue(), rightNumber.intValue()); return Integer.compare(leftNumber.intValue(), rightNumber.intValue());
} }
else if (leftNumber instanceof Short || rightNumber instanceof Short) { else if (leftNumber instanceof Short || rightNumber instanceof Short) {
return leftNumber.shortValue() - rightNumber.shortValue(); return Short.compare(leftNumber.shortValue(), rightNumber.shortValue());
} }
else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { else if (leftNumber instanceof Byte || rightNumber instanceof Byte) {
return leftNumber.byteValue() - rightNumber.byteValue(); return Byte.compare(leftNumber.byteValue(), rightNumber.byteValue());
} }
else { else {
// Unknown Number subtypes -> best guess is double multiplication // Unknown Number subtypes -> best guess is double multiplication

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -522,7 +522,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
public boolean equals(Object other) { public boolean equals(Object other) {
// Effectively checking object equality as well as toString equality. // Effectively checking object equality as well as toString equality.
// On WebSphere MQ, Destination objects do not implement equals... // On WebSphere MQ, Destination objects do not implement equals...
return (this == other || destinationEquals((DestinationCacheKey) other)); return (this == other || (other instanceof DestinationCacheKey &&
destinationEquals((DestinationCacheKey) other)));
} }
@Override @Override
@ -577,6 +578,9 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof ConsumerCacheKey)) {
return false;
}
ConsumerCacheKey otherKey = (ConsumerCacheKey) other; ConsumerCacheKey otherKey = (ConsumerCacheKey) other;
return (destinationEquals(otherKey) && return (destinationEquals(otherKey) &&
ObjectUtils.nullSafeEquals(this.selector, otherKey.selector) && ObjectUtils.nullSafeEquals(this.selector, otherKey.selector) &&

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,6 +38,7 @@ import org.springframework.web.util.pattern.PathPattern;
/** /**
* {@code HandlerMapping} implementation that supports {@link RouterFunction RouterFunctions}. * {@code HandlerMapping} implementation that supports {@link RouterFunction RouterFunctions}.
*
* <p>If no {@link RouterFunction} is provided at * <p>If no {@link RouterFunction} is provided at
* {@linkplain #RouterFunctionMapping(RouterFunction) construction time}, this mapping * {@linkplain #RouterFunctionMapping(RouterFunction) construction time}, this mapping
* will detect all router functions in the application context, and consult them in * will detect all router functions in the application context, and consult them in
@ -56,8 +57,8 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
/** /**
* Create an empty {@code RouterFunctionMapping}. * Create an empty {@code RouterFunctionMapping}.
* <p>If this constructor is used, this mapping will detect all {@link RouterFunction} instances * <p>If this constructor is used, this mapping will detect all
* available in the application context. * {@link RouterFunction} instances available in the application context.
*/ */
public RouterFunctionMapping() { public RouterFunctionMapping() {
} }
@ -154,20 +155,18 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void setAttributes(Map<String, Object> attributes, ServerRequest serverRequest, private void setAttributes(
HandlerFunction<?> handlerFunction) { Map<String, Object> attributes, ServerRequest serverRequest, HandlerFunction<?> handlerFunction) {
attributes.put(RouterFunctions.REQUEST_ATTRIBUTE, serverRequest); attributes.put(RouterFunctions.REQUEST_ATTRIBUTE, serverRequest);
attributes.put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerFunction); attributes.put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerFunction);
PathPattern matchingPattern = PathPattern matchingPattern = (PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
(PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
if (matchingPattern != null) { if (matchingPattern != null) {
attributes.put(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern); attributes.put(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern);
} }
Map<String, String> uriVariables = Map<String, String> uriVariables =
(Map<String, String>) attributes (Map<String, String>) attributes.get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
.get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
if (uriVariables != null) { if (uriVariables != null) {
attributes.put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables); attributes.put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
} }