Example usage for org.springframework.beans.factory.xml XmlBeanDefinitionReader loadBeanDefinitions

List of usage examples for org.springframework.beans.factory.xml XmlBeanDefinitionReader loadBeanDefinitions

Introduction

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

Prototype

public int loadBeanDefinitions(InputSource inputSource) throws BeanDefinitionStoreException 

Source Link

Document

Load bean definitions from the specified XML file.

Usage

From source file:com.home.ln_spring.ch4.XmlConfigWithBeanFactory.java

public static void main(String args[]) {

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader rdr = new XmlBeanDefinitionReader(factory);
    rdr.loadBeanDefinitions(new FileSystemResource("src/main/resources/xmlBeanFactory.xml"));

    Oracle oracle = factory.getBean("oracle", Oracle.class);
    System.out.println(oracle.defineMeaningOfLife());
}

From source file:org.openplans.delayfeeder.LoadFeeds.java

public static void main(String args[]) throws HibernateException, IOException {
    if (args.length != 1) {
        System.out.println("expected one argument: the path to a csv of agency,route,url");
    }/*w  w w  . j  a v a 2s. co  m*/
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.loadBeanDefinitions("org/openplans/delayfeeder/application-context.xml");
    xmlReader.loadBeanDefinitions("data-sources.xml");

    SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");

    Session session = sessionFactory.getCurrentSession();
    Transaction tx = session.beginTransaction();

    FileReader fileReader = new FileReader(new File(args[0]));
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    while (bufferedReader.ready()) {
        String line = bufferedReader.readLine().trim();
        if (line.startsWith("#")) {
            continue;
        }
        if (line.length() < 3) {
            //blank or otherwise broken line
            continue;
        }

        String[] parts = line.split(",");
        String agency = parts[0];
        String route = parts[1];
        String url = parts[2];
        Query query = session.createQuery("from RouteFeed where agency = :agency and route = :route");
        query.setParameter("agency", agency);
        query.setParameter("route", route);
        @SuppressWarnings("rawtypes")
        List list = query.list();
        RouteFeed feed;
        if (list.size() == 0) {
            feed = new RouteFeed();
            feed.agency = agency;
            feed.route = route;
            feed.lastEntry = new GregorianCalendar();
        } else {
            feed = (RouteFeed) list.get(0);
        }
        if (!url.equals(feed.url)) {
            feed.url = url;
            feed.lastEntry.setTimeInMillis(0);
        }
        session.saveOrUpdate(feed);
    }
    tx.commit();
}

From source file:org.transitappliance.loader.LoaderFrontEnd.java

/**
 * The main CLI of the program. Just loads the config file and spins up Spring.
 * @param args The command line arguments. Uses varargs so this can be called from a script
 *//*from w  w  w  . j  a v a2s .co  m*/
public static void main(String... args) {
    // benchmarking
    long startTime = System.currentTimeMillis();
    long totalTime;

    // Modeled after the main method in OTP Graph Builder

    // arg checking
    if (args.length == 0) {
        System.out.println("usage: loader config.xml");
        System.exit(1);
    }

    System.out.println("Transit Appliance Stop Loader");

    // Load Spring
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);

    // Load config file for this agency and database adapter
    for (String file : args)
        reader.loadBeanDefinitions(new FileSystemResource(file));

    // get the loader, config'd for this agency
    TransitStopLoader loader = (TransitStopLoader) ctx.getBean("transitStopLoader");

    loader.loadStops();
}

From source file:com.jaspersoft.jasperserver.export.RemoveDuplicatedDisplayName.java

