Skip to content

Commit 7df3a32

Browse files
committed
Polishing
1 parent 3779fe9 commit 7df3a32

File tree

3 files changed

+74
-72
lines changed

3 files changed

+74
-72
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,28 @@ MappingRegistry getMappingRegistry() {
153153
return this.mappingRegistry;
154154
}
155155

156+
/**
157+
* Register the given mapping.
158+
* <p>This method may be invoked at runtime after initialization has completed.
159+
* @param mapping the mapping for the handler method
160+
* @param handler the handler
161+
* @param method the method
162+
*/
163+
public void registerMapping(T mapping, Object handler, Method method) {
164+
this.mappingRegistry.register(mapping, handler, method);
165+
}
166+
167+
/**
168+
* Un-register the given mapping.
169+
* <p>This method may be invoked at runtime after initialization has completed.
170+
* @param mapping the mapping to unregister
171+
*/
172+
public void unregisterMapping(T mapping) {
173+
this.mappingRegistry.unregister(mapping);
174+
}
175+
176+
177+
// Handler method detection
156178

157179
/**
158180
* Detects handler methods at initialization.
@@ -196,13 +218,6 @@ protected void initHandlerMethods() {
196218
handlerMethodsInitialized(getHandlerMethods());
197219
}
198220

199-
/**
200-
* Whether the given type is a handler with handler methods.
201-
* @param beanType the type of the bean being checked
202-
* @return "true" if this a handler type, "false" otherwise.
203-
*/
204-
protected abstract boolean isHandler(Class<?> beanType);
205-
206221
/**
207222
* Look for handler methods in a handler.
208223
* @param handler the bean name of a handler or a handler instance
@@ -230,16 +245,6 @@ public T inspect(Method method) {
230245
}
231246
}
232247

233-
/**
234-
* Provide the mapping for a handler method. A method for which no
235-
* mapping can be provided is not a handler method.
236-
* @param method the method to provide a mapping for
237-
* @param handlerType the handler type, possibly a sub-type of the method's
238-
* declaring class
239-
* @return the mapping, or {@code null} if the method is not mapped
240-
*/
241-
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
242-
243248
/**
244249
* Register a handler method and its unique mapping. Invoked at startup for
245250
* each detected handler method.
@@ -272,11 +277,6 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) {
272277
return handlerMethod;
273278
}
274279

275-
/**
276-
* Extract and return the URL paths contained in a mapping.
277-
*/
278-
protected abstract Set<String> getMappingPathPatterns(T mapping);
279-
280280
/**
281281
* Extract and return the CORS configuration for the mapping.
282282
*/
@@ -291,25 +291,8 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
291291
protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) {
292292
}
293293

294-
/**
295-
* Register the given mapping.
296-
* <p>This method may be invoked at runtime after initialization has completed.
297-
* @param mapping the mapping for the handler method
298-
* @param handler the handler
299-
* @param method the method
300-
*/
301-
public void registerMapping(T mapping, Object handler, Method method) {
302-
this.mappingRegistry.register(mapping, handler, method);
303-
}
304294

305-
/**
306-
* Un-register the given mapping.
307-
* <p>This method may be invoked at runtime after initialization has completed.
308-
* @param mapping the mapping to unregister
309-
*/
310-
public void unregisterMapping(T mapping) {
311-
this.mappingRegistry.unregister(mapping);
312-
}
295+
// Handler method lookup
313296

