Search in sources :

Example 1 with DirectoryScanner

use of org.springframework.integration.file.DirectoryScanner in project spring-integration by spring-projects.

the class AbstractInboundFileSynchronizingMessageSource method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    Assert.notNull(this.localDirectory, "localDirectory must not be null");
    try {
        if (!this.localDirectory.exists()) {
            if (this.autoCreateLocalDirectory) {
                if (logger.isDebugEnabled()) {
                    logger.debug("The '" + this.localDirectory + "' directory doesn't exist; Will create.");
                }
                this.localDirectory.mkdirs();
            } else {
                throw new FileNotFoundException(this.localDirectory.getName());
            }
        }
        this.fileSource.setDirectory(this.localDirectory);
        if (this.localFileListFilter == null) {
            this.localFileListFilter = new FileSystemPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), getComponentName());
        }
        FileListFilter<File> filter = buildFilter();
        if (this.scannerExplicitlySet) {
            Assert.state(!this.fileSource.isUseWatchService(), "'useWatchService' and 'scanner' are mutually exclusive.");
            this.fileSource.getScanner().setFilter(filter);
        } else if (!this.fileSource.isUseWatchService()) {
            DirectoryScanner directoryScanner = new DefaultDirectoryScanner();
            directoryScanner.setFilter(filter);
            this.fileSource.setScanner(directoryScanner);
        } else {
            this.fileSource.setFilter(filter);
        }
        if (this.getBeanFactory() != null) {
            this.fileSource.setBeanFactory(this.getBeanFactory());
        }
        this.fileSource.afterPropertiesSet();
        this.synchronizer.afterPropertiesSet();
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new BeanInitializationException("Failure during initialization of MessageSource for: " + this.getClass(), e);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) FileSystemPersistentAcceptOnceFileListFilter(org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter) DirectoryScanner(org.springframework.integration.file.DirectoryScanner) DefaultDirectoryScanner(org.springframework.integration.file.DefaultDirectoryScanner) FileNotFoundException(java.io.FileNotFoundException) SimpleMetadataStore(org.springframework.integration.metadata.SimpleMetadataStore) File(java.io.File) DefaultDirectoryScanner(org.springframework.integration.file.DefaultDirectoryScanner) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 DefaultDirectoryScanner (org.springframework.integration.file.DefaultDirectoryScanner)1 DirectoryScanner (org.springframework.integration.file.DirectoryScanner)1 FileSystemPersistentAcceptOnceFileListFilter (org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter)1 SimpleMetadataStore (org.springframework.integration.metadata.SimpleMetadataStore)1