public static void main(String[] args) {

    Parameters params = null;//www . j a va  2 s  .  c  o  m
    boolean success = false;
    try {

        GenericApplicationContext ctx = new GenericApplicationContext();
        XmlBeanDefinitionReader configReader = new XmlBeanDefinitionReader(ctx);
        List resourceXML = getPaths(args[2]);
        if (args != null && args.length > 0) {
            for (int i = 0; i < resourceXML.size(); i++) {
                org.springframework.core.io.Resource resource = classPathResourceFactory
                        .create((String) resourceXML.get(i));
                configReader.loadBeanDefinitions(resource);
            }
        }
        ctx.refresh();
        if (args.length > 3) {
            if ("UPDATE".equals(args[3])) {
                updateRepo = true;
            }
        }

        // write to file
        //

        try {
            CommandBean commandBean = (CommandBean) ctx.getBean("removeDuplicateDisplayName",
                    CommandBean.class);
            Charset encoding = Charset.forName(
                    ((RemoveDuplicatedDisplayName) commandBean).getEncodingProvider().getCharacterEncoding());
            osw = new OutputStreamWriter(new FileOutputStream("remove_duplicated_display_name_report.txt"),
                    encoding);
            commandBean.process(params);

        } finally {
            osw.close();
        }
        success = true;
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    System.exit(success ? 0 : -1);
}

From source file:org.apache.empire.samples.spring.SampleSpringApp.java

static GenericApplicationContext getContext() {
    log.info("Creating Spring Application Context ...");
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
    reader.loadBeanDefinitions(new ClassPathResource("/applicationContext.xml"));

    ctx.refresh();//from   w  w w .ja v a 2 s. c om
    return ctx;
}

From source file:exercise.cca.data.cli.main.MainCli.java

protected static ConfigurableApplicationContext loadContext(final String contextPath) {
    final GenericApplicationContext ctx = new GenericApplicationContext();
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource(contextPath));
    final PropertyPlaceholderConfigurer placeholderProcessor = new PropertyPlaceholderConfigurer();
    ctx.addBeanFactoryPostProcessor(placeholderProcessor);
    ctx.refresh();/*from   ww  w .  j  av  a2  s . c o  m*/
    return ctx;
}

From source file:com.wavemaker.commons.util.SpringUtils.java

public static Object getBean(Resource resource, String beanName) {
    GenericApplicationContext ctx = initSpringConfig(false);
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(resource);
    ctx.refresh();/*www. j a v a2 s  .co  m*/
    return ctx.getBean(beanName);
}

From source file:com.wavemaker.commons.util.SpringUtils.java

private static GenericApplicationContext initSpringConfig(boolean refresh) {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("config.xml"));

    if (refresh) {
        ctx.refresh();/*from w ww  . j  a v  a  2  s  . co  m*/
    }

    return ctx;
}

From source file:net.sourceforge.jabm.spring.BeanFactorySingleton.java

public static void initialiseFactory(Resource resource) {

    beanFactory = new DefaultListableBeanFactory();

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    reader.loadBeanDefinitions(resource);

    // Caching must be disabled for
    // net.sourceforge.jabm.init.RandomVariateSimulationInitialiser
    beanFactory.setCacheBeanMetadata(false);
    beanFactory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());

    // Register the custom simulation scope
    beanFactory.registerScope(SimulationScope.ATTRIBUTE_VALUE, SimulationScope.getSingletonInstance());
}

From source file:com.textocat.textokit.eval.EvaluationLauncher.java

public static void runUsingProperties(Properties configProperties) throws Exception {
    GenericApplicationContext appCtx = new GenericApplicationContext();

    appCtx.getEnvironment().getPropertySources()
            .addLast(new PropertiesPropertySource("configFile", configProperties));

    XmlBeanDefinitionReader xmlBDReader = new XmlBeanDefinitionReader(appCtx);
    xmlBDReader.loadBeanDefinitions(APP_CONTEXT_LOCATION);

    // register listeners
    Map<String, String> listenerImpls = getPrefixedKeyPairs(configProperties, PREFIX_LISTENER_ID);
    for (String listenerId : listenerImpls.keySet()) {
        String listenerClass = listenerImpls.get(listenerId);
        BeanDefinitionBuilder bb = genericBeanDefinition(listenerClass);
        Map<String, String> listenerProperties = getPrefixedKeyPairs(configProperties,
                PREFIX_LISTENER_PROPERTY + listenerId + ".");
        for (String propName : listenerProperties.keySet()) {
            bb.addPropertyValue(propName, listenerProperties.get(propName));
        }//from w  ww .j a va 2 s . com
        appCtx.registerBeanDefinition(listenerId, bb.getBeanDefinition());
    }

    appCtx.refresh();

    appCtx.registerShutdownHook();

    GoldStandardBasedEvaluation eval = appCtx.getBean(GoldStandardBasedEvaluation.class);
    eval.run();
}