Polishing

This commit is contained in:
Juergen Hoeller
2016-03-23 18:39:29 +01:00
parent 5025c615b1
commit 9af12d290e
34 changed files with 231 additions and 262 deletions

View File

@@ -27,15 +27,15 @@ import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
/**
* Holder that combines a {@link Resource} descriptor with
* {@link HttpRange} information to be used for reading
* selected parts of the resource.
* Holder that combines a {@link Resource} descriptor with {@link HttpRange}
* information to be used for reading selected parts of the resource.
*
* <p>Used as an argument for partial conversion operations in
* {@link org.springframework.http.converter.ResourceHttpMessageConverter}.
*
* @author Brian Clozel
* @since 4.3.0
* @since 4.3
* @see HttpRange
*/
public class HttpRangeResource implements Resource {
@@ -43,77 +43,81 @@ public class HttpRangeResource implements Resource {
private final Resource resource;
public HttpRangeResource(List<HttpRange> httpRanges, Resource resource) {
Assert.notEmpty(httpRanges, "list of HTTP Ranges should not be empty");
Assert.notEmpty(httpRanges, "List of HTTP Ranges should not be empty");
this.httpRanges = httpRanges;
this.resource = resource;
}
/**
* Return the list of HTTP (byte) ranges describing the requested
* parts of the Resource, as provided by the HTTP Range request.
*/
public final List<HttpRange> getHttpRanges() {
return httpRanges;
return this.httpRanges;
}
@Override
public boolean exists() {
return resource.exists();
return this.resource.exists();
}
@Override
public boolean isReadable() {
return resource.isReadable();
return this.resource.isReadable();
}
@Override
public boolean isOpen() {
return resource.isOpen();
return this.resource.isOpen();
}
@Override
public URL getURL() throws IOException {
return resource.getURL();
return this.resource.getURL();
}
@Override
public URI getURI() throws IOException {
return resource.getURI();
return this.resource.getURI();
}
@Override
public File getFile() throws IOException {
return resource.getFile();
return this.resource.getFile();
}
@Override
public long contentLength() throws IOException {
return resource.contentLength();
return this.resource.contentLength();
}
@Override
public long lastModified() throws IOException {
return resource.lastModified();
return this.resource.lastModified();
}
@Override
public Resource createRelative(String relativePath) throws IOException {
return resource.createRelative(relativePath);
return this.resource.createRelative(relativePath);
}
@Override
public String getFilename() {
return resource.getFilename();
return this.resource.getFilename();
}
@Override
public String getDescription() {
return resource.getDescription();
return this.resource.getDescription();
}
@Override
public InputStream getInputStream() throws IOException {
return resource.getInputStream();
return this.resource.getInputStream();
}
}

View File

@@ -148,7 +148,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return supports(clazz) && canWrite(mediaType);
}
}
/**
* Returns {@code true} if the given media type includes any of the

View File

@@ -17,15 +17,13 @@
package org.springframework.web.bind.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
/**
* Annotation for mapping HTTP {@code DELETE} requests onto specific handler
* methods.
@@ -41,10 +39,10 @@ import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
* @see PatchMapping
* @see RequestMapping
*/
@Target(METHOD)
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = DELETE)
@RequestMapping(method = RequestMethod.DELETE)
public @interface DeleteMapping {
/**

View File

@@ -17,15 +17,13 @@
package org.springframework.web.bind.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
/**
* Annotation for mapping HTTP {@code GET} requests onto specific handler
* methods.
@@ -45,10 +43,10 @@ import static org.springframework.web.bind.annotation.RequestMethod.GET;
* @see PatchMapping
* @see RequestMapping
*/
@Target(METHOD)
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = GET)
@RequestMapping(method = RequestMethod.GET)
public @interface GetMapping {
/**

View File

@@ -83,6 +83,7 @@ public @interface ModelAttribute {
* binding for that attribute.
* <p>By default this is set to "true" in which case data binding applies.
* Set this to "false" to disable data binding.
* @since 4.3
*/
boolean binding() default true;

View File

@@ -17,15 +17,13 @@
package org.springframework.web.bind.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.bind.annotation.RequestMethod.PATCH;
/**
* Annotation for mapping HTTP {@code PATCH} requests onto specific handler
* methods.
@@ -41,10 +39,10 @@ import static org.springframework.web.bind.annotation.RequestMethod.PATCH;
* @see DeleteMapping
* @see RequestMapping
*/
@Target(METHOD)
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = PATCH)
@RequestMapping(method = RequestMethod.PATCH)
public @interface PatchMapping {
/**

View File

@@ -17,15 +17,13 @@
package org.springframework.web.bind.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
/**
* Annotation for mapping HTTP {@code POST} requests onto specific handler
* methods.
@@ -41,10 +39,10 @@ import static org.springframework.web.bind.annotation.RequestMethod.POST;
* @see PatchMapping
* @see RequestMapping
*/
@Target(METHOD)
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = POST)
@RequestMapping(method = RequestMethod.POST)
public @interface PostMapping {
/**

View File

@@ -17,15 +17,13 @@
package org.springframework.web.bind.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
/**
* Annotation for mapping HTTP {@code PUT} requests onto specific handler
* methods.
@@ -41,10 +39,10 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT;
* @see PatchMapping
* @see RequestMapping
*/
@Target(METHOD)
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = PUT)
@RequestMapping(method = RequestMethod.PUT)
public @interface PutMapping {
/**

View File

@@ -17,17 +17,15 @@
package org.springframework.web.context.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.context.WebApplicationContext.SCOPE_APPLICATION;
import org.springframework.web.context.WebApplicationContext;
/**
* {@code @ApplicationScope} is a specialization of {@link Scope @Scope} for a
@@ -50,10 +48,10 @@ import static org.springframework.web.context.WebApplicationContext.SCOPE_APPLIC
* @see org.springframework.stereotype.Component
* @see org.springframework.context.annotation.Bean
*/
@Scope(SCOPE_APPLICATION)
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Scope(WebApplicationContext.SCOPE_APPLICATION)
public @interface ApplicationScope {
/**

View File

@@ -17,17 +17,15 @@
package org.springframework.web.context.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.context.WebApplicationContext.SCOPE_REQUEST;
import org.springframework.web.context.WebApplicationContext;
/**
* {@code @RequestScope} is a specialization of {@link Scope @Scope} for a
@@ -50,10 +48,10 @@ import static org.springframework.web.context.WebApplicationContext.SCOPE_REQUES
* @see org.springframework.stereotype.Component
* @see org.springframework.context.annotation.Bean
*/
@Scope(SCOPE_REQUEST)
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Scope(WebApplicationContext.SCOPE_REQUEST)
public @interface RequestScope {
/**

View File

@@ -17,17 +17,15 @@
package org.springframework.web.context.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.annotation.AliasFor;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.springframework.web.context.WebApplicationContext.SCOPE_SESSION;
import org.springframework.web.context.WebApplicationContext;
/**
* {@code @SessionScope} is a specialization of {@link Scope @Scope} for a
@@ -50,10 +48,10 @@ import static org.springframework.web.context.WebApplicationContext.SCOPE_SESSIO
* @see org.springframework.stereotype.Component
* @see org.springframework.context.annotation.Bean
*/
@Scope(SCOPE_SESSION)
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Scope(WebApplicationContext.SCOPE_SESSION)
public @interface SessionScope {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -103,8 +103,8 @@ public class ControllerAdviceBean implements Ordered {
this.order = initOrderFromBean(bean);
}
ControllerAdvice annotation = AnnotatedElementUtils.findMergedAnnotation(
beanType, ControllerAdvice.class);
ControllerAdvice annotation =
AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class);
if (annotation != null) {
this.basePackages = initBasePackages(annotation);

View File

@@ -132,10 +132,10 @@ public final class ModelFactory {
while (!this.modelMethods.isEmpty()) {
InvocableHandlerMethod modelMethod = getNextModelMethod(container).getHandlerMethod();
ModelAttribute annotation = modelMethod.getMethodAnnotation(ModelAttribute.class);
if (container.containsAttribute(annotation.name())) {
if (!annotation.binding()) {
container.setBindingDisabled(annotation.name());
ModelAttribute ann = modelMethod.getMethodAnnotation(ModelAttribute.class);
if (container.containsAttribute(ann.name())) {
if (!ann.binding()) {
container.setBindingDisabled(ann.name());
}
continue;
}
@@ -144,7 +144,7 @@ public final class ModelFactory {
if (!modelMethod.isVoid()){
String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType());
if (!annotation.binding()) {
if (!ann.binding()) {
container.setBindingDisabled(returnValueName);
}
if (!container.containsAttribute(returnValueName)) {
@@ -193,32 +193,32 @@ public final class ModelFactory {
/**
* Derives the model attribute name for a method parameter based on:
* <ol>
* <li>The parameter {@code @ModelAttribute} annotation value
* <li>The parameter type
* <li>The parameter {@code @ModelAttribute} annotation value
* <li>The parameter type
* </ol>
* @return the derived name; never {@code null} or an empty string
*/
public static String getNameForParameter(MethodParameter parameter) {
ModelAttribute annot = parameter.getParameterAnnotation(ModelAttribute.class);
String name = (annot != null) ? annot.value() : null;
ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);
String name = (ann != null ? ann.value() : null);
return StringUtils.hasText(name) ? name : Conventions.getVariableNameForParameter(parameter);
}
/**
* Derive the model attribute name for the given return value using one of:
* <ol>
* <li>The method {@code ModelAttribute} annotation value
* <li>The declared return type if it is more specific than {@code Object}
* <li>The actual return value type
* <li>The method {@code ModelAttribute} annotation value
* <li>The declared return type if it is more specific than {@code Object}
* <li>The actual return value type
* </ol>
* @param returnValue the value returned from a method invocation
* @param returnType the return type of the method
* @return the model name, never {@code null} nor empty
*/
public static String getNameForReturnValue(Object returnValue, MethodParameter returnType) {
ModelAttribute annotation = returnType.getMethodAnnotation(ModelAttribute.class);
if (annotation != null && StringUtils.hasText(annotation.value())) {
return annotation.value();
ModelAttribute ann = returnType.getMethodAnnotation(ModelAttribute.class);
if (ann != null && StringUtils.hasText(ann.value())) {
return ann.value();
}
else {
Method method = returnType.getMethod();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.MethodParameter;
import org.springframework.util.Assert;
import org.springframework.web.context.request.NativeWebRequest;
/**
@@ -76,7 +75,9 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
HandlerMethodReturnValueHandler handler = selectHandler(returnValue, returnType);
Assert.notNull(handler, "Unknown return value type [" + returnType.getParameterType().getName() + "]");
if (handler == null) {
throw new IllegalArgumentException("Unknown return value type: " + returnType.getParameterType().getName());
}
handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
}