List of usage examples for org.springframework.beans.factory.xml XmlBeanDefinitionReader XmlBeanDefinitionReader
public XmlBeanDefinitionReader(BeanDefinitionRegistry registry)
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.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 *///ww w . ja v a 2 s. com 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: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 va2s .c o 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:com.jaspersoft.jasperserver.export.RemoveDuplicatedDisplayName.java
public static void main(String[] args) { Parameters params = null;// w ww. j a v a 2s .co 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.mzd.shap.spring.cli.ConfigSetup.java
public static void main(String[] args) { // check args if (args.length != 1) { exitOnError(1, null);// w ww. j a v a2s .c o m } // check file existance File analyzerXML = new File(args[0]); if (!analyzerXML.exists()) { exitOnError(1, "'" + analyzerXML.getPath() + "' did not exist\n"); } // prompt user whether existing data should be purged boolean isPurged = false; String ormContext = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("\nDo you wish to purge the database before running setup?"); System.out.println("WARNING: all existing data in SHAP will be lost!"); System.out.println("Really purge? yes/[NO]"); String ans = br.readLine(); if (ans.toLowerCase().equals("yes")) { System.out.println("Purging enabled"); ormContext = "orm-purge-context.xml"; isPurged = true; } else { System.out.println("Purging disabled"); ormContext = "orm-context.xml"; } } catch (IOException ex) { throw new RuntimeException(ex); } // run tool try { // Using a generic application context since we're referencing // both classpath and filesystem resources. GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("datasource-context.xml"), new ClassPathResource(ormContext), new FileSystemResource(analyzerXML)); ctx.refresh(); /* * Create an base admin user. */ if (isPurged) { //only attempted if we've wiped the old database. RoleDao roleDao = (RoleDao) ctx.getBean("roleDao"); Role adminRole = roleDao.saveOrUpdate(new Role("admin", "ROLE_ADMIN")); Role userRole = roleDao.saveOrUpdate(new Role("user", "ROLE_USER")); UserDao userDao = (UserDao) ctx.getBean("userDao"); userDao.saveOrUpdate(new User("admin", "admin", "shap01", adminRole, userRole)); } /* * Create some predefined analyzers. Users should have modified * the configuration file to suit their environment. */ AnnotatorDao annotatorDao = (AnnotatorDao) ctx.getBean("annotatorDao"); DetectorDao detectorDao = (DetectorDao) ctx.getBean("detectorDao"); ConfigSetup config = (ConfigSetup) ctx.getBean("configuration"); for (Annotator an : config.getAnnotators()) { System.out.println("Adding annotator: " + an.getName()); annotatorDao.saveOrUpdate(an); } for (Detector dt : config.getDetectors()) { System.out.println("Adding detector: " + dt.getName()); detectorDao.saveOrUpdate(dt); } System.exit(0); } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }
From source file:org.bambooframework.dao.impl.cfg.BeansConfigurationHelper.java
public static DaoEngineConfigurationImpl parseDaoEngineConfiguration(Resource springResource, String beanName) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); xmlBeanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); xmlBeanDefinitionReader.loadBeanDefinitions(springResource); DaoEngineConfigurationImpl processEngineConfiguration = (DaoEngineConfigurationImpl) beanFactory .getBean(beanName);// www . j a va2 s. co m processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(beanFactory)); return processEngineConfiguration; }
From source file:org.activiti.crystalball.simulator.impl.cfg.BeansConfigurationHelper.java
public static SimulationEngineConfiguration parseSimulationEngineConfiguration(Resource springResource, String beanName) {/* ww w . j a va2 s .c om*/ DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); xmlBeanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); xmlBeanDefinitionReader.loadBeanDefinitions(springResource); SimulationEngineConfigurationImpl simulationEngineConfiguration = (SimulationEngineConfigurationImpl) beanFactory .getBean(beanName); simulationEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(beanFactory)); return simulationEngineConfiguration; }
From source file:org.springmodules.cache.config.ParserContextFactory.java
public static ParserContext create(BeanDefinitionParserDelegate delegate) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); XmlReaderContext readerContext = new XmlReaderContext(null, null, null, null, reader, null); return new ParserContext(readerContext, delegate); }
From source file:com.lewisd.maven.lint.rules.opensource.OpensourceRulesIT.java
@BeforeClass public static void beforeAllTest() { applicationContext = new GenericApplicationContext(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassPathResource classPathResource = new ClassPathResource(CONFIG_LOCATION, classLoader); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(applicationContext); xmlBeanDefinitionReader.loadBeanDefinitions(classPathResource); applicationContext.getBeanFactory().registerSingleton("LOG", LOG); applicationContext.getBeanFactory().registerResolvableDependency(PluginParameterExpressionEvaluator.class, mock(PluginParameterExpressionEvaluator.class)); applicationContext.refresh();//from w w w. j ava 2 s . c o m }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
public static GenericApplicationContext getSpringApplicationContext(InputStream applicationContxtInStream, String springBeansFilePath) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false);// w w w. j ava 2s.c om xbdr.loadBeanDefinitions(new InputStreamResource(applicationContxtInStream)); appContext.refresh(); return appContext; }