From 5a702033490fd1f9ef6d136ad46c6de5b89eb4c4 Mon Sep 17 00:00:00 2001 From: Iwein Fuld Date: Sun, 17 Aug 2008 05:47:46 +0000 Subject: [PATCH] Finishing up INT-293, INT-154. Parametrized DefaultMessageMapper, refactored FtpSource to use a pool, added namespace support for FtpTarget. --- .../adapter/ftp/config/FtpTargetParser.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java new file mode 100644 index 0000000000..36611d8719 --- /dev/null +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java @@ -0,0 +1,73 @@ +/* + * Copyright 2002-2008 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.adapter.ftp.config; + +import java.io.File; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; +import org.springframework.integration.adapter.ftp.FtpTarget; +import org.springframework.integration.adapter.ftp.QueuedFTPClientPool; +import org.springframework.integration.message.DefaultMessageMapper; +import org.w3c.dom.Element; + +public class FtpTargetParser extends AbstractSimpleBeanDefinitionParser { + private static final String POOL_ATTRIBUTE_USER = "username"; + + private static final String POOL_ATTRIBUTE_PASS = "password"; + + private static final String POOL_ATTRIBUTE_HOST = "host"; + + private static final String POOL_ATTRIBUTE_PORT = "port"; + + private static final String POOL_ATTRIBUTE_REMOTEDIR = "remote-working-directory"; + + @Override + protected Class getBeanClass(Element element) { + return FtpTarget.class; + } + + @Override + protected boolean isEligibleAttribute(String attributeName) { + return !POOL_ATTRIBUTE_HOST.equals(attributeName) && !POOL_ATTRIBUTE_PASS.equals(attributeName) + && !POOL_ATTRIBUTE_PORT.equals(attributeName) && !POOL_ATTRIBUTE_USER.equals(attributeName) + && !POOL_ATTRIBUTE_REMOTEDIR.equals(attributeName) && super.isEligibleAttribute(attributeName); + } + + @Override + protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { + super.postProcess(beanDefinition, element); + QueuedFTPClientPool queuedFTPClientPool = constructFTPClientPool(element); + beanDefinition.addConstructorArgValue(queuedFTPClientPool); + beanDefinition.addConstructorArgValue(new DefaultMessageMapper()); + } + + private QueuedFTPClientPool constructFTPClientPool(Element element) { + String user = element.getAttribute(POOL_ATTRIBUTE_USER); + String pass = element.getAttribute(POOL_ATTRIBUTE_PASS); + String host = element.getAttribute(POOL_ATTRIBUTE_HOST); + String port = element.getAttribute(POOL_ATTRIBUTE_PORT); + String remoteWorkingDirectory = element.getAttribute(POOL_ATTRIBUTE_REMOTEDIR); + QueuedFTPClientPool queuedFTPClientPool = new QueuedFTPClientPool(); + queuedFTPClientPool.setUsername(user); + queuedFTPClientPool.setPassword(pass); + queuedFTPClientPool.setHost(host); + queuedFTPClientPool.setPort(Integer.parseInt(port)); + queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory); + return queuedFTPClientPool; + } +}