Removing 'file' package contents from 'org.springframework.integration.adapter'. The new 'org.springframework.integration.file' module replaces it.

This commit is contained in:
Mark Fisher
2008-09-22 05:17:30 +00:00
parent 845474263d
commit b7756e881d
40 changed files with 49 additions and 1551 deletions

View File

@@ -1,82 +0,0 @@
/*
* 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.file;
import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageCreator;
import org.springframework.integration.message.MessagingException;
/**
* Base class providing common behavior for file-based message creators. The
* subclasses will redefine the {@code readMessagePayload()} method. This class
* allows to choose between keeping the file after message creation and removing
* it, by setting the appropriate value in the constructor. The desired
* behaviour depends on the nature of the created message (i.e. messages with a
* {@link String} payload can safely remove the file after creation, but
* messages with a {@link File} payload cannot do that) or of the collaborator
* that uses the class instance (e.g. if the file is a locally created copy, it
* can be always discarded).
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
public abstract class AbstractFileMessageCreator<T> implements MessageCreator<File, T> {
protected Log logger = LogFactory.getLog(this.getClass());
private final boolean deleteFileAfterCreation;
/**
* @param deleteFileAfterCreation Indicates whether the file should be
* deleted after the message has been created.
*/
public AbstractFileMessageCreator(boolean deleteFileAfterCreation) {
this.deleteFileAfterCreation = deleteFileAfterCreation;
}
public final Message<T> createMessage(File file) {
try {
T payload = this.readMessagePayload(file);
if (payload == null) {
return null;
}
Message<T> message = new GenericMessage<T>(payload);
if (this.deleteFileAfterCreation) {
file.delete();
}
return message;
}
catch (Exception e) {
String description = "failure occurred mapping file to message";
if (logger.isWarnEnabled()) {
logger.warn(description, e);
}
throw new MessagingException(description, e);
}
}
protected abstract T readMessagePayload(File file) throws Exception;
}

View File

@@ -1,47 +0,0 @@
/*
* 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.file;
import java.io.File;
import org.springframework.util.FileCopyUtils;
/**
* A {@link org.springframework.integration.message.MessageCreator}
* implementation for messages with a byte array payload.
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class ByteArrayFileMessageCreator extends AbstractFileMessageCreator<byte[]> {
/**
* Specifies whether the file should be removed after the message has been created.
* See {@link AbstractFileMessageCreator}
* @param deleteFilesAfterMessageCreation
*/
public ByteArrayFileMessageCreator(boolean deleteFilesAfterMessageCreation) {
super(deleteFilesAfterMessageCreation);
}
@Override
protected byte[] readMessagePayload(File file) throws Exception {
return FileCopyUtils.copyToByteArray(file);
}
}

View File

@@ -1,36 +0,0 @@
/*
* 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.file;
import org.springframework.integration.message.Message;
import org.springframework.util.StringUtils;
/**
* Default implementation of the filename generator strategy. Concatenates the
* message id and the current timestamp.
*
* @author Mark Fisher
*/
public class DefaultFileNameGenerator implements FileNameGenerator {
public String generateFileName(Message<?> message) {
String filenameProperty = message.getHeaders().get(FILENAME_PROPERTY_KEY, String.class);
return StringUtils.hasText(filenameProperty) ?
filenameProperty : message.getHeaders().getId() + ".msg";
}
}

View File

@@ -1,43 +0,0 @@
/*
* 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.file;
import java.io.File;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageCreator;
/**
* A {@link MessageCreator} that creates {@link Message} instances with the
* absolute path to the {@link File} as payload.
*
* @author Marius Bogoevici
*/
public class FileMessageCreator extends AbstractFileMessageCreator<File> {
public FileMessageCreator() {
// The file should never be removed, as just the reference to it is
// passed to the message
super(false);
}
@Override
protected File readMessagePayload(File file) throws Exception {
return file;
}
}

View File

