From 12e896ed8b19b3e7c5423a4727ec347004aaa90b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 25 Oct 2013 11:43:13 -0700 Subject: [PATCH] Polish --- build.gradle | 1 + .../handler/annotation/PathVariable.java | 12 ++++---- .../web/bind/annotation/PathVariable.java | 6 ++-- .../web/util/UriComponentsBuilder.java | 4 +-- .../servlet/mvc/support/DefaultMvcUrls.java | 23 +++++---------- .../web/servlet/mvc/support/MvcUrlUtils.java | 6 +--- .../web/servlet/mvc/support/MvcUrls.java | 28 ++++++------------- 7 files changed, 30 insertions(+), 50 deletions(-) diff --git a/build.gradle b/build.gradle index 55759453315..ed365e64210 100644 --- a/build.gradle +++ b/build.gradle @@ -726,6 +726,7 @@ project("spring-webmvc-tiles3") { } optional("org.apache.tiles:tiles-extras:3.0.1") { exclude group: "org.slf4j", module: "jcl-over-slf4j" + exclude group: "org.springframework", module: "spring-web" } optional("org.apache.tiles:tiles-el:3.0.1") { exclude group: "org.slf4j", module: "jcl-over-slf4j" diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/PathVariable.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/PathVariable.java index df22081b694..a3b4aec9240 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/PathVariable.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/PathVariable.java @@ -24,17 +24,17 @@ import java.lang.annotation.Target; /** * Annotation that indicates a method parameter should be bound to a path template - * variable. Supported on message handling methods such as {@link MessageMapping - * @MessageMapping} for messages with path-like destination semantics. - *

- * A {@code @PathVariable} template variable is always required and does not have a + * variable. Supported on message handling methods such as + * {@link MessageMapping @MessageMapping} for messages with path-like destination + * semantics. + * + *

A {@code @PathVariable} template variable is always required and does not have a * default value to fall back on. * * @author Brian Clozel + * @since 4.0 * @see org.springframework.messaging.handler.annotation.MessageMapping * @see org.springframework.messaging.simp.handler.SimpAnnotationMethodMessageHandler - * - * @since 4.0 */ @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java index 4a117205233..a61f09ee45e 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java @@ -28,17 +28,19 @@ import java.lang.annotation.Target; * environments. * * @author Arjen Poutsma + * @since 3.0 * @see RequestMapping * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter - * @since 3.0 */ @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface PathVariable { - /** The URI template variable to bind to. */ + /** + * The URI template variable to bind to. + */ String value() default ""; } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index fe530ff35f6..05fce62b090 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -248,7 +248,7 @@ public class UriComponentsBuilder { throw new IllegalArgumentException("[" + httpUrl + "] is not a valid HTTP URL"); } } - + // build methods @@ -398,7 +398,7 @@ public class UriComponentsBuilder { } return this; } - + /** * Set the URI scheme-specific-part. When invoked, this method overwrites * {@linkplain #userInfo(String) user-info}, {@linkplain #host(String) host}, diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultMvcUrls.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultMvcUrls.java index f5749619d5d..1b4784d2639 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultMvcUrls.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultMvcUrls.java @@ -63,10 +63,9 @@ public class DefaultMvcUrls implements MvcUrls { * {@link HandlerMethodArgumentResolver}s. Since both of these tend to be implemented * by the same class, the most convenient option is to obtain the configured * {@code HandlerMethodArgumentResolvers} in the {@code RequestMappingHandlerAdapter} - * and provide that to this contstructor. - * + * and provide that to this constructor. * @param uriComponentsContributors a collection of {@link UriComponentsContributor} - * or {@link HandlerMethodArgumentResolver}s. + * or {@link HandlerMethodArgumentResolver}s. */ public DefaultMvcUrls(Collection uriComponentsContributors) { this(uriComponentsContributors, null); @@ -77,26 +76,22 @@ public class DefaultMvcUrls implements MvcUrls { * {@link HandlerMethodArgumentResolver}s. Since both of these tend to be implemented * by the same class, the most convenient option is to obtain the configured * {@code HandlerMethodArgumentResolvers} in the {@code RequestMappingHandlerAdapter} - * and provide that to this contstructor. - *

- * If the {@link ConversionService} argument is {@code null}, - * {@link DefaultFormattingConversionService} will be used by default. + * and provide that to this constructor. * + *

