List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:benedict.zhang.addon.persistence.PersistenceManager.java
public void addonDescriptionUpdater(String path) { session = sessionFactory.openSession(); session.beginTransaction();/*from w w w. ja va2 s . co m*/ ApplicationContext context = new FileSystemXmlApplicationContext(path); AddonDescription addonDescription = context.getBean(updateAddonDescriptionBeanId, AddonDescription.class); session.save(addonDescription); session.getTransaction().commit(); session.close(); }
From source file:net.sf.jailer.Configuration.java
@SuppressWarnings("unchecked") private static synchronized AbstractXmlApplicationContext getContext() { if (theApplicationContext == null) { String configFile = "jailer.xml"; if (CommandLineParser.getInstance().getWorkingfolder() != null) { configFile = "file:" + CommandLineParser.getInstance().newFile(configFile).getAbsolutePath(); }/*from ww w. java 2 s . c o m*/ theApplicationContext = new FileSystemXmlApplicationContext(configFile); doMinimizeUPK = Boolean.TRUE.equals(theApplicationContext.getBean("minimize-UPK")); theScriptEnhancer = (List<ScriptEnhancer>) theApplicationContext.getBean("script-enhancer"); theRenderer = (DataModelRenderer) theApplicationContext.getBean("renderer"); if (theApplicationContext.containsBean("null-column-placeholder")) { nullColumnPlaceholder = (String) theApplicationContext.getBean("null-column-placeholder"); } if (theApplicationContext.containsBean("local-entity-graph")) { localEntityGraphConfiguration = theApplicationContext.getBean("local-entity-graph"); } } return theApplicationContext; }
From source file:org.activequant.util.spring.ServiceLocator.java
private ApplicationContext resolveApplicationContext(String path) { // filesystem if (new File(path).exists()) { return new FileSystemXmlApplicationContext(path); }//from w w w . j a v a2 s . c om // classpath if (ServiceLocator.class.getClassLoader().getResource(path) != null) { return new ClassPathXmlApplicationContext(path); } // error throw new IllegalArgumentException("Cannot locate spring context file '" + path + "'"); }
From source file:edu.harvard.i2b2.ontology.util.OntologyUtil.java
/** * Return the ontology spring config/*from w ww . j a v a2s. c o m*/ * * @return */ public BeanFactory getSpringBeanFactory() { if (beanFactory == null) { String appDir = null; try { // read application directory property file via classpath Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME); // read directory property appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES); } catch (I2B2Exception e) { log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath "); } if (appDir != null) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "file:" + appDir + "/" + "OntologyApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + "OntologyApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }
From source file:org.trpr.platform.runtime.impl.container.spring.SpringContainerImpl.java
/** * Helper method that locates and loads all Bootstrap extensions *///from ww w .j a va2 s .co m private void initializeBootstrapExtensions() { File[] bootstrapExtensionFiles = FileLocator.findFiles(RuntimeConstants.BOOTSTRAP_EXTENSIONS_FILE); // Create the Bootstrap Extension dependency manager that will load all bootstrap extensions BootstrapExtensionDependencyManager beManager = new BootstrapExtensionDependencyManager(this); for (File beFile : bootstrapExtensionFiles) { try { // add the "file:" prefix to file names to get around strange behavior of FileSystemXmlApplicationContext that converts absolute path // to relative path AbstractApplicationContext beDefinitionsContext = new FileSystemXmlApplicationContext( FILE_PREFIX + beFile.getAbsolutePath()); // All beans in the BE definitions context are expected to be of type BootstrapExtensionInfo. // We look up and load only these to BootstrapExtensionDependencyManager String[] beInfos = beDefinitionsContext.getBeanNamesForType(BootstrapExtensionInfo.class); for (String beInfo : beInfos) { beManager.addBootstrapExtensionInfo( (BootstrapExtensionInfo) beDefinitionsContext.getBean(beInfo)); } // destroy the beDefinitionsContext as we dont need it anymore beDefinitionsContext.destroy(); } catch (Exception e) { LOGGER.error("Error in loading BootStrap Extension File. Ignoring contents of : " + beFile.getAbsolutePath() + " .Error message : " + e.getMessage(), e); } } this.bootstrapExtensions = (BootstrapExtension[]) beManager.loadBootstrapExtensions() .toArray(new BootstrapExtension[0]); }
From source file:eu.scape_project.up2ti.Unpack2TempIdentify.java
/** * Start/*from w w w.ja v a 2 s.c om*/ * * @param args Command line arguments * @throws ParseException * @throws IOException * @throws FileNotFoundException * @throws InterruptedException */ private void start(String[] args) throws ParseException, IOException, FileNotFoundException, InterruptedException { Configuration conf = new Configuration(); // Command line interface config = new Up2tiCliConfig(); CommandLineParser cmdParser = new PosixParser(); GenericOptionsParser gop = new GenericOptionsParser(conf, args); Up2tiCliOptions cliOptions = new Up2tiCliOptions(); CommandLine cmd = cmdParser.parse(cliOptions.options, gop.getRemainingArgs()); if ((args.length == 0) || (cmd.hasOption(cliOptions.HELP_OPT))) { cliOptions.exit("Help", 0); } else { cliOptions.initOptions(cmd, config); } // Trying to load spring configuration from local file system (same // directory where the application is executed). If the spring // configuration is not given as a parameter, it is loaded as a // resource from the class path. if (config.getSpringConfig() != null && (new File(config.getSpringConfig()).exists())) { ctx = new FileSystemXmlApplicationContext("file://" + config.getSpringConfig()); } else { ctx = new ClassPathXmlApplicationContext(SPRING_CONFIG_RESOURCE_PATH); } if (!config.isLocal()) { startHadoopJob(conf, config); } else { startApplication(); } }
From source file:se.ivankrizsan.messagecowboy.services.transport.CamelTransportService.java
@Override public synchronized void refreshConnectors() throws IOException { final boolean theConfigRsrcChangedFlag = hasConfigurationResourceBeenModified(); if (theConfigRsrcChangedFlag) { LOGGER.debug("Refreshing Camel configuration"); try {/* w ww. jav a2 s.co m*/ // Tear down previous Camel and Spring context in order. killCamelInstance(); } catch (Exception e) { LOGGER.warn("Failed to stop Camel context to refresh configuration.", e); } // Create a new Spring context for Camel to use. LOGGER.debug("Creating a Camel Spring Context with the following files {}", StringUtils.join(mConfigResourcesLocationPatterns, ",")); mCamelSpringContext = new FileSystemXmlApplicationContext( mConfigResourcesLocationPatterns.toArray(new String[mConfigResourcesLocationPatterns.size()])); mCamelSpringContext.start(); mCamelSpringContext.registerShutdownHook(); // close with JVM. mCamelContext = new SpringCamelContext(mCamelSpringContext); try { // Since Camel is used in MC mainly for externally triggered tasks, // we need to get around the standard non-blocking startup behavior. // Starting the Camel Context and wait for it to finish. BlockingCamelStarter theBlockingCamelStarter = new BlockingCamelStarter(mCamelContext); theBlockingCamelStarter.get(); // Create Camel "clients". mConsumerTemplate = mCamelContext.createConsumerTemplate(); mProducerTemplate = mCamelContext.createProducerTemplate(); } catch (Exception e) { LOGGER.error("Failed to start camel", e); } LOGGER.info("Message Cowboy Transport using Apache Camel {} - Status: {}", mCamelContext.getVersion(), mCamelContext.getStatus().toString()); LOGGER.debug("The following Camel components are available: {}", StringUtils.join(mCamelContext.getComponentNames(), ",")); } else { LOGGER.debug("No changes in configuration resources, skips refresh"); } }
From source file:net.bioclipse.structuredb.business.StructuredbManager.java
private ApplicationContext createApplicationcontext(String databaseName, boolean local) { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( Structuredb.class.getClassLoader().getResource("applicationContext.xml").toString()); BasicDataSource dataSource = (BasicDataSource) context.getBean("dataSource"); if (local) {// w ww .jav a2 s .co m dataSource.setUrl(HsqldbUtil.getInstance().getConnectionUrl(databaseName + ".sdb")); } else { throw new UnsupportedOperationException("non-local databases not " + "supported in this version"); } return context; }
From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java
/** * Function to create spring bean factory * /*from w ww . j av a 2 s . co m*/ * @return BeanFactory */ public BeanFactory getSpringBeanFactory() { if (beanFactory == null) { String appDir = null; try { // read application directory property file via classpath loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME); // read directory property appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES); } catch (I2B2Exception e) { log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath "); } if (appDir != null) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "file:" + appDir + "/" + "CRCLoaderApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + "CRCLoaderApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }