Example usage for org.springframework.beans.factory.xml XmlBeanFactory containsBean

List of usage examples for org.springframework.beans.factory.xml XmlBeanFactory containsBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlBeanFactory containsBean.

Prototype

@Override
    public boolean containsBean(String name) 

Source Link

Usage

From source file:ch.tatool.app.service.export.DataImportTest.java

public static void main(String[] args) {
    // get the httpentity containing the data
    HttpEntity httpEntity = getHttpEntity();
    // Create a httpclient instance
    DefaultHttpClient httpclient = new DefaultHttpClient();
    // setup a POST call
    HttpGet httpGet = new HttpGet(serverUrl);

    try {//from  w ww. j  a  v  a2s  .c  o m
        HttpResponse response = httpclient.execute(httpGet);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            System.out.println("Unable to download data: " + response.getStatusLine().getReasonPhrase());
            System.out.println(response.getStatusLine().getStatusCode());
        } else {
            // all ok
            HttpEntity enty = response.getEntity();
            InputStream is = enty.getContent();

            XmlBeanFactory beanFactory = null;
            try {

                beanFactory = new XmlBeanFactory(new InputStreamResource(is));

            } catch (BeansException be) {
                // TODO: inform user that training configuration is broken
                throw new RuntimeException("Unable to load module configuration", be);
            }

            // check whether we have the mandatory beans (rootElement)
            if (!beanFactory.containsBean("rootElement")) {
                // TODO: inform user that training configuration is broken
                throw new RuntimeException("No rootElement bean found in the module configuration file");
            }

            // fetch the rootElement
            Node rootElement = (Node) beanFactory.getBean("rootElement");

            System.out.println(rootElement.getId());

        }
    } catch (IOException ioe) {

    }

    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:ch.tatool.core.module.initializer.SpringExecutorInitializer.java

@SuppressWarnings("unchecked")
protected Map<String, DataExporter> getModuleExporters(String configurationXML) {
    // try loading the configuration
    XmlBeanFactory beanFactory = null;
    try {//from w w  w  . j a  v  a 2s  . c o  m
        beanFactory = new XmlBeanFactory(new ByteArrayResource(configurationXML.getBytes()));
    } catch (BeansException be) {
        logger.error("Unable to load Tatool file.", be);
        throw new RuntimeException("Unable to load Tatool file.", be);
    }

    // see whether we have properties
    if (beanFactory.containsBean("moduleExporters")) {
        Map<String, DataExporter> exporters = (Map<String, DataExporter>) beanFactory
                .getBean("moduleExporters");
        return exporters;
    } else {
        return Collections.emptyMap();
    }
}

From source file:ch.tatool.core.module.initializer.SpringExecutorInitializer.java

/**
 * Checks whether a configuration xml is valid or not.
 */// www.  j  a v a 2s.c  om
protected Element loadRootElementFromSpringXML(String configXML) {
    // try loading the configuration
    XmlBeanFactory beanFactory = null;
    try {
        beanFactory = new XmlBeanFactory(new ByteArrayResource(configXML.getBytes()));
    } catch (BeansException be) {
        logger.error("Unable to load Tatool file.", be);
        throw new RuntimeException("Unable to load Tatool file.");
    }

    // check whether we have the mandatory beans (rootElement)
    if (!beanFactory.containsBean(ROOT_ELEMENT)) {
        logger.error("Unable to load Tatool file. Root element missing!");
        throw new CreationException("Unable to load Tatool file. Root element missing!");
    }

    // fetch the rootElement
    try {
        Element root = (Element) beanFactory.getBean(ROOT_ELEMENT);
        return root;
    } catch (RuntimeException e) {
        String[] errors = e.getMessage().split(";");
        throw new CreationException(errors[errors.length - 1]);
    }
}

From source file:ch.tatool.core.module.initializer.SpringExecutorInitializer.java

@SuppressWarnings("unchecked")
protected Map<String, String> getModuleSetupProperties(String configurationXML) {
    // try loading the configuration
    XmlBeanFactory beanFactory = null;
    try {//from ww  w .  j  a va 2s  . c o  m
        beanFactory = new XmlBeanFactory(new ByteArrayResource(configurationXML.getBytes()));
    } catch (BeansException be) {
        logger.error("Unable to load Tatool file.", be);
        String[] errors = be.getMessage().split(";");
        throw new CreationException(errors[errors.length - 1]);
    }

    // see whether we have properties
    if (beanFactory.containsBean("moduleProperties")) {
        Map<String, String> properties = (Map<String, String>) beanFactory.getBean("moduleProperties");
        return properties;
    } else {
        return Collections.emptyMap();
    }
}

From source file:ch.tatool.app.service.impl.ModuleServiceImpl.java

private Map<String, DataExporter> getModuleExportersFromXML(byte[] configurationXML) {
    // try loading the configuration
    XmlBeanFactory beanFactory = null;
    if (configurationXML != null) {
        try {//from   w  w w. ja va  2  s .c  om
            beanFactory = new XmlBeanFactory(new ByteArrayResource(configurationXML));
        } catch (BeansException be) {
            // TODO: inform user that module configuration is broken
            throw new RuntimeException("Unable to load Tatool file.", be);
        }

        // see whether we have exporters
        if (beanFactory.containsBean("moduleExporters")) {
            Map<String, DataExporter> exporters = (Map<String, DataExporter>) beanFactory
                    .getBean("moduleExporters");
            return exporters;
        } else {
            return Collections.emptyMap();
        }
    } else {
        return null;
    }
}