From ad485e912464144e37bfcb35c72e024a8644858a Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 22 Nov 2010 00:48:05 -0500 Subject: [PATCH] INT-1614 moved outbound parsers into a single class in the file module --- ...emoteFileInboundChannelAdapterParser.java} | 2 +- ...emoteFileOutboundChannelAdapterParser.java | 61 +++++++------ .../FtpInboundChannelAdapterParser.java | 4 +- .../ftp/config/FtpNamespaceHandler.java | 3 +- .../SftpInboundChannelAdapterParser.java | 4 +- .../sftp/config/SftpNamespaceHandler.java | 3 +- .../SftpOutboundChannelAdapterParser.java | 89 ------------------- 7 files changed, 44 insertions(+), 122 deletions(-) rename spring-integration-file/src/main/java/org/springframework/integration/file/config/{AbstractRemoteInboundChannelAdapterParser.java => AbstractRemoteFileInboundChannelAdapterParser.java} (96%) rename spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java => spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java (58%) delete mode 100644 spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpOutboundChannelAdapterParser.java diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteInboundChannelAdapterParser.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java similarity index 96% rename from spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteInboundChannelAdapterParser.java rename to spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java index f8e691934d..67d2a17315 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteInboundChannelAdapterParser.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java @@ -33,7 +33,7 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @since 2.0 */ -public abstract class AbstractRemoteInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { +public abstract class AbstractRemoteFileInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { @Override protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) { diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java similarity index 58% rename from spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java rename to spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java index 61b35d8d44..d89cc8b817 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.ftp.config; +package org.springframework.integration.file.config; import org.w3c.dom.Element; @@ -33,51 +33,60 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @since 2.0 */ -public class FtpOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { +public class RemoteFileOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { @Override protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { - BeanDefinitionBuilder handlerBuilder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.integration.file.remote.handler.FileTransferringMessageHandler"); + // build SessionFactory BeanDefinitionBuilder sessionFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.integration.file.remote.session.CachingSessionFactory"); sessionFactoryBuilder.addConstructorArgReference(element.getAttribute("session-factory")); + + // build MessageHandler + BeanDefinitionBuilder handlerBuilder = BeanDefinitionBuilder.genericBeanDefinition( + "org.springframework.integration.file.remote.handler.FileTransferringMessageHandler"); handlerBuilder.addConstructorArgValue(sessionFactoryBuilder.getBeanDefinition()); + + // configure remote directory expression String remoteDirectory = element.getAttribute("remote-directory"); String remoteDirectoryExpression = element.getAttribute("remote-directory-expression"); - boolean hasDirectory = StringUtils.hasText(remoteDirectory); - boolean hasDirectoryExpression = StringUtils.hasText(remoteDirectoryExpression); - if (!(hasDirectory ^ hasDirectoryExpression)) { + boolean hasRemoteDirectory = StringUtils.hasText(remoteDirectory); + boolean hasRemoteDirectoryExpression = StringUtils.hasText(remoteDirectoryExpression); + if (!(hasRemoteDirectory ^ hasRemoteDirectoryExpression)) { throw new BeanDefinitionStoreException("exactly one of 'remote-directory' or 'remote-directory-expression' " + - "is required on the FTP outbound adapter"); + "is required on a remote file outbound adapter"); } - BeanDefinition expressionDef = null; - if (hasDirectory) { - expressionDef = new RootBeanDefinition("org.springframework.expression.common.LiteralExpression"); - expressionDef.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectory); + BeanDefinition remoteDirectoryExpressionDefinition = null; + if (hasRemoteDirectory) { + remoteDirectoryExpressionDefinition = new RootBeanDefinition("org.springframework.expression.common.LiteralExpression"); + remoteDirectoryExpressionDefinition.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectory); } - else if (hasDirectoryExpression) { - expressionDef = new RootBeanDefinition("org.springframework.integration.config.ExpressionFactoryBean"); - expressionDef.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectoryExpression); + else if (hasRemoteDirectoryExpression) { + remoteDirectoryExpressionDefinition = new RootBeanDefinition("org.springframework.integration.config.ExpressionFactoryBean"); + remoteDirectoryExpressionDefinition.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectoryExpression); } - handlerBuilder.addPropertyValue("remoteDirectoryExpression", expressionDef); - String remoteFileExpression = element.getAttribute("remote-filename-generator-expression"); - String fileNameGenerator = element.getAttribute("remote-filename-generator"); - boolean hasRemoteFileExpression = StringUtils.hasText(remoteFileExpression); - boolean hasFileNameGenerator = StringUtils.hasText(fileNameGenerator); - if (hasRemoteFileExpression || hasFileNameGenerator) { - if (hasRemoteFileExpression && hasFileNameGenerator) { + handlerBuilder.addPropertyValue("remoteDirectoryExpression", remoteDirectoryExpressionDefinition); + + // configure remote FileNameGenerator + String remoteFileNameGenerator = element.getAttribute("remote-filename-generator"); + String remoteFileNameGeneratorExpression = element.getAttribute("remote-filename-generator-expression"); + boolean hasRemoteFileNameGenerator = StringUtils.hasText(remoteFileNameGenerator); + boolean hasRemoteFileNameGeneratorExpression = StringUtils.hasText(remoteFileNameGeneratorExpression); + if (hasRemoteFileNameGenerator || hasRemoteFileNameGeneratorExpression) { + if (hasRemoteFileNameGenerator && hasRemoteFileNameGeneratorExpression) { throw new BeanDefinitionStoreException("at most one of 'remote-filename-generator-expression' or 'remote-filename-generator' " + - "is allowed on the FTP outbound adapter"); + "is allowed on a remote file outbound adapter"); } - if (StringUtils.hasText(remoteFileExpression)) { + if (hasRemoteFileNameGenerator) { + handlerBuilder.addPropertyReference("fileNameGenerator", remoteFileNameGenerator); + } + else { BeanDefinitionBuilder fileNameGeneratorBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.integration.file.DefaultFileNameGenerator"); - fileNameGeneratorBuilder.addPropertyValue("expression", remoteFileExpression); + fileNameGeneratorBuilder.addPropertyValue("expression", remoteFileNameGeneratorExpression); handlerBuilder.addPropertyValue("fileNameGenerator", fileNameGeneratorBuilder.getBeanDefinition()); } } - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, "remote-filename-generator", "fileNameGenerator"); IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "charset"); return handlerBuilder.getBeanDefinition(); } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java index 53902e96ae..b3e9e65041 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java @@ -16,13 +16,13 @@ package org.springframework.integration.ftp.config; -import org.springframework.integration.file.config.AbstractRemoteInboundChannelAdapterParser; +import org.springframework.integration.file.config.AbstractRemoteFileInboundChannelAdapterParser; /** * @author Mark Fisher * @since 2.0 */ -public class FtpInboundChannelAdapterParser extends AbstractRemoteInboundChannelAdapterParser { +public class FtpInboundChannelAdapterParser extends AbstractRemoteFileInboundChannelAdapterParser { private static final String BASE_PACKAGE = "org.springframework.integration.ftp"; diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java index 7b63e25088..a62cccee0f 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java @@ -17,6 +17,7 @@ package org.springframework.integration.ftp.config; import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler; +import org.springframework.integration.file.config.RemoteFileOutboundChannelAdapterParser; /** * Provides namespace support for using FTP @@ -31,7 +32,7 @@ public class FtpNamespaceHandler extends AbstractIntegrationNamespaceHandler { public void init() { registerBeanDefinitionParser("inbound-channel-adapter", new FtpInboundChannelAdapterParser()); - registerBeanDefinitionParser("outbound-channel-adapter", new FtpOutboundChannelAdapterParser()); + registerBeanDefinitionParser("outbound-channel-adapter", new RemoteFileOutboundChannelAdapterParser()); } } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java index 6b20a21f8d..35f690b8c0 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java @@ -16,7 +16,7 @@ package org.springframework.integration.sftp.config; -import org.springframework.integration.file.config.AbstractRemoteInboundChannelAdapterParser; +import org.springframework.integration.file.config.AbstractRemoteFileInboundChannelAdapterParser; /** * Parser for 'sftp:inbound-channel-adapter' @@ -24,7 +24,7 @@ import org.springframework.integration.file.config.AbstractRemoteInboundChannelA * @author Mark Fisher * @since 2.0 */ -public class SftpInboundChannelAdapterParser extends AbstractRemoteInboundChannelAdapterParser { +public class SftpInboundChannelAdapterParser extends AbstractRemoteFileInboundChannelAdapterParser { private static final String BASE_PACKAGE = "org.springframework.integration.sftp"; diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java index 23a58aa167..61c4279e25 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java @@ -17,6 +17,7 @@ package org.springframework.integration.sftp.config; import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler; +import org.springframework.integration.file.config.RemoteFileOutboundChannelAdapterParser; /** * Provides namespace support for using SFTP. @@ -31,6 +32,6 @@ public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler { public void init() { registerBeanDefinitionParser("inbound-channel-adapter", new SftpInboundChannelAdapterParser()); - registerBeanDefinitionParser("outbound-channel-adapter", new SftpOutboundChannelAdapterParser()); + registerBeanDefinitionParser("outbound-channel-adapter", new RemoteFileOutboundChannelAdapterParser()); } } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpOutboundChannelAdapterParser.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpOutboundChannelAdapterParser.java deleted file mode 100644 index 51c1cbae9d..0000000000 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpOutboundChannelAdapterParser.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.sftp.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser; -import org.springframework.integration.config.xml.IntegrationNamespaceUtils; -import org.springframework.util.StringUtils; - -/** - * Parser for the 'sftp:outbound-channel-adapter' element. - * - * @author Oleg Zhurakousky - * @since 2.0 - */ -public class SftpOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { - - @Override - protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { - BeanDefinitionBuilder sessionPoolBuilder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.integration.file.remote.session.CachingSessionFactory"); - sessionPoolBuilder.addConstructorArgReference(element.getAttribute("session-factory")); - String sessionPoolName = BeanDefinitionReaderUtils.registerWithGeneratedName( - sessionPoolBuilder.getBeanDefinition(), parserContext.getRegistry()); - BeanDefinitionBuilder handlerBuilder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.integration.file.remote.handler.FileTransferringMessageHandler"); - handlerBuilder.addConstructorArgReference(sessionPoolName); - IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "charset"); - String remoteDirectory = element.getAttribute("remote-directory"); - String remoteDirectoryExpression = element.getAttribute("remote-directory-expression"); - boolean hasDirectory = StringUtils.hasText(remoteDirectory); - boolean hasDirectoryExpression = StringUtils.hasText(remoteDirectoryExpression); - if (!(hasDirectory ^ hasDirectoryExpression)) { - throw new BeanDefinitionStoreException("exactly one of 'remote-directory' or 'remote-directory-expression' " + - "is required on the SFTP outbound adapter"); - } - BeanDefinition expressionDef = null; - if (hasDirectory) { - expressionDef = new RootBeanDefinition("org.springframework.expression.common.LiteralExpression"); - expressionDef.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectory); - } - else if (hasDirectoryExpression) { - expressionDef = new RootBeanDefinition("org.springframework.integration.config.ExpressionFactoryBean"); - expressionDef.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectoryExpression); - } - handlerBuilder.addPropertyValue("remoteDirectoryExpression", expressionDef); - String remoteFileExpression = element.getAttribute("remote-filename-generator-expression"); - String fileNameGenerator = element.getAttribute("remote-filename-generator"); - boolean hasRemoteFileExpression = StringUtils.hasText(remoteFileExpression); - boolean hasFileNameGenerator = StringUtils.hasText(fileNameGenerator); - if (hasRemoteFileExpression || hasFileNameGenerator) { - if (hasRemoteFileExpression && hasFileNameGenerator) { - throw new BeanDefinitionStoreException("at most one of 'remote-filename-generator-expression' or 'remote-filename-generator' " + - "is allowed on the SFTP outbound adapter"); - } - if (StringUtils.hasText(remoteFileExpression)) { - BeanDefinitionBuilder fileNameGeneratorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.integration.file.DefaultFileNameGenerator"); - fileNameGeneratorBuilder.addPropertyValue("expression", remoteFileExpression); - handlerBuilder.addPropertyValue("fileNameGenerator", fileNameGeneratorBuilder.getBeanDefinition()); - } - } - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, "remote-filename-generator", "fileNameGenerator"); - return handlerBuilder.getBeanDefinition(); - } - -}