Example usage for org.springframework.context.support FileSystemXmlApplicationContext containsBean

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext containsBean

Introduction

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

Prototype

@Override
    public boolean containsBean(String name) 

Source Link

Usage

From source file:org.apache.ftpserver.main.Daemon.java

/**
 * Get the configuration object./* w ww . j  a v  a  2s . c o  m*/
 */
private static FtpServer getConfiguration(String[] args) throws Exception {

    FtpServer server = null;
    if (args == null || args.length < 2) {
        LOG.info("Using default configuration....");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 2) && args[1].equals("-default")) {
        // supported for backwards compatibility, but not documented
        System.out.println("The -default switch is deprecated, please use --default instead");
        LOG.info("Using default configuration....");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 2) && args[1].equals("--default")) {
        LOG.info("Using default configuration....");
        server = new FtpServerFactory().createServer();
    } else if (args.length == 2) {
        LOG.info("Using xml configuration file " + args[1] + "...");
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[1]);

        if (ctx.containsBean("server")) {
            server = (FtpServer) ctx.getBean("server");
        } else {
            String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
            if (beanNames.length == 1) {
                server = (FtpServer) ctx.getBean(beanNames[0]);
            } else if (beanNames.length > 1) {
                System.out
                        .println("Using the first server defined in the configuration, named " + beanNames[0]);
                server = (FtpServer) ctx.getBean(beanNames[0]);
            } else {
                System.err.println("XML configuration does not contain a server configuration");
            }
        }
    } else {
        throw new FtpException("Invalid configuration option");
    }

    return server;
}

From source file:org.apache.smscserver.main.Daemon.java

/**
 * Get the configuration object./*from  ww  w .  ja v  a  2 s  . com*/
 */
private static SmscServer getConfiguration(String[] args) throws Exception {

    SmscServer server = null;
    if ((args == null) || (args.length < 2)) {
        Daemon.LOG.info("Using default configuration....");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 2) && args[1].equals("-default")) {
        // supported for backwards compatibility, but not documented
        System.out.println("The -default switch is deprecated, please use --default instead");
        Daemon.LOG.info("Using default configuration....");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 2) && args[1].equals("--default")) {
        Daemon.LOG.info("Using default configuration....");
        server = new SmscServerFactory().createServer();
    } else if (args.length == 2) {
        Daemon.LOG.info("Using xml configuration file " + args[1] + "...");
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[1]);

        if (ctx.containsBean("server")) {
            server = (SmscServer) ctx.getBean("server");
        } else {
            String[] beanNames = ctx.getBeanNamesForType(SmscServer.class);
            if (beanNames.length == 1) {
                server = (SmscServer) ctx.getBean(beanNames[0]);
            } else if (beanNames.length > 1) {
                System.out
                        .println("Using the first server defined in the configuration, named " + beanNames[0]);
                server = (SmscServer) ctx.getBean(beanNames[0]);
            } else {
                System.err.println("XML configuration does not contain a server configuration");
            }
        }
    } else {
        throw new SmscException("Invalid configuration option");
    }

    return server;
}

From source file:com.predic8.membrane.annot.bean.MCUtil.java

@SuppressWarnings("unchecked")
public static <T> T fromXML(Class<T> clazz, final String xml) {
    final String MAGIC = "magic.xml";

    FileSystemXmlApplicationContext fsxacApplicationContext = new FileSystemXmlApplicationContextExtension(
            MAGIC, xml);/*from   w w w.  jav  a2  s  . co  m*/
    fsxacApplicationContext.setConfigLocation(MAGIC);

    fsxacApplicationContext.refresh();

    Object bean = null;

    if (fsxacApplicationContext.containsBean("main")) {
        bean = fsxacApplicationContext.getBean("main");
    } else {
        Collection<T> beans = fsxacApplicationContext.getBeansOfType(clazz).values();
        if (beans.size() > 1)
            throw new InvalidParameterException(
                    "There is more than one bean of type '" + clazz.getName() + "'.");
        bean = beans.iterator().next();
    }

    if (bean == null)
        throw new InvalidParameterException("Did not find bean with ID 'main'.");

    if (!clazz.isAssignableFrom(bean.getClass()))
        throw new InvalidParameterException("Bean 'main' is not a " + clazz.getName() + " .");

    return (T) bean;
}

