com.hillert.si.SpringIntegrationUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.hillert.si.SpringIntegrationUtils.java

Source

/*
 * Copyright 2002-2010 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 com.hillert.si;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.FileWritingMessageHandler;

/**
 * Displays the names of the input and output directories.
 *
 */
public final class SpringIntegrationUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(SpringIntegrationUtils.class);

    private SpringIntegrationUtils() {
    }

    /**
     * Helper Method to dynamically determine and display input and output
     * directories as defined in the Spring Integration context.
     *
     * @param context Spring Application Context
     */
    public static void displayDirectories(final ApplicationContext context) {

        final Map<String, FileReadingMessageSource> fileReadingMessageSources = context
                .getBeansOfType(FileReadingMessageSource.class);
        final Map<String, FileWritingMessageHandler> fileWritingMessageHandlers = context
                .getBeansOfType(FileWritingMessageHandler.class);

        final List<String> inputDirectories = new ArrayList<String>();
        final List<String> outputDirectories = new ArrayList<String>();

        for (final FileReadingMessageSource messageSource : fileReadingMessageSources.values()) {
            final File inDir = (File) new DirectFieldAccessor(messageSource).getPropertyValue("directory");
            inputDirectories.add(inDir.getAbsolutePath());
        }

        for (final FileWritingMessageHandler messageHandler : fileWritingMessageHandlers.values()) {
            final File outDir = (File) new DirectFieldAccessor(messageHandler)
                    .getPropertyValue("destinationDirectory");
            outputDirectories.add(outDir.getAbsolutePath());
        }

        final StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.append("\n=========================================================");
        stringBuilder.append("\n");

        for (final String inputDirectory : inputDirectories) {
            stringBuilder.append("\n    Input directory is: '" + inputDirectory + "'");
        }

        for (final String outputDirectory : outputDirectories) {
            stringBuilder.append("\n    Output directory is: '" + outputDirectory + "'");
        }

        stringBuilder.append("\n\n=========================================================");

        LOGGER.info(stringBuilder.toString());

    }

}