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

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