From 5a9a21bceedbc1b8f83451f17229c035a3ef1d08 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 18 Oct 2011 15:58:05 -0400 Subject: [PATCH] Refactored FileWritingMessageHandlerFactoryBean Brought FileWritingMessageHandlerFactoryBean into the hierarchy of AbstractSimpleMessageHandlerFactoryBean --- ...stractSimpleMessageHandlerFactoryBean.java | 11 +- ...ractStandardMessageHandlerFactoryBean.java | 2 +- .../ExpressionControlBusFactoryBean.java | 2 +- .../FileWritingMessageHandlerFactoryBean.java | 137 +++++------------- .../config/GroovyControlBusFactoryBean.java | 2 +- 5 files changed, 46 insertions(+), 108 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java index 4c82b6d8a8..61f79fd5f2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java @@ -27,10 +27,11 @@ import org.springframework.util.Assert; /** * @author Dave Syer + * @author Oleg Zhurakousky */ -public abstract class AbstractSimpleMessageHandlerFactoryBean implements FactoryBean, BeanFactoryAware { +public abstract class AbstractSimpleMessageHandlerFactoryBean implements FactoryBean, BeanFactoryAware { - private volatile MessageHandler handler; + private volatile M handler; private volatile MessageChannel outputChannel; @@ -63,7 +64,7 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean implements Factory return this.beanFactory; } - public MessageHandler getObject() throws Exception { + public M getObject() throws Exception { if (this.handler == null) { this.handler = this.createHandlerInternal(); Assert.notNull(this.handler, "failed to create MessageHandler"); @@ -80,7 +81,7 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean implements Factory return this.handler; } - protected final MessageHandler createHandlerInternal() { + protected final M createHandlerInternal() { synchronized (this.initializationMonitor) { if (this.initialized) { // There was a problem when this method was called already @@ -103,7 +104,7 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean implements Factory return handler; } - protected abstract MessageHandler createHandler(); + protected abstract M createHandler(); public Class getObjectType() { if (this.handler != null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractStandardMessageHandlerFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractStandardMessageHandlerFactoryBean.java index 0b64b7fe69..c2881d9f93 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractStandardMessageHandlerFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractStandardMessageHandlerFactoryBean.java @@ -30,7 +30,7 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @author Alexander Peters */ -abstract class AbstractStandardMessageHandlerFactoryBean extends AbstractSimpleMessageHandlerFactoryBean { +abstract class AbstractStandardMessageHandlerFactoryBean extends AbstractSimpleMessageHandlerFactoryBean{ private static final ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionControlBusFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionControlBusFactoryBean.java index f26c7f46a6..179f9b86b3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionControlBusFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ExpressionControlBusFactoryBean.java @@ -37,7 +37,7 @@ import org.springframework.util.ReflectionUtils; * @author Oleg Zhurakousky * @since 2.0 */ -public class ExpressionControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean { +public class ExpressionControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean { private volatile Long sendTimeout; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileWritingMessageHandlerFactoryBean.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileWritingMessageHandlerFactoryBean.java index fd7b35bb01..7e2494d12d 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileWritingMessageHandlerFactoryBean.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileWritingMessageHandlerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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,72 +16,39 @@ package org.springframework.integration.file.config; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.integration.MessageChannel; +import java.io.File; + +import org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean; import org.springframework.integration.file.FileNameGenerator; import org.springframework.integration.file.FileWritingMessageHandler; -import org.springframework.integration.support.channel.ChannelResolver; - -import java.io.File; /** * @author Mark Fisher * @author Iwein Fuld + * @author Oleg Zhurakousky * @since 1.0.3 */ -public class FileWritingMessageHandlerFactoryBean implements FactoryBean, BeanFactoryAware { - - private volatile FileWritingMessageHandler handler; - - private volatile BeanFactory beanFactory; - +public class FileWritingMessageHandlerFactoryBean extends AbstractSimpleMessageHandlerFactoryBean{ + private volatile File directory; - private volatile MessageChannel outputChannel; - - private volatile ChannelResolver channelResolver; - private volatile String charset; - + private volatile FileNameGenerator fileNameGenerator; - + private volatile Boolean deleteSourceFiles; - + private volatile Boolean autoCreateDirectory; - + private volatile Boolean requiresReply; - + private volatile Long sendTimeout; - - private volatile Integer order; private volatile String temporaryFileSuffix; - - private final Object initializationMonitor = new Object(); - - - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; - } - + public void setDirectory(File directory) { this.directory = directory; } - - public void setTemporaryFileSuffix(String temporaryFileSuffix) { - this.temporaryFileSuffix = temporaryFileSuffix; - } - - public void setOutputChannel(MessageChannel outputChannel) { - this.outputChannel = outputChannel; - } - - public void setChannelResolver(ChannelResolver channelResolver) { - this.channelResolver = channelResolver; - } public void setCharset(String charset) { this.charset = charset; @@ -107,62 +74,32 @@ public class FileWritingMessageHandlerFactoryBean implements FactoryBean getObjectType() { - return FileWritingMessageHandler.class; - } - - public boolean isSingleton() { - return true; - } - - private void initHandler() { - synchronized (this.initializationMonitor) { - if (this.handler != null) { - return; - } - this.handler = new FileWritingMessageHandler(this.directory); - if (this.outputChannel != null) { - this.handler.setOutputChannel(this.outputChannel); - } - if (this.channelResolver != null) { - this.handler.setChannelResolver(this.channelResolver); - } - if (this.charset != null) { - this.handler.setCharset(this.charset); - } - if (this.fileNameGenerator != null) { - this.handler.setFileNameGenerator(this.fileNameGenerator); - } - if (this.deleteSourceFiles != null) { - this.handler.setDeleteSourceFiles(this.deleteSourceFiles); - } - if (this.autoCreateDirectory != null) { - this.handler.setAutoCreateDirectory(this.autoCreateDirectory); - } - if (this.requiresReply != null) { - this.handler.setRequiresReply(this.requiresReply); - } - if (this.sendTimeout != null) { - this.handler.setSendTimeout(this.sendTimeout); - } - if (this.order != null) { - this.handler.setOrder(this.order); - } - this.handler.setTemporaryFileSuffix(this.temporaryFileSuffix); - this.handler.setBeanFactory(this.beanFactory); - this.handler.afterPropertiesSet(); + if (this.fileNameGenerator != null) { + handler.setFileNameGenerator(this.fileNameGenerator); } + if (this.deleteSourceFiles != null) { + handler.setDeleteSourceFiles(this.deleteSourceFiles); + } + if (this.autoCreateDirectory != null) { + handler.setAutoCreateDirectory(this.autoCreateDirectory); + } + if (this.requiresReply != null) { + handler.setRequiresReply(this.requiresReply); + } + if (this.sendTimeout != null) { + handler.setSendTimeout(this.sendTimeout); + } + handler.setTemporaryFileSuffix(this.temporaryFileSuffix); + return handler; } - } diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java index 715d1b7049..94b84b8e62 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java @@ -38,7 +38,7 @@ import org.springframework.util.CustomizableThreadCreator; * @author Mark Fisher * @since 2.0 */ -public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean { +public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean { private volatile Long sendTimeout;