Minor formatting changes.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user