Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jan 26, 2016
1 parent 3779fe9 commit 7df3a32
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ MappingRegistry getMappingRegistry() {
return this.mappingRegistry;
}

/**
* Register the given mapping.
* <p>This method may be invoked at runtime after initialization has completed.
* @param mapping the mapping for the handler method
* @param handler the handler
* @param method the method
*/
public void registerMapping(T mapping, Object handler, Method method) {
this.mappingRegistry.register(mapping, handler, method);
}

/**
* Un-register the given mapping.
* <p>This method may be invoked at runtime after initialization has completed.
* @param mapping the mapping to unregister
*/
public void unregisterMapping(T mapping) {
this.mappingRegistry.unregister(mapping);
}


// Handler method detection

/**
* Detects handler methods at initialization.
Expand Down Expand Up @@ -196,13 +218,6 @@ protected void initHandlerMethods() {
handlerMethodsInitialized(getHandlerMethods());
}

/**
* Whether the given type is a handler with handler methods.
* @param beanType the type of the bean being checked
* @return "true" if this a handler type, "false" otherwise.
*/
protected abstract boolean isHandler(Class<?> beanType);

/**
* Look for handler methods in a handler.
* @param handler the bean name of a handler or a handler instance
Expand Down Expand Up @@ -230,16 +245,6 @@ public T inspect(Method method) {
}
}

/**
* Provide the mapping for a handler method. A method for which no
* mapping can be provided is not a handler method.
* @param method the method to provide a mapping for
* @param handlerType the handler type, possibly a sub-type of the method's
* declaring class
* @return the mapping, or {@code null} if the method is not mapped
*/
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);

/**
* Register a handler method and its unique mapping. Invoked at startup for
* each detected handler method.
Expand Down Expand Up @@ -272,11 +277,6 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) {
return handlerMethod;
}

/**
* Extract and return the URL paths contained in a mapping.
*/
protected abstract Set<String> getMappingPathPatterns(T mapping);

/**
* Extract and return the CORS configuration for the mapping.
*/
Expand All @@ -291,25 +291,8 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) {
}

/**
* Register the given mapping.
* <p>This method may be invoked at runtime after initialization has completed.
* @param mapping the mapping for the handler method
* @param handler the handler
* @param method the method
*/
public void registerMapping(T mapping, Object handler, Method method) {
this.mappingRegistry.register(mapping, handler, method);
}

/**
* Un-register the given mapping.
* <p>This method may be invoked at runtime after initialization has completed.
* @param mapping the mapping to unregister
*/
public void unregisterMapping(T mapping) {
this.mappingRegistry.unregister(mapping);
}
// Handler method lookup

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

/**
* Check if a mapping matches the current request and return a (potentially
* new) mapping with conditions relevant to the current request.
* @param mapping the mapping to get a match for
* @param request the current HTTP servlet request
* @return the match, or {@code null} if the mapping doesn't match
*/
protected abstract T getMatchingMapping(T mapping, HttpServletRequest request);

/**
* Return a comparator for sorting matching mappings.
* The returned comparator should sort 'better' matches higher.
* @param request the current request
* @return the comparator (never {@code null})
*/
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);

/**
* Invoked when a matching mapping is found.
* @param mapping the matching mapping
Expand Down Expand Up @@ -452,6 +418,48 @@ protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequ
}


// Abstract template methods

/**
* Whether the given type is a handler with handler methods.
* @param beanType the type of the bean being checked
* @return "true" if this a handler type, "false" otherwise.
*/
protected abstract boolean isHandler(Class<?> beanType);

/**
* Provide the mapping for a handler method. A method for which no
* mapping can be provided is not a handler method.
* @param method the method to provide a mapping for
* @param handlerType the handler type, possibly a sub-type of the method's
* declaring class
* @return the mapping, or {@code null} if the method is not mapped
*/
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);

/**
* Extract and return the URL paths contained in a mapping.
*/
protected abstract Set<String> getMappingPathPatterns(T mapping);

/**
* Check if a mapping matches the current request and return a (potentially
* new) mapping with conditions relevant to the current request.
* @param mapping the mapping to get a match for
* @param request the current HTTP servlet request
* @return the match, or {@code null} if the mapping doesn't match
*/
protected abstract T getMatchingMapping(T mapping, HttpServletRequest request);

/**
* Return a comparator for sorting matching mappings.
* The returned comparator should sort 'better' matches higher.
* @param request the current request
* @return the comparator (never {@code null})
*/
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);


/**
* A registry that maintains all mappings to handler methods, exposing methods
* to perform lookups and providing concurrent access.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -33,7 +33,6 @@
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver;
import org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.method.support.UriComponentsContributor;
import org.springframework.web.servlet.HandlerMapping;
Expand All @@ -43,22 +42,18 @@
/**
* Resolves method arguments annotated with an @{@link PathVariable}.
*
* <p>An @{@link PathVariable} is a named value that gets resolved from a URI
* template variable. It is always required and does not have a default value
* to fall back on. See the base class
* <p>An @{@link PathVariable} is a named value that gets resolved from a URI template variable.
* It is always required and does not have a default value to fall back on. See the base class
* {@link org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver}
* for more information on how named values are processed.
*
* <p>If the method parameter type is {@link Map}, the name specified in the
* annotation is used to resolve the URI variable String value. The value is
* then converted to a {@link Map} via type conversion assuming a suitable
* {@link Converter} or {@link PropertyEditor} has been registered.
* Or if the annotation does not specify name the
* {@link RequestParamMapMethodArgumentResolver} is used instead to provide
* access to all URI variables in a map.
* <p>If the method parameter type is {@link Map}, the name specified in the annotation is used
* to resolve the URI variable String value. The value is then converted to a {@link Map} via
* type conversion, assuming a suitable {@link Converter} or {@link PropertyEditor} has been
* registered.
*
* <p>A {@link WebDataBinder} is invoked to apply type conversion to resolved
* path variable values that don't yet match the method parameter type.
* <p>A {@link WebDataBinder} is invoked to apply type conversion to resolved path variable
* values that don't yet match the method parameter type.
*
* @author Rossen Stoyanchev
* @author Arjen Poutsma
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.io.AbstractResource;
Expand Down

0 comments on commit 7df3a32

Please sign in to comment.