Polishing

This commit is contained in:
Juergen Hoeller
2014-08-21 18:41:23 +02:00
parent 11805b6a5d
commit 86c5880888
2 changed files with 18 additions and 24 deletions

View File

@@ -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,32 +44,32 @@ 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 Class<? extends T> getHandlerType() {
return this.handlerType;
}
public T getHandler() {
if (this.beanFactory == null) {
logger.warn("No BeanFactory available, attempting to use default constructor");
return BeanUtils.instantiate(this.handlerType);
}
else {
return this.beanFactory.createBean(this.handlerType);
}
}
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 (this.beanFactory != null) {
return this.beanFactory.createBean(this.handlerType);
}
else {
return BeanUtils.instantiate(this.handlerType);
}
}
@Override
public String toString() {
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")