If the {@link ConversionService} argument is {@code null}, + * {@link DefaultFormattingConversionService} will be used by default. * @param uriComponentsContributors a collection of {@link UriComponentsContributor} - * or {@link HandlerMethodArgumentResolver}s. + * or {@link HandlerMethodArgumentResolver}s. * @param conversionService a ConversionService to use when method argument values - * need to be formatted as Strings before being added to the URI + * need to be formatted as Strings before being added to the URI */ public DefaultMvcUrls(Collection uriComponentsContributors, ConversionService conversionService) { - Assert.notNull(uriComponentsContributors, "'uriComponentsContributors' must not be null"); - for (Object contributor : uriComponentsContributors) { if (contributor instanceof UriComponentsContributor) { this.contributors.add((UriComponentsContributor) contributor); } } - this.conversionService = (conversionService != null) ? conversionService : new DefaultFormattingConversionService(); } @@ -118,14 +113,12 @@ public class DefaultMvcUrls implements MvcUrls { private UriComponents applyContributers(UriComponentsBuilder builder, Method method, Object[] argumentValues, Map uriVars) { - if (this.contributors.isEmpty()) { return builder.buildAndExpand(uriVars); } int paramCount = method.getParameters().length; int argCount = argumentValues.length; - Assert.isTrue(paramCount == argCount, "Number of method parameters " + paramCount + " does not match number of argument values " + argCount); @@ -145,7 +138,6 @@ public class DefaultMvcUrls implements MvcUrls { @Override public UriComponents linkToMethodOn(Object mockController) { - Assert.isInstanceOf(ControllerMethodValues.class, mockController); ControllerMethodValues controllerMethodValues = (ControllerMethodValues) mockController; @@ -162,7 +154,6 @@ public class DefaultMvcUrls implements MvcUrls { } private void addTypeLevelUriVaris(ControllerMethodValues info, Map uriVariables) { - Object[] values = info.getTypeLevelUriVariables(); if (!ObjectUtils.isEmpty(values)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrlUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrlUtils.java index 11567e2068d..e1dda18a58d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrlUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrlUtils.java @@ -43,7 +43,6 @@ import org.springframework.web.util.UriComponents; * * @author Oliver Gierke * @author Rossen Stoyanchev - * * @since 4.0 */ public class MvcUrlUtils { @@ -67,7 +66,6 @@ public class MvcUrlUtils { logger.warn("Multiple class level mappings on " + controllerType.getName() + ", using the first one"); } return annot.value()[0]; - } /** @@ -97,7 +95,6 @@ public class MvcUrlUtils { * invoked method and argument values are remembered, and a "mock" value is returned * so it can be used to help prepare a {@link UriComponents} through * {@link MvcUrls#linkToMethodOn(Object)}. - * * @param controllerType the type of controller to mock, must not be {@literal null}. * @param typeLevelUriVariables URI variables to expand into the type-level mapping * @return the created controller instance @@ -109,7 +106,6 @@ public class MvcUrlUtils { @SuppressWarnings("unchecked") private static T initProxy(Class type, ControllerMethodInvocationInterceptor interceptor) { - if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type); @@ -192,7 +188,7 @@ public class MvcUrlUtils { *

* Instances of this interface are returned from * {@link MvcUrlUtils#controller(Class, Object...) controller(Class, Object...)} and - * are needed for {@link MvcUrls#linkToMethodOn(ControllerMethodValues)}. + * are needed for {@link MvcUrls#linkToMethodOn(Object)}. */ public interface ControllerMethodValues { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrls.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrls.java index 23bc4aa0114..3f42ed9ff35 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrls.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/MvcUrls.java @@ -27,19 +27,18 @@ import org.springframework.web.util.UriComponentsBuilder; /** * A contract for creating URLs by referencing Spring MVC controllers and methods. - *

- * The MVC Java config and the MVC namespace automatically create an instance of this + * + *

The MVC Java config and the MVC namespace automatically create an instance of this * contract for use in controllers and anywhere else during the processing of a request. * The best way for access it is to have it autowired, or otherwise injected either by * type or also qualified by name ("mvcUrls") if necessary. - *

- * If not using either option, with explicit configuration it's easy to create an instance - * of {@link DefaultMvcUrls} in Java config or in XML configuration, use + * + *

If not using either option, with explicit configuration it's easy to create an + * instance of {@link DefaultMvcUrls} in Java config or in XML configuration, use * {@link DefaultMvcUrlsFactoryBean}. * * @author Oliver Gierke * @author Rossen Stoyanchev - * * @since 4.0 */ public interface MvcUrls { @@ -50,9 +49,7 @@ public interface MvcUrls { * the Servlet mapping as well as the portion of the path matching to the controller * level request mapping. If the controller contains multiple mappings, the * {@link DefaultMvcUrls} will use the first one. - * * @param controllerType the controller type to create a URL to - * * @return a builder that can be used to further build the {@link UriComponents}. */ UriComponentsBuilder linkToController(Class controllerType); @@ -60,19 +57,15 @@ public interface MvcUrls { /** * Create a {@link UriComponents} by pointing to a controller method along with method * argument values. - *

- * Type and method-level mappings of the controller method are extracted and the + * + *

Type and method-level mappings of the controller method are extracted and the * resulting {@link UriComponents} is further enriched with method argument values from * {@link PathVariable} and {@link RequestParam} parameters. Any other arguments not * relevant to the building of the URL can be provided as {@literal null} and will be * ignored. Support for additional custom arguments can be added through a * {@link UriComponentsContributor}. - * - * FIXME Type-level URI template variables? - * * @param method the target controller method * @param argumentValues argument values matching to method parameters - * * @return UriComponents instance, never {@literal null} */ UriComponents linkToMethod(Method method, Object... argumentValues); @@ -88,10 +81,10 @@ public interface MvcUrls { * class AddressController { * * @RequestMapping("/{country}") - * public HttpEntity getAddressesForCountry(@PathVariable String country) { … } + * public HttpEntity<Void> getAddressesForCountry(@PathVariable String country) { ... } * * @RequestMapping(value="/", method=RequestMethod.POST) - * public void addAddress(Address address) { … } + * public void addAddress(Address address) { ... } * } * * // short-hand style with static import of MvcUrlUtils.controller @@ -104,16 +97,13 @@ public interface MvcUrls { * controller.addAddress(null); * * mvcUrls.linkToMethodOn(controller); - * * * * The above mechanism supports {@link PathVariable} and {@link RequestParam} method * arguments. Any other arguments can be provided as {@literal null} and will be * ignored. Additional custom arguments can be added through an implementation of * {@link UriComponentsContributor}. - * * @param mockController created via {@link MvcUrlUtils#controller(Class, Object...)} - * * @return UriComponents instance, never {@literal null} */ UriComponents linkToMethodOn(Object mockController);