From source file:com.emc.vipr.sync.ViPRSync.java

/**
 * Initializes a Spring Application Context from the given file and
 * bootstraps the ViPRSync object from there.
 *///from   w  w w  .j av  a2  s .c o m
protected static ViPRSync springBootstrap(String pathToSpringXml) {
    File springXml = new File(pathToSpringXml);
    if (!springXml.exists()) {
        throw new ConfigurationException("the Spring XML file: " + springXml + " does not exist");
    }

    l4j.info("loading configuration from Spring XML file: " + springXml);
    FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(pathToSpringXml);

    if (!ctx.containsBean(ROOT_SPRING_BEAN)) {
        throw new ConfigurationException("your Spring XML file: " + springXml + " must contain one bean named '"
                + ROOT_SPRING_BEAN + "' that initializes an ViPRSync object");
    }

    return ctx.getBean(ROOT_SPRING_BEAN, ViPRSync.class);
}

From source file:org.apache.smscserver.main.CommandLine.java

/**
 * Get the configuration object.//w w w  . ja v  a2  s .  c  o m
 */
protected SmscServer getConfiguration(String[] args) throws Exception {

    SmscServer server = null;
    if (args.length == 0) {
        System.out.println("Using default configuration");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("-default")) {
        // supported for backwards compatibility, but not documented
        System.out.println("The -default switch is deprecated, please use --default instead");
        System.out.println("Using default configuration");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("--default")) {
        System.out.println("Using default configuration");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("--help")) {
        this.usage();
    } else if ((args.length == 1) && args[0].equals("-?")) {
        this.usage();
    } else if (args.length == 1) {
        System.out.println("Using XML configuration file " + args[0] + "...");
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[0]);

        if (ctx.containsBean("server")) {
            server = (SmscServer) ctx.getBean("server");
        } else {
            String[] beanNames = ctx.getBeanNamesForType(SmscServer.class);
            if (beanNames.length == 1) {
                server = (SmscServer) ctx.getBean(beanNames[0]);
            } else if (beanNames.length > 1) {
                System.err
                        .println("Using the first server defined in the configuration, named " + beanNames[0]);
                server = (SmscServer) ctx.getBean(beanNames[0]);
            } else {
                System.err.println("XML configuration does not contain a server configuration");
            }
        }
    } else {
        this.usage();
    }

    return server;
}

From source file:org.apache.ftpserver.main.CommandLine.java

/**
 * Get the configuration object./*  w w  w . ja v  a 2 s  . co  m*/
 */
protected FtpServer getConfiguration(String[] args) throws Exception {

    FtpServer server = null;
    if (args.length == 0) {
        System.out.println("Using default configuration");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("-default")) {
        // supported for backwards compatibility, but not documented
        System.out.println("The -default switch is deprecated, please use --default instead");
        System.out.println("Using default configuration");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("--default")) {
        System.out.println("Using default configuration");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("--help")) {
        usage();
    } else if ((args.length == 1) && args[0].equals("-?")) {
        usage();
    } else if (args.length == 1) {
        System.out.println("Using XML configuration file " + args[0] + "...");
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[0]);

        if (ctx.containsBean("server")) {
            server = (FtpServer) ctx.getBean("server");
        } else {
            String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
            if (beanNames.length == 1) {
                server = (FtpServer) ctx.getBean(beanNames[0]);
            } else if (beanNames.length > 1) {
                System.out
                        .println("Using the first server defined in the configuration, named " + beanNames[0]);
                server = (FtpServer) ctx.getBean(beanNames[0]);
            } else {
                System.err.println("XML configuration does not contain a server configuration");
            }
        }
    } else {
        usage();
    }

    return server;
}