Polishing (selective backports from master)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -61,7 +61,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
/**
|
||||
* Specify the maximum time allotted in milliseconds for the shutdown of
|
||||
* any phase (group of SmartLifecycle beans with the same 'phase' value).
|
||||
* The default value is 30 seconds.
|
||||
* <p>The default value is 30 seconds.
|
||||
*/
|
||||
public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase) {
|
||||
this.timeoutPerShutdownPhase = timeoutPerShutdownPhase;
|
||||
@@ -80,13 +80,12 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
// Lifecycle implementation
|
||||
|
||||
/**
|
||||
* Start all registered beans that implement Lifecycle and are
|
||||
* <i>not</i> already running. Any bean that implements SmartLifecycle
|
||||
* will be started within its 'phase', and all phases will be ordered
|
||||
* from lowest to highest value. All beans that do not implement
|
||||
* SmartLifecycle will be started in the default phase 0. A bean
|
||||
* declared as a dependency of another bean will be started before
|
||||
* the dependent bean regardless of the declared phase.
|
||||
* Start all registered beans that implement {@link Lifecycle} and are <i>not</i>
|
||||
* already running. Any bean that implements {@link SmartLifecycle} will be
|
||||
* started within its 'phase', and all phases will be ordered from lowest to
|
||||
* highest value. All beans that do not implement {@link SmartLifecycle} will be
|
||||
* started in the default phase 0. A bean declared as a dependency of another bean
|
||||
* will be started before the dependent bean regardless of the declared phase.
|
||||
*/
|
||||
@Override
|
||||
public void start() {
|
||||
@@ -95,13 +94,12 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop all registered beans that implement Lifecycle and <i>are</i>
|
||||
* currently running. Any bean that implements SmartLifecycle
|
||||
* will be stopped within its 'phase', and all phases will be ordered
|
||||
* from highest to lowest value. All beans that do not implement
|
||||
* SmartLifecycle will be stopped in the default phase 0. A bean
|
||||
* declared as dependent on another bean will be stopped before
|
||||
* the dependency bean regardless of the declared phase.
|
||||
* Stop all registered beans that implement {@link Lifecycle} and <i>are</i>
|
||||
* currently running. Any bean that implements {@link SmartLifecycle} will be
|
||||
* stopped within its 'phase', and all phases will be ordered from highest to
|
||||
* lowest value. All beans that do not implement {@link SmartLifecycle} will be
|
||||
* stopped in the default phase 0. A bean declared as dependent on another bean
|
||||
* will be stopped before the dependency bean regardless of the declared phase.
|
||||
*/
|
||||
@Override
|
||||
public void stop() {
|
||||
@@ -127,7 +125,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
}
|
||||
|
||||
|
||||
// internal helpers
|
||||
// Internal helpers
|
||||
|
||||
private void startBeans(boolean autoStartupOnly) {
|
||||
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -21,7 +21,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
@@ -47,7 +47,7 @@ public class DateFormatter implements Formatter<Date> {
|
||||
private static final Map<ISO, String> ISO_PATTERNS;
|
||||
|
||||
static {
|
||||
Map<ISO, String> formats = new HashMap<ISO, String>(4);
|
||||
Map<ISO, String> formats = new EnumMap<ISO, String>(ISO.class);
|
||||
formats.put(ISO.DATE, "yyyy-MM-dd");
|
||||
formats.put(ISO.TIME, "HH:mm:ss.SSSZ");
|
||||
formats.put(ISO.DATE_TIME, "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.format.datetime.joda;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
@@ -73,7 +73,7 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
|
||||
/**
|
||||
* User defined formatters.
|
||||
*/
|
||||
private final Map<Type, DateTimeFormatter> formatters = new HashMap<Type, DateTimeFormatter>();
|
||||
private final Map<Type, DateTimeFormatter> formatters = new EnumMap<Type, DateTimeFormatter>(Type.class);
|
||||
|
||||
/**
|
||||
* Factories used when specific formatters have not been specified.
|
||||
@@ -82,7 +82,7 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
|
||||
|
||||
|
||||
public JodaTimeFormatterRegistrar() {
|
||||
this.factories = new HashMap<Type, DateTimeFormatterFactory>();
|
||||
this.factories = new EnumMap<Type, DateTimeFormatterFactory>(Type.class);
|
||||
for (Type type : Type.values()) {
|
||||
this.factories.put(type, new DateTimeFormatterFactory());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -34,6 +34,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.jmx.MBeanServerNotFoundException;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -68,8 +69,7 @@ public abstract class JmxUtils {
|
||||
* {@code MBeanServer} can be found. Logs a warning if more than one
|
||||
* {@code MBeanServer} found, returning the first one from the list.
|
||||
* @return the {@code MBeanServer} if found
|
||||
* @throws org.springframework.jmx.MBeanServerNotFoundException
|
||||
* if no {@code MBeanServer} could be found
|
||||
* @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found
|
||||
* @see javax.management.MBeanServerFactory#findMBeanServer
|
||||
*/
|
||||
public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException {
|
||||
@@ -84,8 +84,7 @@ public abstract class JmxUtils {
|
||||
* If this parameter is {@code null}, all registered MBeanServers are considered.
|
||||
* If the empty String is given, the platform MBeanServer will be returned.
|
||||
* @return the {@code MBeanServer} if found
|
||||
* @throws org.springframework.jmx.MBeanServerNotFoundException
|
||||
* if no {@code MBeanServer} could be found
|
||||
* @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found
|
||||
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
|
||||
*/
|
||||
public static MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException {
|
||||
@@ -94,7 +93,7 @@ public abstract class JmxUtils {
|
||||
// null means any registered server, but "" specifically means the platform server
|
||||
if (!"".equals(agentId)) {
|
||||
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId);
|
||||
if (servers != null && servers.size() > 0) {
|
||||
if (!CollectionUtils.isEmpty(servers)) {
|
||||
// Check to see if an MBeanServer is registered.
|
||||
if (servers.size() > 1 && logger.isWarnEnabled()) {
|
||||
logger.warn("Found more than one MBeanServer instance" +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -80,8 +80,7 @@ public interface BindingResult extends Errors {
|
||||
* Extract the raw field value for the given field.
|
||||
* Typically used for comparison purposes.
|
||||
* @param field the field to check
|
||||
* @return the current value of the field in its raw form,
|
||||
* or {@code null} if not known
|
||||
* @return the current value of the field in its raw form, or {@code null} if not known
|
||||
*/
|
||||
Object getRawFieldValue(String field);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -562,9 +562,10 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
|
||||
private void assertValidators(Validator... validators) {
|
||||
Assert.notNull(validators, "Validators required");
|
||||
Object target = getTarget();
|
||||
for (Validator validator : validators) {
|
||||
if (validator != null && (getTarget() != null && !validator.supports(getTarget().getClass()))) {
|
||||
throw new IllegalStateException("Invalid target for Validator [" + validator + "]: " + getTarget());
|
||||
if (validator != null && (target != null && !validator.supports(target.getClass()))) {
|
||||
throw new IllegalStateException("Invalid target for Validator [" + validator + "]: " + target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -58,9 +58,9 @@ public class DefaultBindingErrorProcessor implements BindingErrorProcessor {
|
||||
String fixedField = bindingResult.getNestedPath() + missingField;
|
||||
String[] codes = bindingResult.resolveMessageCodes(MISSING_FIELD_ERROR_CODE, missingField);
|
||||
Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), fixedField);
|
||||
bindingResult.addError(new FieldError(
|
||||
bindingResult.getObjectName(), fixedField, "", true,
|
||||
codes, arguments, "Field '" + fixedField + "' is required"));
|
||||
FieldError error = new FieldError(bindingResult.getObjectName(), fixedField, "", true,
|
||||
codes, arguments, "Field '" + fixedField + "' is required");
|
||||
bindingResult.addError(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,12 +70,12 @@ public class DefaultBindingErrorProcessor implements BindingErrorProcessor {
|
||||
String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
|
||||
Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
|
||||
Object rejectedValue = ex.getValue();
|
||||
if (rejectedValue != null && rejectedValue.getClass().isArray()) {
|
||||
if (ObjectUtils.isArray(rejectedValue)) {
|
||||
rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
|
||||
}
|
||||
bindingResult.addError(new FieldError(
|
||||
bindingResult.getObjectName(), field, rejectedValue, true,
|
||||
codes, arguments, ex.getLocalizedMessage()));
|
||||
FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true,
|
||||
codes, arguments, ex.getLocalizedMessage());
|
||||
bindingResult.addError(error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -96,12 +96,6 @@ public class FieldError extends ObjectError {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Field error in object '" + getObjectName() + "' on field '" + this.field +
|
||||
"': rejected value [" + this.rejectedValue + "]; " + resolvableToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
@@ -125,4 +119,11 @@ public class FieldError extends ObjectError {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Field error in object '" + getObjectName() + "' on field '" + this.field +
|
||||
"': rejected value [" + ObjectUtils.nullSafeToString(this.rejectedValue) + "]; " +
|
||||
resolvableToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -27,8 +27,8 @@ package org.springframework.validation;
|
||||
public interface MessageCodeFormatter {
|
||||
|
||||
/**
|
||||
* Build and return a message code consisting of the given fields, usually delimited
|
||||
* by {@link DefaultMessageCodesResolver#CODE_SEPARATOR}.
|
||||
* Build and return a message code consisting of the given fields,
|
||||
* usually delimited by {@link DefaultMessageCodesResolver#CODE_SEPARATOR}.
|
||||
* @param errorCode e.g.: "typeMismatch"
|
||||
* @param objectName e.g.: "user"
|
||||
* @param field e.g. "age"
|
||||
@@ -36,4 +36,5 @@ public interface MessageCodeFormatter {
|
||||
* @see DefaultMessageCodesResolver.Format
|
||||
*/
|
||||
String format(String errorCode, String objectName, String field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -68,11 +68,6 @@ public class ObjectError extends DefaultMessageSourceResolvable {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Error in object '" + this.objectName + "': " + resolvableToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
@@ -90,4 +85,9 @@ public class ObjectError extends DefaultMessageSourceResolvable {
|
||||
return super.hashCode() * 29 + getObjectName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Error in object '" + this.objectName + "': " + resolvableToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user