OPEN - issue INT-364: add namespace support to file project
http://jira.springframework.org/browse/INT-364 Added basic namespace support and parser test. Made inputDirectory a Resource instead of a File
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.integration.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
@@ -25,7 +26,7 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
@@ -48,7 +49,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class PollableFileSource implements PollableSource<File>, MessageDeliveryAware<File>, InitializingBean {
|
||||
public class PollableFileSource implements PollableSource<File>, MessageDeliveryAware<File> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(PollableFileSource.class);
|
||||
|
||||
@@ -58,8 +59,16 @@ public class PollableFileSource implements PollableSource<File>, MessageDelivery
|
||||
|
||||
private volatile FileListFilter filter = new AcceptOnceFileFilter();
|
||||
|
||||
public void setInputDirectory(File inputDirectory) {
|
||||
this.inputDirectory = inputDirectory;
|
||||
public void setInputDirectory(Resource inputDirectory) {
|
||||
Assert.notNull(inputDirectory, "inputDirectory cannot be null");
|
||||
Assert.isTrue(inputDirectory.exists(), inputDirectory + " doesn't exist.");
|
||||
try {
|
||||
this.inputDirectory = inputDirectory.getFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException("Unexpected IOException when looking for " + inputDirectory, e);
|
||||
}
|
||||
Assert.isTrue(this.inputDirectory.canRead(), "No read permissions on " + this.inputDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,12 +84,6 @@ public class PollableFileSource implements PollableSource<File>, MessageDelivery
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(inputDirectory, "inputDirectory cannot be null");
|
||||
Assert.isTrue(this.inputDirectory.exists(), inputDirectory + " doesn't exist.");
|
||||
Assert.isTrue(this.inputDirectory.canRead(), "No read permissions on " + inputDirectory);
|
||||
}
|
||||
|
||||
public Message<File> receive() throws MessagingException {
|
||||
refreshQueue();
|
||||
Message<File> message = null;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.AbstractPollingInboundChannelAdapterParser;
|
||||
import org.springframework.integration.file.PollableFileSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class FileInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
|
||||
|
||||
@Override
|
||||
protected String parseSource(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(PollableFileSource.class);
|
||||
String directory = element.getAttribute("directory");
|
||||
if (StringUtils.hasText(directory)) {
|
||||
builder.addPropertyValue("inputDirectory", directory);
|
||||
}
|
||||
String filter = element.getAttribute("filter");
|
||||
if (StringUtils.hasText(filter)){
|
||||
builder.addPropertyReference("filter", filter);
|
||||
}
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
public class FileNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("inbound-channel-adapter", new FileInboundChannelAdapterParser());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
targetNamespace="http://www.springframework.org/schema/integration/file"
|
||||
elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/integration"/>
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines the configuration elements for Spring Integration Stream-based Channel Adapters.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="inbound-channel-adapter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures a source that reads from stdin (System.in).
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="directory" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string"/>
|
||||
<xsd:attribute name="filter" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1 @@
|
||||
http\://www.springframework.org/schema/integration/file=org.springframework.integration.file.config.FileNamespaceHandler
|
||||
@@ -0,0 +1 @@
|
||||
http\://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd=org/springframework/integration/file/config/spring-integration-file-1.0.xsd
|
||||
Reference in New Issue
Block a user