Skip to content
Browse files

Polishing

  • Loading branch information...
1 parent 8b2b165 commit 4d3ca4319e66e6a9e2470838b8b7627da757e3e5 @jhoeller jhoeller committed Mar 11, 2014
View
49 spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -18,27 +18,30 @@
/**
- * A property accessor is able to read (and possibly write) to object properties. The
- * interface places no restrictions and so implementors are free to access properties
- * directly as fields or through getters or in any other way they see as appropriate. A
- * resolver can optionally specify an array of target classes for which it should be
- * called - but if it returns null from getSpecificTargetClasses() then it will be called
- * for all property references and given a chance to determine if it can read or write
- * them. Property resolvers are considered to be ordered and each will be called in turn.
+ * A property accessor is able to read from (and possibly write to) an object's properties.
+ * This interface places no restrictions, and so implementors are free to access properties
+ * directly as fields or through getters or in any other way they see as appropriate.
+ *
+ * <p>A resolver can optionally specify an array of target classes for which it should be
+ * called. However, if it returns {@code null} from {@link #getSpecificTargetClasses()},
+ * it will be called for all property references and given a chance to determine if it
+ * can read or write them.
+ *
+ * <p>Property resolvers are considered to be ordered and each will be called in turn.
* The only rule that affects the call order is that any naming the target class directly
- * in getSpecifiedTargetClasses() will be called first, before the general resolvers.
+ * in {@link #getSpecificTargetClasses()} will be called first, before the general resolvers.
*
* @author Andy Clement
* @since 3.0
*/
public interface PropertyAccessor {
/**
- * Return an array of classes for which this resolver should be called. Returning null
- * indicates this is a general resolver that can be called in an attempt to resolve a
- * property on any type.
- * @return an array of classes that this resolver is suitable for (or null if a
- * general resolver)
+ * Return an array of classes for which this resolver should be called.
+ * <p>>Returning {@code null} indicates this is a general resolver that
+ * can be called in an attempt to resolve a property on any type.
+ * @return an array of classes that this resolver is suitable for
+ * (or {@code null} if a general resolver)
*/
Class<?>[] getSpecificTargetClasses();
@@ -49,13 +52,13 @@
* @param target the target object upon which the property is being accessed
* @param name the name of the property being accessed
* @return true if this resolver is able to read the property
- * @throws AccessException if there is any problem determining whether the property
- * can be read
+ * @throws AccessException if there is any problem determining whether the property can be read
*/
boolean canRead(EvaluationContext context, Object target, String name) throws AccessException;
/**
- * Called to read a property from a specified target object
+ * Called to read a property from a specified target object.
+ * Should only succeed if {@link #canRead} also returns {@code true}.
* @param context the evaluation context in which the access is being attempted
* @param target the target object upon which the property is being accessed
* @param name the name of the property being accessed
@@ -65,20 +68,20 @@
TypedValue read(EvaluationContext context, Object target, String name) throws AccessException;
/**
- * Called to determine if a resolver instance is able to write to a specified property
- * on a specified target object.
+ * Called to determine if a resolver instance is able to write to a specified
+ * property on a specified target object.
* @param context the evaluation context in which the access is being attempted
* @param target the target object upon which the property is being accessed
* @param name the name of the property being accessed
* @return true if this resolver is able to write to the property
- * @throws AccessException if there is any problem determining whether the property
- * can be written to
+ * @throws AccessException if there is any problem determining whether the
+ * property can be written to
*/
boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException;
/**
- * Called to write to a property on a specified target object. Should only succeed if
- * canWrite() also returns true.
+ * Called to write to a property on a specified target object.
+ * Should only succeed if {@link #canWrite} also returns {@code true}.
* @param context the evaluation context in which the access is being attempted
* @param target the target object upon which the property is being accessed
* @param name the name of the property being accessed
View
5 ...c/main/java/org/springframework/http/converter/xml/AbstractJaxb2HttpMessageConverter.java
@@ -31,6 +31,7 @@
* that use JAXB2. Creates {@link JAXBContext} object lazily.
*
* @author Arjen Poutsma
+ * @author Rossen Stoyanchev
* @since 3.0
*/
public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHttpMessageConverter<T> {
@@ -61,8 +62,8 @@ protected final Marshaller createMarshaller(Class<?> clazz) {
* Customize the {@link Marshaller} created by this
* message converter before using it to write the object to the output.
* @param marshaller the marshaller to customize
- * @see #createMarshaller(Class)
* @since 4.0.3
+ * @see #createMarshaller(Class)
*/
protected void customizeMarshaller(Marshaller marshaller) {
}
@@ -90,8 +91,8 @@ protected final Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBExcep
* Customize the {@link Unmarshaller} created by this
* message converter before using it to read the object from the input.
* @param unmarshaller the unmarshaller to customize
- * @see #createUnmarshaller(Class)
* @since 4.0.3
+ * @see #createUnmarshaller(Class)
*/
protected void customizeUnmarshaller(Unmarshaller unmarshaller) {
}
View
8 spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
-
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpHeaders;
@@ -116,11 +115,12 @@ private void writeHeaders() {
}
}
+
/**
* Extends HttpHeaders with the ability to look up headers already present in
* the underlying HttpServletResponse.
*
- * The intent is merely to expose what is available through the HttpServletResponse
+ * <p>The intent is merely to expose what is available through the HttpServletResponse
* i.e. the ability to look up specific header values by name. All other
* map-related operations (e.g. iteration, removal, etc) apply only to values
* added directly through HttpHeaders methods.
@@ -144,8 +144,8 @@ public String getFirst(String headerName) {
@Override
public List<String> get(Object key) {
+ Assert.isInstanceOf(String.class, key, "Key must be a String-based header name");
- Assert.isInstanceOf(String.class, key, "key must be a String-based header name");
Collection<String> values1 = servletResponse.getHeaders((String) key);
boolean isEmpty1 = CollectionUtils.isEmpty(values1);
View
4 spring-web/src/main/java/org/springframework/web/util/WebUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -277,7 +277,7 @@ public static Object getSessionAttribute(HttpServletRequest request, String name
* @throws IllegalStateException if the session attribute could not be found
*/
public static Object getRequiredSessionAttribute(HttpServletRequest request, String name)
- throws IllegalStateException {
+ throws IllegalStateException {
Object attr = getSessionAttribute(request, name);
if (attr == null) {
View
5 spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMapManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -25,7 +25,6 @@
*
* @author Rossen Stoyanchev
* @since 3.1
- *
* @see FlashMap
*/
public interface FlashMapManager {
@@ -46,7 +45,7 @@
/**
* Save the given FlashMap, in some underlying storage and set the start
* of its expiration period.
- * <p><strong>Note:</strong> Invoke this method prior to a redirect in order
+ * <p><strong>NOTE:</strong> Invoke this method prior to a redirect in order
* to allow saving the FlashMap in the HTTP session or in a response
* cookie before the response is committed.
* @param flashMap the FlashMap to save
View
18 .../src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.web.servlet.config.annotation;
import org.springframework.util.PathMatcher;
@@ -29,11 +30,16 @@
public class PathMatchConfigurer {
private Boolean useSuffixPatternMatch;
+
private Boolean useTrailingSlashMatch;
+
private Boolean useRegisteredSuffixPatternMatch;
+
private UrlPathHelper urlPathHelper;
+
private PathMatcher pathMatcher;
+
/**
* Whether to use suffix pattern match (".*") when matching patterns to
* requests. If enabled a method mapped to "/users" also matches to "/users.*".
@@ -95,23 +101,25 @@ public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher) {
return this;
}
+
public Boolean isUseSuffixPatternMatch() {
- return useSuffixPatternMatch;
+ return this.useSuffixPatternMatch;
}
public Boolean isUseTrailingSlashMatch() {
- return useTrailingSlashMatch;
+ return this.useTrailingSlashMatch;
}
public Boolean isUseRegisteredSuffixPatternMatch() {
- return useRegisteredSuffixPatternMatch;
+ return this.useRegisteredSuffixPatternMatch;
}
public UrlPathHelper getUrlPathHelper() {
- return urlPathHelper;
+ return this.urlPathHelper;
}
public PathMatcher getPathMatcher() {
- return pathMatcher;
+ return this.pathMatcher;
}
+
}
View
17 ...a/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -26,7 +26,6 @@
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -114,8 +113,8 @@
* @see HandlerMethodArgumentResolver
* @see HandlerMethodReturnValueHandler
*/
-public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware,
- InitializingBean {
+public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
+ implements BeanFactoryAware, InitializingBean {
private List<HandlerMethodArgumentResolver> customArgumentResolvers;
@@ -698,7 +697,7 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl
Class<?> handlerType = handlerMethod.getBeanType();
SessionAttributesHandler sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
if (sessionAttrHandler == null) {
- synchronized(this.sessionAttributesHandlerCache) {
+ synchronized (this.sessionAttributesHandlerCache) {
sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
if (sessionAttrHandler == null) {
sessionAttrHandler = new SessionAttributesHandler(handlerType, sessionAttributeStore);
@@ -710,7 +709,8 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl
}
/**
- * Invoke the {@link RequestMapping} handler method preparing a {@link ModelAndView} if view resolution is required.
+ * Invoke the {@link RequestMapping} handler method preparing a {@link ModelAndView}
+ * if view resolution is required.
*/
private ModelAndView invokeHandleMethod(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
@@ -778,7 +778,7 @@ private ModelFactory getModelFactory(HandlerMethod handlerMethod, WebDataBinderF
List<InvocableHandlerMethod> attrMethods = new ArrayList<InvocableHandlerMethod>();
// Global methods first
for (Entry<ControllerAdviceBean, Set<Method>> entry : this.modelAttributeAdviceCache.entrySet()) {
- if(entry.getKey().isApplicableToBeanType(handlerType)) {
+ if (entry.getKey().isApplicableToBeanType(handlerType)) {
Object bean = entry.getKey().resolveBean();
for (Method method : entry.getValue()) {
attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
@@ -810,7 +810,7 @@ private WebDataBinderFactory getDataBinderFactory(HandlerMethod handlerMethod) t
List<InvocableHandlerMethod> initBinderMethods = new ArrayList<InvocableHandlerMethod>();
// Global methods first
for (Entry<ControllerAdviceBean, Set<Method>> entry : this.initBinderAdviceCache .entrySet()) {
- if(entry.getKey().isApplicableToBeanType(handlerType)) {
+ if (entry.getKey().isApplicableToBeanType(handlerType)) {
Object bean = entry.getKey().resolveBean();
for (Method method : entry.getValue()) {
initBinderMethods.add(createInitBinderMethod(bean, method));
@@ -850,7 +850,6 @@ private ModelAndView getModelAndView(ModelAndViewContainer mavContainer,
ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {
modelFactory.updateModel(webRequest, mavContainer);
-
if (mavContainer.isRequestHandled()) {
return null;
}
View
20 ...webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java
@@ -20,12 +20,12 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
@@ -43,13 +43,14 @@
*/
public abstract class AbstractFlashMapManager implements FlashMapManager {
+ private static final Object writeLock = new Object();
+
protected final Log logger = LogFactory.getLog(getClass());
private int flashMapTimeout = 180;
private UrlPathHelper urlPathHelper = new UrlPathHelper();
- private static final Object writeLock = new Object();
/**
* Set the amount of time in seconds after a {@link FlashMap} is saved
@@ -82,17 +83,17 @@ public UrlPathHelper getUrlPathHelper() {
return this.urlPathHelper;
}
+
@Override
public final FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response) {
-
List<FlashMap> maps = retrieveFlashMaps(request);
if (CollectionUtils.isEmpty(maps)) {
return null;
}
+
if (logger.isDebugEnabled()) {
logger.debug("Retrieved FlashMap(s): " + maps);
}
-
List<FlashMap> mapsToRemove = getExpiredFlashMaps(maps);
FlashMap match = getMatchingFlashMap(maps, request);
@@ -163,8 +164,7 @@ protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest req
String expectedPath = flashMap.getTargetRequestPath();
if (expectedPath != null) {
String requestUri = this.urlPathHelper.getOriginatingRequestUri(request);
- if (!requestUri.equals(expectedPath)
- && !requestUri.equals(expectedPath + "/")) {
+ if (!requestUri.equals(expectedPath) && !requestUri.equals(expectedPath + "/")) {
return false;
}
}
@@ -187,18 +187,16 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request);
flashMap.setTargetRequestPath(path);
-
decodeParameters(flashMap.getTargetRequestParams(), request);
if (logger.isDebugEnabled()) {
logger.debug("Saving FlashMap=" + flashMap);
}
-
flashMap.startExpirationPeriod(this.flashMapTimeout);
synchronized (writeLock) {
List<FlashMap> allMaps = retrieveFlashMaps(request);
- allMaps = (allMaps == null) ? new CopyOnWriteArrayList<FlashMap>() : allMaps;
+ allMaps = (allMaps != null ? allMaps : new CopyOnWriteArrayList<FlashMap>());
allMaps.add(flashMap);
updateFlashMaps(allMaps, request, response);
}
@@ -232,7 +230,7 @@ private void decodeParameters(MultiValueMap<String, String> params, HttpServletR
* @param request the current request
* @param response the current response
*/
- protected abstract void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request,
- HttpServletResponse response);
+ protected abstract void updateFlashMaps(
+ List<FlashMap> flashMaps, HttpServletRequest request, HttpServletResponse response);
}
View
8 ...-webmvc/src/main/java/org/springframework/web/servlet/support/SessionFlashMapManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -17,7 +17,6 @@
package org.springframework.web.servlet.support;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -30,10 +29,11 @@
* @author Rossen Stoyanchev
* @since 3.1.1
*/
-public class SessionFlashMapManager extends AbstractFlashMapManager{
+public class SessionFlashMapManager extends AbstractFlashMapManager {
private static final String FLASH_MAPS_SESSION_ATTRIBUTE = SessionFlashMapManager.class.getName() + ".FLASH_MAPS";
+
/**
* Retrieve saved FlashMap instances from the HTTP Session.
* <p>Does not cause an HTTP session to be created but may update it if a
@@ -44,7 +44,7 @@
@SuppressWarnings("unchecked")
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) {
HttpSession session = request.getSession(false);
- return (session != null) ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null;
+ return (session != null ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null);
}
/**
View
5 ...ng-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java
@@ -16,12 +16,10 @@
package org.springframework.web.servlet.support;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -305,8 +303,7 @@ public void setFlashMaps(List<FlashMap> flashMaps) {
}
@Override
- protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request,
- HttpServletResponse response) {
+ protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request, HttpServletResponse response) {
this.flashMaps = flashMaps;
}
}

0 comments on commit 4d3ca43

Please sign in to comment.
Something went wrong with that request. Please try again.