diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java index fcafa5388b..12b826b556 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java @@ -16,6 +16,8 @@ package org.springframework.integration.adapter.file.config; +import org.w3c.dom.Element; + import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.integration.ConfigurationException; @@ -23,7 +25,6 @@ import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator; import org.springframework.integration.adapter.file.FileMessageCreator; import org.springframework.integration.adapter.file.TextFileMessageCreator; import org.springframework.util.StringUtils; -import org.w3c.dom.Element; /** * Base class for directory-based sources. @@ -32,53 +33,48 @@ import org.w3c.dom.Element; */ public abstract class AbstractDirectorySourceParser extends AbstractSimpleBeanDefinitionParser { - private static final String FILE_SOURCE_TYPE_ATTRIBUTE = "file"; - - private static final String TEXT_SOURCE_TYPE_ATTRIBUTE = "text"; - - private static final String BINARY_SOURCE_TYPE_ATTRIBUTE = "binary"; - public static final String MESSAGE_CREATOR_REFERENCE_ATTRIBUTE = "message-creator"; public static final String TYPE_ATTRIBUTE = "type"; - - + + private final boolean deleteFileAfterMessageCreation; - + + public AbstractDirectorySourceParser(boolean deleteFileAfterMessageCreation){ this.deleteFileAfterMessageCreation = deleteFileAfterMessageCreation; } - - + + @Override protected boolean isEligibleAttribute(String attributeName) { - return !( MESSAGE_CREATOR_REFERENCE_ATTRIBUTE.equals(attributeName) - || TYPE_ATTRIBUTE.equals(attributeName)) + return !MESSAGE_CREATOR_REFERENCE_ATTRIBUTE.equals(attributeName) + && !TYPE_ATTRIBUTE.equals(attributeName) && super.isEligibleAttribute(attributeName); } - + @Override protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { String messageCreatorReference = element.getAttribute(MESSAGE_CREATOR_REFERENCE_ATTRIBUTE); String type = element.getAttribute(TYPE_ATTRIBUTE); if (StringUtils.hasText(type) && StringUtils.hasText(messageCreatorReference)) { throw new ConfigurationException( - "Either the 'type' or the 'message-creator' attributes are allowed, but not both"); + "Either the 'type' or the 'message-creator' attributes are allowed, but not both."); } if (StringUtils.hasText(messageCreatorReference)) { beanDefinition.addConstructorArgReference(messageCreatorReference); } else { - if (!StringUtils.hasText(type) || FILE_SOURCE_TYPE_ATTRIBUTE.equals(type)) { - beanDefinition.addConstructorArgValue(new FileMessageCreator()); - } - else if (TEXT_SOURCE_TYPE_ATTRIBUTE.equals(type)) { + if ("text".equals(type)) { beanDefinition.addConstructorArgValue(new TextFileMessageCreator(deleteFileAfterMessageCreation)); } - else if (BINARY_SOURCE_TYPE_ATTRIBUTE.equals(type)) { + else if ("binary".equals(type)) { beanDefinition.addConstructorArgValue(new ByteArrayFileMessageCreator(deleteFileAfterMessageCreation)); } + else { + beanDefinition.addConstructorArgValue(new FileMessageCreator()); + } } } - + } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java index 2586f818e3..808fff2eae 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java @@ -16,9 +16,10 @@ package org.springframework.integration.adapter.file.config; +import org.w3c.dom.Element; + import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.integration.adapter.file.FileSource; -import org.w3c.dom.Element; /** * Parser for the <file-source/> element. @@ -30,10 +31,12 @@ public class FileSourceParser extends AbstractDirectorySourceParser { public static final String DIRECTORY_ATTRIBUTE = "directory"; + public FileSourceParser() { super(false); } + @Override protected Class getBeanClass(Element element) { return FileSource.class; @@ -41,7 +44,7 @@ public class FileSourceParser extends AbstractDirectorySourceParser { @Override protected boolean isEligibleAttribute(String attributeName) { - return !(DIRECTORY_ATTRIBUTE.equals(attributeName)) && super.isEligibleAttribute(attributeName); + return !DIRECTORY_ATTRIBUTE.equals(attributeName) && super.isEligibleAttribute(attributeName); } @Override diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java index 024552d7d6..980c770469 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java @@ -16,10 +16,10 @@ package org.springframework.integration.adapter.ftp.config; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; +import org.w3c.dom.Element; + import org.springframework.integration.adapter.file.config.AbstractDirectorySourceParser; import org.springframework.integration.adapter.ftp.FtpSource; -import org.w3c.dom.Element; /** * Parser for the <ftp-source/> element. @@ -28,14 +28,15 @@ import org.w3c.dom.Element; * @author Marius Bogoevici */ public class FtpSourceParser extends AbstractDirectorySourceParser { - + public FtpSourceParser() { super(true); } + @Override protected Class getBeanClass(Element element) { return FtpSource.class; } - + } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java index 332914ca46..e30ef276de 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java @@ -23,6 +23,7 @@ import static org.junit.Assert.fail; import java.io.File; import org.junit.Test; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.context.ApplicationContext; @@ -49,7 +50,7 @@ public class FileSourceParserTests { assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath()); assertTrue(messageCreator instanceof FileMessageCreator); } - + @Test public void testFileSourceTextType() { ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass()); @@ -60,7 +61,7 @@ public class FileSourceParserTests { assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath()); assertTrue(messageCreator instanceof TextFileMessageCreator); } - + @Test public void testFileSourceBinaryType() { ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass()); @@ -71,7 +72,7 @@ public class FileSourceParserTests { assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath()); assertTrue(messageCreator instanceof ByteArrayFileMessageCreator); } - + @Test public void testFileSourceFileType() { ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass()); @@ -82,7 +83,7 @@ public class FileSourceParserTests { assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath()); assertTrue(messageCreator instanceof FileMessageCreator); } - + @Test public void testFileSourceCustomType() { ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass()); @@ -93,15 +94,15 @@ public class FileSourceParserTests { assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath()); assertTrue(messageCreator instanceof CustomMessageCreator); } - + @Test public void testInvalidFileSource() { try { - ApplicationContext context = new ClassPathXmlApplicationContext("invalidFileSourceTests.xml", this.getClass()); + new ClassPathXmlApplicationContext("invalidFileSourceTests.xml", this.getClass()); fail(); } catch (BeanDefinitionStoreException e) { assertTrue(e.getCause() instanceof ConfigurationException); } } - + } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java index 5218a1bbb9..e575d0740d 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java @@ -23,6 +23,7 @@ import static org.junit.Assert.fail; import java.io.File; import org.junit.Test; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.context.ApplicationContext; @@ -128,8 +129,7 @@ public class FtpSourceParserTests { @Test public void testInvalidFtpSource() { try { - ApplicationContext context = new ClassPathXmlApplicationContext("invalidFtpSourceTests.xml", this - .getClass()); + new ClassPathXmlApplicationContext("invalidFtpSourceTests.xml", this.getClass()); fail(); } catch (BeanDefinitionStoreException e) {