From e324c2ab4a21b211d8ac0f88edfcec5c795dd671 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 22 Aug 2014 00:14:10 +0200 Subject: [PATCH] Polishing --- .../annotation/ConfigurationClassParser.java | 18 ++++----- .../io/support/PropertiesLoaderSupport.java | 6 +-- .../springframework/web/servlet/FlashMap.java | 26 ++++++------- .../handler/BeanCreatingHandlerProvider.java | 37 +++++++------------ .../standard/ServerEndpointRegistration.java | 7 ++-- 5 files changed, 39 insertions(+), 55 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index b3f16ccea3..b25b874d8f 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -231,16 +231,16 @@ class ConfigurationClassParser { * @return the superclass, or {@code null} if none found or previously processed */ protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { - // recursively process any member (nested) classes first + // Recursively process any member (nested) classes first processMemberClasses(configClass, sourceClass); - // process any @PropertySource annotations + // Process any @PropertySource annotations for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable( sourceClass.getMetadata(), PropertySources.class, org.springframework.context.annotation.PropertySource.class)) { processPropertySource(propertySource); } - // process any @ComponentScan annotations + // Process any @ComponentScan annotations AnnotationAttributes componentScan = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ComponentScan.class); if (componentScan != null) { // the config class is annotated with @ComponentScan -> perform the scan immediately @@ -257,10 +257,10 @@ class ConfigurationClassParser { } } - // process any @Import annotations + // Process any @Import annotations processImports(configClass, sourceClass, getImports(sourceClass), true); - // process any @ImportResource annotations + // Process any @ImportResource annotations if (sourceClass.getMetadata().isAnnotated(ImportResource.class.getName())) { AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ImportResource.class); String[] resources = importResource.getStringArray("value"); @@ -271,18 +271,18 @@ class ConfigurationClassParser { } } - // process individual @Bean methods + // Process individual @Bean methods Set beanMethods = sourceClass.getMetadata().getAnnotatedMethods(Bean.class.getName()); for (MethodMetadata methodMetadata : beanMethods) { configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass)); } - // process superclass, if any + // Process superclass, if any if (sourceClass.getMetadata().hasSuperClass()) { String superclass = sourceClass.getMetadata().getSuperClassName(); if (!superclass.startsWith("java") && !this.knownSuperclasses.containsKey(superclass)) { this.knownSuperclasses.put(superclass, configClass); - // superclass found, return its annotation metadata and recurse + // Superclass found, return its annotation metadata and recurse try { return sourceClass.getSuperClass(); } @@ -292,7 +292,7 @@ class ConfigurationClassParser { } } - // no superclass, processing is complete + // No superclass, processing is complete return null; } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java index 1e68ba23d8..fb9508390e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.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. @@ -66,7 +66,7 @@ public abstract class PropertiesLoaderSupport { * Set local properties, e.g. via the "props" tag in XML bean definitions, * allowing for merging multiple properties sets into one. */ - public void setPropertiesArray(Properties[] propertiesArray) { + public void setPropertiesArray(Properties... propertiesArray) { this.localProperties = propertiesArray; } @@ -88,7 +88,7 @@ public abstract class PropertiesLoaderSupport { * Hence, make sure that the most specific files are the last * ones in the given list of locations. */ - public void setLocations(Resource[] locations) { + public void setLocations(Resource... locations) { this.locations = locations; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java index 6c9cdb0d19..6a44673f48 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java @@ -58,16 +58,15 @@ public final class FlashMap extends HashMap implements Comparabl /** * Provide a URL path to help identify the target request for this FlashMap. - * The path may be absolute (e.g. /application/resource) or relative to the - * current request (e.g. ../resource). - * @param path the URI path + *

The path may be absolute (e.g. "/application/resource") or relative to the + * current request (e.g. "../resource"). */ public void setTargetRequestPath(String path) { this.targetRequestPath = path; } /** - * Return the target URL path or {@code null}. + * Return the target URL path (or {@code null} if none specified). */ public String getTargetRequestPath() { return this.targetRequestPath; @@ -75,7 +74,7 @@ public final class FlashMap extends HashMap implements Comparabl /** * Provide request parameters identifying the request for this FlashMap. - * @param params a Map with the names and values of expected parameters. + * @param params a Map with the names and values of expected parameters */ public FlashMap addTargetRequestParams(MultiValueMap params) { if (params != null) { @@ -90,8 +89,8 @@ public final class FlashMap extends HashMap implements Comparabl /** * Provide a request parameter identifying the request for this FlashMap. - * @param name the expected parameter name, skipped if empty or {@code null} - * @param value the expected value, skipped if empty or {@code null} + * @param name the expected parameter name (skipped if empty or {@code null}) + * @param value the expected value (skipped if empty or {@code null}) */ public FlashMap addTargetRequestParam(String name, String value) { if (StringUtils.hasText(name) && StringUtils.hasText(value)) { @@ -117,18 +116,15 @@ public final class FlashMap extends HashMap implements Comparabl } /** - * Whether this instance has expired depending on the amount of elapsed - * time since the call to {@link #startExpirationPeriod}. + * Return whether this instance has expired depending on the amount of + * elapsed time since the call to {@link #startExpirationPeriod}. */ public boolean isExpired() { - if (this.expirationStartTime != 0) { - return (System.currentTimeMillis() - this.expirationStartTime > this.timeToLive * 1000); - } - else { - return false; - } + return (this.expirationStartTime != 0 && + (System.currentTimeMillis() - this.expirationStartTime > this.timeToLive * 1000)); } + /** * Compare two FlashMaps and prefer the one that specifies a target URL * path or has more target URL parameters. Before comparing FlashMap diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/handler/BeanCreatingHandlerProvider.java b/spring-websocket/src/main/java/org/springframework/web/socket/handler/BeanCreatingHandlerProvider.java index 36ccc029ae..ed2661abd5 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/handler/BeanCreatingHandlerProvider.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/handler/BeanCreatingHandlerProvider.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. @@ -16,10 +16,7 @@ package org.springframework.web.socket.handler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -35,8 +32,6 @@ import org.springframework.util.Assert; */ public class BeanCreatingHandlerProvider implements BeanFactoryAware { - private static final Log logger = LogFactory.getLog(BeanCreatingHandlerProvider.class); - private final Class handlerType; private AutowireCapableBeanFactory beanFactory; @@ -49,41 +44,35 @@ public class BeanCreatingHandlerProvider implements BeanFactoryAware { @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof AutowireCapableBeanFactory) { this.beanFactory = (AutowireCapableBeanFactory) beanFactory; } } + public void destroy(T handler) { + if (this.beanFactory != null) { + this.beanFactory.destroyBean(handler); + } + } + + public Class getHandlerType() { return this.handlerType; } public T getHandler() { - if (logger.isTraceEnabled()) { - logger.trace("Creating instance for handler type " + this.handlerType); - } - if (this.beanFactory == null) { - logger.warn("No BeanFactory available, attempting to use default constructor"); - return BeanUtils.instantiate(this.handlerType); - } - else { + if (this.beanFactory != null) { return this.beanFactory.createBean(this.handlerType); } - } - - public void destroy(T handler) { - if (this.beanFactory != null) { - if (logger.isTraceEnabled()) { - logger.trace("Destroying handler instance " + handler); - } - this.beanFactory.destroyBean(handler); + else { + return BeanUtils.instantiate(this.handlerType); } } @Override public String toString() { - return "BeanCreatingHandlerProvider [handlerClass=" + this.handlerType + "]"; + return "BeanCreatingHandlerProvider[handlerType=" + this.handlerType + "]"; } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java index bf8da81ff4..b70f9377bf 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.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. @@ -28,7 +28,6 @@ import javax.websocket.HandshakeResponse; import javax.websocket.server.HandshakeRequest; import javax.websocket.server.ServerEndpointConfig; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.util.Assert; @@ -50,7 +49,6 @@ import org.springframework.web.socket.handler.BeanCreatingHandlerProvider; * * @author Rossen Stoyanchev * @since 4.0 - * * @see ServerEndpointExporter */ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurator @@ -169,12 +167,13 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato } @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + public void setBeanFactory(BeanFactory beanFactory) { if (this.endpointProvider != null) { this.endpointProvider.setBeanFactory(beanFactory); } } + // Implementations of ServerEndpointConfig.Configurator @SuppressWarnings("unchecked")