List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext
public GenericApplicationContext()
From source file:org.anarres.dblx.core.Main.java
public static void main(String[] args) throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); Arguments arguments = new Arguments(args); GenericApplicationContext context = new GenericApplicationContext(); AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context); reader.register(AppConfiguration.class); for (AppConfiguration.Provider configurationProvider : ServiceLoader .load(AppConfiguration.Provider.class)) { for (Class<?> configurationClass : configurationProvider.getConfigurationClasses()) { LOG.debug("Registering additional ServerConfiguration class " + configurationClass.getName()); reader.register(configurationClass); }//from w w w . ja v a 2 s . co m } SpringUtils.addConfigurations(context, arguments); context.refresh(); context.registerShutdownHook(); context.start(); LOG.info("Ready; startup took " + stopwatch); }
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 ww . ja v a 2 s.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: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 www . j a v a 2 s . c om 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;// w w w. j a va 2 s. 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);/*www.jav a2 s.co 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: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();/* w ww . java 2 s . c o m*/ }
From source file:com.mitre.cockpits.cmscockpit.CmsCockpitConfigurationTest.java
@BeforeClass public static void testsSetup() { Registry.setCurrentTenantByID("junit"); final GenericApplicationContext context = new GenericApplicationContext(); context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader())); context.setClassLoader(Registry.class.getClassLoader()); context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader()); context.setParent(Registry.getGlobalApplicationContext()); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.setBeanClassLoader(Registry.class.getClassLoader()); xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class); xmlReader.loadBeanDefinitions(getSpringConfigurationLocations()); context.refresh();//w ww . j a va 2 s. co m applicationContext = context; }
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);/*from w ww. j a va2s. c o m*/ xbdr.loadBeanDefinitions(new InputStreamResource(applicationContxtInStream)); appContext.refresh(); return appContext; }
From source file:edu.berkeley.compbio.ncbitaxonomy.NcbiTaxonomyDbContextFactory.java
public static ApplicationContext makeNcbiTaxonomyDbContext() //String dbName) throws IOException { /*/*from w ww .j av a2 s .com*/ File propsFile = PropertiesUtils .findPropertiesFile("NCBI_TAXONOMY_PROPERTIES", ".ncbitaxonomy", "ncbi_taxonomy.properties"); EnvironmentUtils.init(propsFile); logger.debug("Using properties file: " + propsFile); Properties p = new Properties(); FileInputStream is = null; try { is = new FileInputStream(propsFile); p.load(is); } finally { is.close(); } //String dbName = (String) p.get("default"); Map<String, Properties> databases = PropertiesUtils.splitPeriodDelimitedProperties(p); */ GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); // xmlReader.loadBeanDefinitions(new ClassPathResource("springjpautils.xml")); xmlReader.loadBeanDefinitions(new ClassPathResource("ncbitaxonomy.xml")); //PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); //cfg.setProperties(databases.get(dbName)); //ctx.addBeanFactoryPostProcessor(cfg); ctx.refresh(); // add a shutdown hook for the above context... ctx.registerShutdownHook(); return ctx; }
From source file:edu.berkeley.compbio.ncbitaxonomy.service.NcbiTaxonomyServicesContextFactory.java
public static ApplicationContext makeNcbiTaxonomyServicesContext() throws IOException { File propsFile = PropertiesUtils.findPropertiesFile("NCBI_TAXONOMY_SERVICE_PROPERTIES", ".ncbitaxonomy", "service.properties"); logger.debug("Using properties file: " + propsFile); Properties p = new Properties(); FileInputStream is = null;// w w w . java 2 s. c o m try { is = new FileInputStream(propsFile); p.load(is); } finally { is.close(); } String dbName = (String) p.get("default"); Map<String, Properties> databases = PropertiesUtils.splitPeriodDelimitedProperties(p); GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("ncbitaxonomyclient.xml")); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties properties = databases.get(dbName); if (properties == null) { logger.error("Service definition not found: " + dbName); logger.error("Valid names: " + StringUtils.join(databases.keySet().iterator(), ", ")); throw new NcbiTaxonomyRuntimeException("Database definition not found: " + dbName); } cfg.setProperties(properties); ctx.addBeanFactoryPostProcessor(cfg); ctx.refresh(); // add a shutdown hook for the above context... ctx.registerShutdownHook(); return ctx; }