@@ -1,33 +0,0 @@
/*
* 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.file;
import org.springframework.integration.message.Message;
/**
* Strategy interface for generating a file name from a message.
*
* @author Mark Fisher
*/
public interface FileNameGenerator {
String FILENAME_PROPERTY_KEY = "filename";
String generateFileName(Message<?> message);
}

View File

@@ -1,160 +0,0 @@
/*
* 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.file;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import org.springframework.core.io.Resource;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageCreator;
import org.springframework.integration.message.MessageDeliveryAware;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
/**
* A messaging source that polls a directory to retrieve files.
*
* @deprecated Replaced by org.springframework.integration.file.PollableFileSource.
*
* @author Mark Fisher
* @author Marius Bogoevici
* @author Iwein Fuld
*/
public class FileSource extends AbstractDirectorySource<File> implements MessageDeliveryAware<File> {
private final File directory;
private volatile FileFilter fileFilter;
private volatile FilenameFilter filenameFilter;
/**
* Creates a default FileSource on the specified directory
* @param directory
*/
public FileSource(Resource directory) {
this(directory, new FileMessageCreator(), null);
}
public FileSource(Resource directory, Comparator<FileSnapshot> comparator) {
this(directory, new FileMessageCreator(), comparator);
}
public FileSource(Resource directory, MessageCreator<File, File> messageCreator) {
this(directory, messageCreator, null);
}
/**
* Creates a FileSource with the specified strategies.
* @param directory
* @param messageCreator the MessageCreator used to convert Files into
* Messages
* @param comparator the comparator is used to order the backlog. If
* <code>null</code> natural order is used.
*/
public FileSource(Resource directory, MessageCreator<File, File> messageCreator, Comparator<FileSnapshot> comparator) {
super(messageCreator, comparator);
Assert.notNull(directory, "The directory must not be null");
try {
this.directory = directory.getFile();
if (!this.directory.isDirectory()) {
throw new ConfigurationException("The FileSource can't be instantiated because "
+ this.directory.getAbsolutePath() + " is not a directory.");
}
}
catch (IOException e) {
throw new ConfigurationException("The FileSource can't be instantiated", e);
}
}
@Override
protected Message<File> buildNextMessage() throws IOException {
File file = retrieveNextPayload();
Message<File> message = this.getMessageCreator().createMessage(file);
message = MessageBuilder.fromMessage(message)
.setHeader(FileNameGenerator.FILENAME_PROPERTY_KEY, file.getName()).setHeader(FILE_INFO_PROPERTY,
getBacklog().getProcessingBuffer().get(0)).build();
return message;
}
/**
* Sets a FilenameFilter to be used with the
* <code>{@link File#listFiles()}</code> command. Note that either a
* FileFilter or a FilenameFilter is used to filter the list of files.
* Calling this setter overwrites the FileNameFilter if it was set before.
* @param fileFilter
*/
public void setFileFilter(FileFilter fileFilter) {
Assert.notNull(fileFilter);
this.filenameFilter = null;
this.fileFilter = fileFilter;
}
/**
* Sets a FilenameFilter to be used with the
* <code>{@link File#listFiles()}</code> command. Note that either a
* FileFilter or a FilenameFilter is used to filter the list of files.
* Calling this setter overwrites the FileFilter if it was set before.
* @param filenameFilter
*/
public void setFilenameFilter(FilenameFilter filenameFilter) {
Assert.notNull(filenameFilter);
this.fileFilter = null;
this.filenameFilter = filenameFilter;
}
@Override
protected void populateSnapshot(List<FileSnapshot> snapshot) throws IOException {
File[] files;
if (this.fileFilter != null) {
files = this.directory.listFiles(this.fileFilter);
}
else if (this.filenameFilter != null) {
files = this.directory.listFiles(this.filenameFilter);
}
else {
files = this.directory.listFiles();
}
if (files == null) {
throw new MessagingException("Problem occurred while polling for files. " + "Is '"
+ directory.getAbsolutePath() + "' a directory?");
}
for (File file : files) {
FileSnapshot fileInfo = new FileSnapshot(file);
snapshot.add(fileInfo);
}
}
@Override
protected File retrieveNextPayload() throws IOException {
List<FileSnapshot> selectedForProcessing = this.getBacklog().selectForProcessing(1);
if (!selectedForProcessing.isEmpty()) {
return selectedForProcessing.get(0).getFile();
}
else {
return null;
}
}
}

