Browse Source

Polishing

pull/805/head
Juergen Hoeller 11 years ago
parent
commit
3c6f1f8352
  1. 14
      spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java
  2. 2
      spring-context/src/main/java/org/springframework/format/annotation/NumberFormat.java
  3. 10
      spring-core/src/main/java/org/springframework/util/ClassUtils.java
  4. 7
      spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java
  5. 2
      spring-web/src/main/java/org/springframework/web/client/RestTemplate.java
  6. 24
      spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

14
spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java

@ -35,13 +35,13 @@ import java.lang.annotation.Target;
* A date or time may be omitted by specifying the style character '-'. * A date or time may be omitted by specifying the style character '-'.
* *
* <p>For ISO-based formatting, set the {@link #iso} attribute to be the desired {@link ISO} format, * <p>For ISO-based formatting, set the {@link #iso} attribute to be the desired {@link ISO} format,
* such as {@link ISO#DATE}. For custom formatting, set the {@link #pattern} attribute to be the * such as {@link ISO#DATE}. For custom formatting, set the {@link #pattern()} attribute to be the
* DateTime pattern, such as {@code yyyy/MM/dd hh:mm:ss a}. * DateTime pattern, such as {@code yyyy/MM/dd hh:mm:ss a}.
* *
* <p>Each attribute is mutually exclusive, so only set one attribute per annotation instance * <p>Each attribute is mutually exclusive, so only set one attribute per annotation instance
* (the most convenient one for your formatting needs). * (the one most convenient one for your formatting needs).
* When the pattern attribute is specified, it takes precedence over both the style and ISO attribute. * When the pattern attribute is specified, it takes precedence over both the style and ISO attribute.
* When the iso attribute is specified, it takes precedence over the style attribute. * When the {@link #iso} attribute is specified, if takes precedence over the style attribute.
* When no annotation attributes are specified, the default format applied is style-based * When no annotation attributes are specified, the default format applied is style-based
* with a style code of 'SS' (short date, short time). * with a style code of 'SS' (short date, short time).
* *
@ -82,23 +82,23 @@ public @interface DateTimeFormat {
/** /**
* Common ISO date time format patterns. * Common ISO date time format patterns.
*/ */
public enum ISO { enum ISO {
/** /**
* The most common ISO Date Format {@code yyyy-MM-dd}, * The most common ISO Date Format {@code yyyy-MM-dd},
* e.g. 2000-10-31. * e.g. "2000-10-31".
*/ */
DATE, DATE,
/** /**
* The most common ISO Time Format {@code HH:mm:ss.SSSZ}, * The most common ISO Time Format {@code HH:mm:ss.SSSZ},
* e.g. 01:30:00.000-05:00. * e.g. "01:30:00.000-05:00".
*/ */
TIME, TIME,
/** /**
* The most common ISO DateTime Format {@code yyyy-MM-dd'T'HH:mm:ss.SSSZ}, * The most common ISO DateTime Format {@code yyyy-MM-dd'T'HH:mm:ss.SSSZ},
* e.g. 2000-10-31 01:30:00.000-05:00. * e.g. "2000-10-31 01:30:00.000-05:00".
* <p>This is the default if no annotation value is specified. * <p>This is the default if no annotation value is specified.
*/ */
DATE_TIME, DATE_TIME,

2
spring-context/src/main/java/org/springframework/format/annotation/NumberFormat.java

@ -67,7 +67,7 @@ public @interface NumberFormat {
/** /**
* Common number format styles. * Common number format styles.
*/ */
public enum Style { enum Style {
/** /**
* The general-purpose number format for the current locale. * The general-purpose number format for the current locale.

10
spring-core/src/main/java/org/springframework/util/ClassUtils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 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.
@ -352,9 +352,9 @@ public abstract class ClassUtils {
*/ */
public static Class<?> getUserClass(Class<?> clazz) { public static Class<?> getUserClass(Class<?> clazz) {
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
Class<?> superClass = clazz.getSuperclass(); Class<?> superclass = clazz.getSuperclass();
if (superClass != null && !Object.class.equals(superClass)) { if (superclass != null && !Object.class.equals(superclass)) {
return superClass; return superclass;
} }
} }
return clazz; return clazz;
@ -821,8 +821,8 @@ public abstract class ClassUtils {
/** /**
* Return a public static method of a class. * Return a public static method of a class.
* @param methodName the static method name
* @param clazz the class which defines the method * @param clazz the class which defines the method
* @param methodName the static method name
* @param args the parameter types to the method * @param args the parameter types to the method
* @return the static method, or {@code null} if no static method was found * @return the static method, or {@code null} if no static method was found
* @throws IllegalArgumentException if the method name is blank or the clazz is null * @throws IllegalArgumentException if the method name is blank or the clazz is null

7
spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java

@ -97,10 +97,8 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
if (result.getValue() == null && isAutoGrowNullReferences && if (result.getValue() == null && isAutoGrowNullReferences &&
nextChildIs(Indexer.class, PropertyOrFieldReference.class)) { nextChildIs(Indexer.class, PropertyOrFieldReference.class)) {
TypeDescriptor resultDescriptor = result.getTypeDescriptor(); TypeDescriptor resultDescriptor = result.getTypeDescriptor();
// Creating lists and maps
if ((resultDescriptor.getType().equals(List.class) || resultDescriptor.getType().equals(Map.class))) {
// Create a new collection or map ready for the indexer // Create a new collection or map ready for the indexer
if (resultDescriptor.getType().equals(List.class)) { if (List.class.equals(resultDescriptor.getType())) {
try { try {
if (isWritableProperty(this.name, contextObject, evalContext)) { if (isWritableProperty(this.name, contextObject, evalContext)) {
List<?> newList = ArrayList.class.newInstance(); List<?> newList = ArrayList.class.newInstance();
@ -117,7 +115,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING); SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
} }
} }
else { else if (Map.class.equals(resultDescriptor.getType())) {
try { try {
if (isWritableProperty(this.name,contextObject, evalContext)) { if (isWritableProperty(this.name,contextObject, evalContext)) {
Map<?,?> newMap = HashMap.class.newInstance(); Map<?,?> newMap = HashMap.class.newInstance();
@ -134,7 +132,6 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING); SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
} }
} }
}
else { else {
// 'simple' object // 'simple' object
try { try {

2
spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

@ -78,7 +78,7 @@ import org.springframework.web.util.UriTemplate;
* HTTP PATCH, HTTP PUT with response body, etc.). Note however that the underlying HTTP * HTTP PATCH, HTTP PUT with response body, etc.). Note however that the underlying HTTP
* library used must also support the desired combination. * library used must also support the desired combination.
* *
* <p>For each HTTP method there are 3 variants -- two accept a URI template string * <p>For each HTTP method there are three variants: two accept a URI template string
* and URI variables (array or map) while a third accepts a {@link URI}. * and URI variables (array or map) while a third accepts a {@link URI}.
* Note that for URI templates it is assumed encoding is necessary, e.g. * Note that for URI templates it is assumed encoding is necessary, e.g.
* {@code restTemplate.getForObject("http://example.com/hotel list")} becomes * {@code restTemplate.getForObject("http://example.com/hotel list")} becomes

24
spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 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.
@ -53,8 +53,8 @@ import org.springframework.web.util.WebUtils;
* type {@link MultipartFile} in conjunction with Spring's {@link MultipartResolver} * type {@link MultipartFile} in conjunction with Spring's {@link MultipartResolver}
* abstraction, and arguments of type {@code javax.servlet.http.Part} in conjunction * abstraction, and arguments of type {@code javax.servlet.http.Part} in conjunction
* with Servlet 3.0 multipart requests. This resolver can also be created in default * with Servlet 3.0 multipart requests. This resolver can also be created in default
* resolution mode in which simple types (int, long, etc.) not annotated * resolution mode in which simple types (int, long, etc.) not annotated with
* with @{@link RequestParam} are also treated as request parameters with the * @{@link RequestParam} are also treated as request parameters with the
* parameter name derived from the argument name. * parameter name derived from the argument name.
* *
* <p>If the method parameter type is {@link Map}, the name specified in the * <p>If the method parameter type is {@link Map}, the name specified in the
@ -202,7 +202,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
if (arg == null) { if (arg == null) {
String[] paramValues = webRequest.getParameterValues(name); String[] paramValues = webRequest.getParameterValues(name);
if (paramValues != null) { if (paramValues != null) {
arg = paramValues.length == 1 ? paramValues[0] : paramValues; arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
} }
} }
} }
@ -218,23 +218,21 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
} }
private boolean isMultipartFileCollection(MethodParameter parameter) { private boolean isMultipartFileCollection(MethodParameter parameter) {
Class<?> collectionType = getCollectionParameterType(parameter); return MultipartFile.class.equals(getCollectionParameterType(parameter));
return ((collectionType != null) && collectionType.equals(MultipartFile.class)); }
private boolean isMultipartFileArray(MethodParameter parameter) {
return MultipartFile.class.equals(parameter.getParameterType().getComponentType());
} }
private boolean isPartCollection(MethodParameter parameter) { private boolean isPartCollection(MethodParameter parameter) {
Class<?> collectionType = getCollectionParameterType(parameter); Class<?> collectionType = getCollectionParameterType(parameter);
return ((collectionType != null) && "javax.servlet.http.Part".equals(collectionType.getName())); return (collectionType != null && "javax.servlet.http.Part".equals(collectionType.getName()));
} }
private boolean isPartArray(MethodParameter parameter) { private boolean isPartArray(MethodParameter parameter) {
Class<?> paramType = parameter.getParameterType().getComponentType(); Class<?> paramType = parameter.getParameterType().getComponentType();
return ((paramType != null) && "javax.servlet.http.Part".equals(paramType.getName())); return (paramType != null && "javax.servlet.http.Part".equals(paramType.getName()));
}
private boolean isMultipartFileArray(MethodParameter parameter) {
Class<?> paramType = parameter.getParameterType().getComponentType();
return ((paramType != null) && MultipartFile.class.equals(paramType));
} }
private Class<?> getCollectionParameterType(MethodParameter parameter) { private Class<?> getCollectionParameterType(MethodParameter parameter) {

Loading…
Cancel
Save