Polishing

This commit is contained in:
Juergen Hoeller
2014-08-22 00:14:10 +02:00
parent 39a23660fa
commit e324c2ab4a
5 changed files with 39 additions and 55 deletions

View File

@@ -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<MethodMetadata> 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;
}

View File

@@ -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;
}

View File

@@ -58,16 +58,15 @@ public final class FlashMap extends HashMap<String, Object> 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
* <p>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<String, Object> 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<String, String> params) {
if (params != null) {
@@ -90,8 +89,8 @@ public final class FlashMap extends HashMap<String, Object> 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<String, Object> 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

View File

@@ -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<T> implements BeanFactoryAware {
private static final Log logger = LogFactory.getLog(BeanCreatingHandlerProvider.class);
private final Class<? extends T> handlerType;
private AutowireCapableBeanFactory beanFactory;
@@ -49,41 +44,35 @@ public class BeanCreatingHandlerProvider<T> 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<? extends T> 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 + "]";
}
}

View File

@@ -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")