View File

@@ -1,45 +0,0 @@
/*
* 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.file;
import java.io.File;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageConsumer;
import org.springframework.integration.message.MessageMapper;
/**
* A message target for writing files. The actual file writing occurs in the
* message mapper.
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class FileTarget implements MessageConsumer {
private MessageMapper<?, File> messageMapper;
public FileTarget(MessageMapper<?, File> messageMapper) {
this.messageMapper = messageMapper;
}
public void onMessage(Message message) {
this.messageMapper.mapMessage(message);
}
}

View File

@@ -1,46 +0,0 @@
/*
* 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.file;
import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;
import org.springframework.util.Assert;
/**
* A {@link FilenameFilter} implementation for matching against
* a regular expression {@link Pattern}.
*
* @author Mark Fisher
*/
public class RegexPatternFilenameFilter implements FilenameFilter {
private volatile Pattern pattern;
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
public boolean accept(File dir, String name) {
Assert.notNull(pattern, "pattern must not be null");
return (name != null) && this.pattern.matcher(name).matches();
}
}

View File

@@ -1,79 +0,0 @@
/*
* 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.file;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessageMapper;
import org.springframework.util.FileCopyUtils;
/**
* A default {@link MessageMapper} for {@link FileTarget}, converting payloads of the
* {@link File}, {@code byte[]} and {@link String} types to files. The name of the newly
* created file is defined by the {@link FileNameGenerator} instance configured with it.
* By default, it uses a {@link DefaultFileNameGenerator}.
*
* @author Marius Bogoevici
*/
public class SimpleFileMessageMapper implements MessageMapper<Object, File> {
private volatile FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
private final File parentDirectory;
public SimpleFileMessageMapper(String parentDirectoryPath) {
this(new File(parentDirectoryPath));
}
public SimpleFileMessageMapper(File parentDirectory) {
this.parentDirectory = parentDirectory;
}
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
this.fileNameGenerator = fileNameGenerator;
}
public File mapMessage(Message<Object> message) {
try {
File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message));
this.writeToFile(file, message.getPayload());
return file;
}
catch (Exception e) {
throw new MessageHandlingException(message, "failure occurred mapping file to message", e);
}
}
public void writeToFile(File file, Object payload) throws IOException {
if (payload instanceof byte[]) {
FileCopyUtils.copy((byte[]) payload, file);
}
else if (payload instanceof String) {
FileCopyUtils.copy((String) payload, new FileWriter(file));
}
else if (payload instanceof File) {
FileCopyUtils.copy((File) payload, file);
}
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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.file;
import java.io.File;
import java.io.FileReader;
import org.springframework.util.FileCopyUtils;
/**
* A {@link org.springframework.integration.message.MessageCreator}
* implementation for creating messages with a String payload from a File.
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class TextFileMessageCreator extends AbstractFileMessageCreator<String> {
/**
* Specifies whether the file should be removed after the message has been created.
* See {@link AbstractFileMessageCreator}
* @param deleteFilesAfterMessageCreation
*/
public TextFileMessageCreator(boolean deleteFilesAfterMessageCreation) {
super(deleteFilesAfterMessageCreation);
}
@Override
protected String readMessagePayload(File file) throws Exception {
return FileCopyUtils.copyToString(new FileReader(file));
}
}

View File

