Example usage for org.springframework.context.support GenericXmlApplicationContext GenericXmlApplicationContext

List of usage examples for org.springframework.context.support GenericXmlApplicationContext GenericXmlApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.support GenericXmlApplicationContext GenericXmlApplicationContext.

Prototype

public GenericXmlApplicationContext() 

Source Link

Document

Create a new GenericXmlApplicationContext that needs to be #load loaded and then manually #refresh refreshed .

Usage

From source file:org.springframework.integration.samples.smb.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//  ww w .ja v  a  2s.c  o  m
 */
public static void main(final String... args) {

    final Scanner scanner = new Scanner(System.in);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n     Welcome to the Spring Integration Smb Sample        "
                + "\n                                                         "
                + "\n    For more information please visit:                   "
                + "\nhttps://github.com/SpringSource/spring-integration-extensions"
                + "\n                                                         "
                + "\n=========================================================");
    }

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    System.out.println("Please enter the: ");
    System.out.println("\t- SMB Host");
    System.out.println("\t- SMB Share and Directory");
    System.out.println("\t- SMB Username");
    System.out.println("\t- SMB Password");

    System.out.print("Host: ");
    final String host = scanner.nextLine();

    System.out.print("Share and Directory (e.g. myFile/path/to/): ");
    final String shareAndDir = scanner.nextLine();

    System.out.print("Username (e.g. guest): ");
    final String username = scanner.nextLine();

    System.out.print("Password (can be empty): ");
    final String password = scanner.nextLine();

    context.getEnvironment().getSystemProperties().put("host", host);
    context.getEnvironment().getSystemProperties().put("shareAndDir", shareAndDir);
    context.getEnvironment().getSystemProperties().put("username", username);
    context.getEnvironment().getSystemProperties().put("password", password);

    context.load("classpath:META-INF/spring/integration/*-context.xml");
    context.registerShutdownHook();
    context.refresh();

    context.registerShutdownHook();

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n    Please press 'q + Enter' to quit the application.    "
                + "\n                                                         "
                + "\n=========================================================");
    }

    SmbSessionFactory smbSessionFactory = context.getBean("smbSession", SmbSessionFactory.class);

    System.out.println("Polling from Share: " + smbSessionFactory.getUrl());

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Exiting application...bye.");
    }

    System.exit(0);

}

From source file:org.springframework.integration.samples.travel.Main.java

/**
 * @param args Not used.// ww w  .j a  va 2  s  .  c  o  m
 */
public static void main(String... args) throws Exception {

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    final ConfigurableEnvironment env = context.getEnvironment();
    boolean mapQuestApiKeyDefined = env.containsProperty("mapquest.apikey");

    if (mapQuestApiKeyDefined) {
        env.setActiveProfiles("mapquest");
    }

    context.load("classpath:META-INF/spring/*.xml");
    context.refresh();

    final TravelGateway travelGateway = context.getBean("travelGateway", TravelGateway.class);

    final Scanner scanner = new Scanner(System.in);

    System.out.println("\n========================================================="
            + "\n                                                         "
            + "\n    Welcome to the Spring Integration Travel App!        "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://www.springintegration.org/                    "
            + "\n                                                         "
            + "\n=========================================================");

    System.out.println(
            "Please select the city, for which you would like to get traffic and weather information:");

    for (City city : City.values()) {
        System.out.println(String.format("\t%s. %s", city.getId(), city.getName()));
    }
    System.out.println("\tq. Quit the application");
    System.out.print("Enter your choice: ");

    while (true) {
        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            System.out.println("Exiting application...bye.");
            break;
        } else {

            final Integer cityId = Integer.valueOf(input);
            final City city = City.getCityForId(cityId);

            final String weatherReply = travelGateway.getWeatherByCity(city);

            System.out.println("\n=========================================================" + "\n    Weather:"
                    + "\n=========================================================");
            System.out.println(weatherReply);

            if (mapQuestApiKeyDefined) {
                final String trafficReply = travelGateway.getTrafficByCity(city);

                System.out.println("\n========================================================="
                        + "\n    Traffic:" + "\n=========================================================");
                System.out.println(trafficReply);
            } else {
                LOGGER.warn("Skipping Traffic Information call. Did you setup your MapQuest API Key? "
                        + "e.g. by calling:\n\n    $ mvn exec:java -Dmapquest.apikey=\"your_mapquest_api_key_url_decoded\"");
            }

            System.out.println("\n=========================================================" + "\n    Done."
                    + "\n=========================================================");
            System.out.print("Enter your choice: ");
        }
    }

    scanner.close();
    context.close();
}