314297
/**
315298
* Look up a handler method for the given request.
@@ -395,23 +378,6 @@ private void addMatchingMappings(Collection<T> mappings, List<Match> matches, Ht
395378
}
396379
}
397380

398-
/**
399-
* Check if a mapping matches the current request and return a (potentially
400-
* new) mapping with conditions relevant to the current request.
401-
* @param mapping the mapping to get a match for
402-
* @param request the current HTTP servlet request
403-
* @return the match, or {@code null} if the mapping doesn't match
404-
*/
405-
protected abstract T getMatchingMapping(T mapping, HttpServletRequest request);
406-
407-
/**
408-
* Return a comparator for sorting matching mappings.
409-
* The returned comparator should sort 'better' matches higher.
410-
* @param request the current request
411-
* @return the comparator (never {@code null})
412-
*/
413-
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);
414-
415381
/**
416382
* Invoked when a matching mapping is found.
417383
* @param mapping the matching mapping
@@ -452,6 +418,48 @@ protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequ
452418
}
453419

454420

421+
// Abstract template methods
422+
423+
/**
424+
* Whether the given type is a handler with handler methods.
425+
* @param beanType the type of the bean being checked
426+
* @return "true" if this a handler type, "false" otherwise.
427+
*/
428+
protected abstract boolean isHandler(Class<?> beanType);
429+
430+
/**
431+
* Provide the mapping for a handler method. A method for which no
432+
* mapping can be provided is not a handler method.
433+
* @param method the method to provide a mapping for
434+
* @param handlerType the handler type, possibly a sub-type of the method's
435+
* declaring class
436+
* @return the mapping, or {@code null} if the method is not mapped
437+
*/
438+
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
439+
440+
/**
441+
* Extract and return the URL paths contained in a mapping.
442+
*/
443+
protected abstract Set<String> getMappingPathPatterns(T mapping);
444+
445+
/**
446+
* Check if a mapping matches the current request and return a (potentially
447+
* new) mapping with conditions relevant to the current request.
448+
* @param mapping the mapping to get a match for
449+
* @param request the current HTTP servlet request
450+
* @return the match, or {@code null} if the mapping doesn't match
451+
*/
452+
protected abstract T getMatchingMapping(T mapping, HttpServletRequest request);
453+
454+
/**
455+
* Return a comparator for sorting matching mappings.
456+
* The returned comparator should sort 'better' matches higher.
457+
* @param request the current request
458+
* @return the comparator (never {@code null})
459+
*/
460+
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);
461+
462+
455463
/**
456464
* A registry that maintains all mappings to handler methods, exposing methods
457465
* to perform lookups and providing concurrent access.

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,6 @@
3333
import org.springframework.web.context.request.NativeWebRequest;
3434
import org.springframework.web.context.request.RequestAttributes;
3535
import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver;
36-
import org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver;
3736
import org.springframework.web.method.support.ModelAndViewContainer;
3837
import org.springframework.web.method.support.UriComponentsContributor;
3938
import org.springframework.web.servlet.HandlerMapping;
@@ -43,22 +42,18 @@
4342
/**
4443
* Resolves method arguments annotated with an @{@link PathVariable}.
4544
*
46-
* <p>An @{@link PathVariable} is a named value that gets resolved from a URI
47-
* template variable. It is always required and does not have a default value
48-
* to fall back on. See the base class
45+
* <p>An @{@link PathVariable} is a named value that gets resolved from a URI template variable.
46+
* It is always required and does not have a default value to fall back on. See the base class
4947
* {@link org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver}
5048
* for more information on how named values are processed.
5149
*
52-
* <p>If the method parameter type is {@link Map}, the name specified in the
53-
* annotation is used to resolve the URI variable String value. The value is
54-
* then converted to a {@link Map} via type conversion assuming a suitable
55-
* {@link Converter} or {@link PropertyEditor} has been registered.
56-
* Or if the annotation does not specify name the
57-
* {@link RequestParamMapMethodArgumentResolver} is used instead to provide
58-
* access to all URI variables in a map.
50+
* <p>If the method parameter type is {@link Map}, the name specified in the annotation is used
51+
* to resolve the URI variable String value. The value is then converted to a {@link Map} via
52+
* type conversion, assuming a suitable {@link Converter} or {@link PropertyEditor} has been
53+
* registered.
5954
*
60-
* <p>A {@link WebDataBinder} is invoked to apply type conversion to resolved
61-
* path variable values that don't yet match the method parameter type.
55+
* <p>A {@link WebDataBinder} is invoked to apply type conversion to resolved path variable
56+
* values that don't yet match the method parameter type.
6257
*
6358
* @author Rossen Stoyanchev
6459
* @author Arjen Poutsma

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.LinkedHashMap;
2929
import java.util.List;
3030
import java.util.Map;
31-
3231
import javax.servlet.http.HttpServletRequest;
3332

3433
import org.springframework.core.io.AbstractResource;

0 commit comments

Comments
 (0)