@@ -1,128 +0,0 @@
/*
* 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.file.config;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.core.io.ResourceLoader;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator;
import org.springframework.integration.adapter.file.FileSource;
import org.springframework.integration.adapter.file.RegexPatternFilenameFilter;
import org.springframework.integration.adapter.file.TextFileMessageCreator;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Parser for the &lt;file-source/&gt; element.
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class FileSourceParser extends AbstractDirectorySourceParser {
public static final String TYPE_ATTRIBUTE = "type";
public static final String DIRECTORY_ATTRIBUTE = "directory";
public static final String FILE_FILTER_ATTRIBUTE = "file-filter";
public static final String FILENAME_FILTER_ATTRIBUTE = "filename-filter";
public static final String FILENAME_PATTERN_ATTRIBUTE = "filename-pattern";
@Override
protected Class<?> getBeanClass(Element element) {
return FileSource.class;
}
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !DIRECTORY_ATTRIBUTE.equals(attributeName) && !FILE_FILTER_ATTRIBUTE.equals(attributeName)
&& !FILENAME_FILTER_ATTRIBUTE.equals(attributeName)
&& !FILENAME_PATTERN_ATTRIBUTE.equals(attributeName) && !TYPE_ATTRIBUTE.equals(attributeName)
&& super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
String directoryLocation = element.getAttribute(DIRECTORY_ATTRIBUTE);
if (!directoryLocation.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) && !isUrl(directoryLocation)) {
directoryLocation = "file:" + directoryLocation;
}
beanDefinition.addConstructorArgValue(directoryLocation);
String fileFilter = element.getAttribute(FILE_FILTER_ATTRIBUTE);
String filenameFilter = element.getAttribute(FILENAME_FILTER_ATTRIBUTE);
String filenamePattern = element.getAttribute(FILENAME_PATTERN_ATTRIBUTE);
this.verifyAtMostOneAttributeSpecified(fileFilter, filenameFilter, filenamePattern);
if (StringUtils.hasText(fileFilter)) {
beanDefinition.addPropertyReference("fileFilter", fileFilter);
}
else if (StringUtils.hasText(filenameFilter)) {
beanDefinition.addPropertyReference("filenameFilter", filenameFilter);
}
else if (StringUtils.hasLength(filenamePattern)) {
RegexPatternFilenameFilter regexFilter = new RegexPatternFilenameFilter();
regexFilter.setPattern(Pattern.compile(filenamePattern));
beanDefinition.addPropertyValue("filenameFilter", regexFilter);
}
super.postProcess(beanDefinition, element);
processTypeAttribute(beanDefinition, element);
}
private void processTypeAttribute(BeanDefinitionBuilder beanDefinition, Element element) {
if (beanDefinition.getRawBeanDefinition().getConstructorArgumentValues().getArgumentCount() == 2) {
// message-creator already defined, ignore type property
}
else {
String type = element.getAttribute(TYPE_ATTRIBUTE);
if ("text".equals(type)) {
beanDefinition.addConstructorArgValue(new TextFileMessageCreator(false));
}
else if ("binary".equals(type)) {
beanDefinition.addConstructorArgValue(new ByteArrayFileMessageCreator(false));
}
}
}
private boolean isUrl(String directoryLocation) {
try {
new URL(directoryLocation);
return true;
}
catch (MalformedURLException e) {
return false;
}
}
private void verifyAtMostOneAttributeSpecified(String... attributes) {
boolean attributeSpecified = false;
for (String attribute : attributes) {
if (StringUtils.hasText(attribute)) {
if (attributeSpecified) {
throw new ConfigurationException("FileSource supports at most one of '" + FILE_FILTER_ATTRIBUTE
+ "', '" + FILENAME_FILTER_ATTRIBUTE + "', and '" + FILENAME_PATTERN_ATTRIBUTE + "'.");
}
attributeSpecified = true;
}
}
}
}

View File

@@ -1,72 +0,0 @@
/*
* 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.file.config;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.adapter.file.FileTarget;
import org.springframework.integration.adapter.file.SimpleFileMessageMapper;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Parser for the &lt;file-target/&gt; element.
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class FileTargetParser extends AbstractSimpleBeanDefinitionParser {
private static final String NAME_GENERATOR_PROPERTY = "fileNameGenerator";
public static final String DIRECTORY_ATTRIBUTE = "directory";
public static final String FILE_NAME_GENERATOR_ATTRIBUTE = "name-generator";
@Override
protected Class<?> getBeanClass(Element element) {
return FileTarget.class;
}
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !(DIRECTORY_ATTRIBUTE.equals(attributeName) || FILE_NAME_GENERATOR_ATTRIBUTE.equals(attributeName))
&& super.isEligibleAttribute(attributeName);
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
super.doParse(element, parserContext, builder);
BeanDefinition messageMapperDefinition = new RootBeanDefinition(SimpleFileMessageMapper.class);
messageMapperDefinition.getConstructorArgumentValues().addGenericArgumentValue(
element.getAttribute(DIRECTORY_ATTRIBUTE));
if (StringUtils.hasText(element.getAttribute(FILE_NAME_GENERATOR_ATTRIBUTE))) {
messageMapperDefinition.getPropertyValues().addPropertyValue(NAME_GENERATOR_PROPERTY,
new RuntimeBeanReference(element.getAttribute(FILE_NAME_GENERATOR_ATTRIBUTE)));
}
String mapperBeanName = parserContext.getReaderContext().generateBeanName(messageMapperDefinition);
parserContext.getRegistry().registerBeanDefinition(
mapperBeanName, messageMapperDefinition);
builder.addConstructorArgReference(mapperBeanName);
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.adapter.file;
package org.springframework.integration.adapter.ftp;
import java.io.IOException;
import java.util.ArrayList;
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageCreator;
import org.springframework.integration.message.MessageDeliveryAware;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.adapter.file;
package org.springframework.integration.adapter.ftp;
import java.util.ArrayList;
import java.util.Collection;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.adapter.file;
package org.springframework.integration.adapter.ftp;
import java.io.File;

View File

@@ -24,9 +24,7 @@ import java.util.List;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.springframework.integration.adapter.file.AbstractDirectorySource;
import org.springframework.integration.adapter.file.Backlog;
import org.springframework.integration.adapter.file.FileSnapshot;
import org.springframework.integration.message.DefaultMessageCreator;
import org.springframework.integration.message.MessageCreator;
import org.springframework.util.Assert;
@@ -46,6 +44,7 @@ public class FtpSource extends AbstractDirectorySource<List<File>> {
private final FTPClientPool clientPool;
public FtpSource(FTPClientPool clientPool) {
this(new DefaultMessageCreator<List<File>>(), clientPool);
}
@@ -55,6 +54,7 @@ public class FtpSource extends AbstractDirectorySource<List<File>> {
this.clientPool = clientPool;
}
public void setMaxFilesPerMessage(int maxFilesPerMessage) {
Assert.isTrue(maxFilesPerMessage > 0, "'maxFilesPerMessage' must be greater than 0");
this.maxFilesPerMessage = maxFilesPerMessage;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.adapter.file.config;
package org.springframework.integration.adapter.ftp.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;

View File

@@ -16,11 +16,11 @@
package org.springframework.integration.adapter.ftp.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.integration.adapter.file.config.AbstractDirectorySourceParser;
import org.springframework.integration.adapter.ftp.FtpSource;
import org.springframework.integration.adapter.ftp.QueuedFTPClientPool;
import org.w3c.dom.Element;
/**
* Parser for the &lt;ftp-source/&gt; element.
@@ -30,6 +30,7 @@ import org.w3c.dom.Element;
* @author Iwein Fuld
*/
public class FtpSourceParser extends AbstractDirectorySourceParser {
private static final String POOL_ATTRIBUTE_USER = "username";
private static final String POOL_ATTRIBUTE_PASS = "password";
@@ -40,6 +41,7 @@ public class FtpSourceParser extends AbstractDirectorySourceParser {
private static final String POOL_ATTRIBUTE_REMOTEDIR = "remote-working-directory";
@Override
protected Class<?> getBeanClass(Element element) {
return FtpSource.class;
@@ -71,4 +73,5 @@ public class FtpSourceParser extends AbstractDirectorySourceParser {
queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory);
beanDefinition.addConstructorArgValue(queuedFTPClientPool);
}
}

View File

@@ -1,5 +1,3 @@
file-source=org.springframework.integration.adapter.file.config.FileSourceParser
file-target=org.springframework.integration.adapter.file.config.FileTargetParser
ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser