List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:org.apache.ignite.internal.client.impl.ClientPropertiesConfigurationSelfTest.java
/** * Validate spring client configuration. * * @throws Exception In case of any exception. *//*from w ww . j av a 2s. c om*/ public void testSpringConfig() throws Exception { GridClientConfiguration cfg = new FileSystemXmlApplicationContext(GRID_CLIENT_SPRING_CONFIG.toString()) .getBean(GridClientConfiguration.class); assertEquals(Arrays.asList("127.0.0.1:11211"), new ArrayList<>(cfg.getServers())); assertNull(cfg.getSecurityCredentialsProvider()); Collection<GridClientDataConfiguration> dataCfgs = cfg.getDataConfigurations(); assertEquals(1, dataCfgs.size()); GridClientDataConfiguration dataCfg = dataCfgs.iterator().next(); assertEquals("partitioned", dataCfg.getName()); assertNotNull(dataCfg.getPinnedBalancer()); assertEquals(GridClientRandomBalancer.class, dataCfg.getPinnedBalancer().getClass()); assertNotNull(dataCfg.getAffinity()); assertEquals(GridClientPartitionAffinity.class, dataCfg.getAffinity().getClass()); }
From source file:org.apache.ignite.startup.GridRandomCommandLineLoader.java
/** * Initializes configurations.//from ww w . ja v a 2s.c om * * @param springCfgPath Configuration file path. * @param logCfgPath Log file name. * @return List of configurations. * @throws IgniteCheckedException If an error occurs. */ @SuppressWarnings("unchecked") private static IgniteConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) throws IgniteCheckedException { assert springCfgPath != null; File path = GridTestUtils.resolveIgnitePath(springCfgPath); if (path == null) throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME."); if (!path.isFile()) throw new IgniteCheckedException("Provided file path is not a file: " + path); // Add no-op logger to remove no-appender warning. Appender app = new NullAppender(); Logger.getRootLogger().addAppender(app); ApplicationContext springCtx; try { springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); } catch (BeansException | MalformedURLException e) { throw new IgniteCheckedException( "Failed to instantiate Spring XML application context: " + e.getMessage(), e); } Map cfgMap; try { // Note: Spring is not generics-friendly. cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); } catch (BeansException e) { throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null) throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); // Remove previously added no-op logger. Logger.getRootLogger().removeAppender(app); if (cfgMap.size() != 1) throw new IgniteCheckedException( "Spring configuration file should contain exactly 1 grid configuration: " + path); IgniteConfiguration cfg = (IgniteConfiguration) F.first(cfgMap.values()); assert cfg != null; if (logCfgPath != null) cfg.setGridLogger(new GridTestLog4jLogger(U.resolveIgniteUrl(logCfgPath))); return cfg; }
From source file:org.apache.ignite.startup.GridVmNodesStarter.java
/** * Initializes configurations.// w ww . j a va 2 s .c o m * * * @param springCfgPath Configuration file path. * @return List of configurations. * @throws IgniteCheckedException If an error occurs. */ @SuppressWarnings("unchecked") private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath) throws IgniteCheckedException { File path = GridTestUtils.resolveIgnitePath(springCfgPath); if (path == null) throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME."); if (!path.isFile()) throw new IgniteCheckedException("Provided file path is not a file: " + path); // Add no-op logger to remove no-appender warning. Appender app = new NullAppender(); Logger.getRootLogger().addAppender(app); ApplicationContext springCtx; try { springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); } catch (BeansException | MalformedURLException e) { throw new IgniteCheckedException( "Failed to instantiate Spring XML application context: " + e.getMessage(), e); } Map cfgMap; try { // Note: Spring is not generics-friendly. cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); } catch (BeansException e) { throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null) throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); // Remove previously added no-op logger. Logger.getRootLogger().removeAppender(app); if (cfgMap.isEmpty()) throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); Collection<IgniteConfiguration> res = new ArrayList<>(); for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) { res.add(cfg); cfg.setIgniteInstanceName(IGNITE_INSTANCE_NAME_PREF + gridCnt.incrementAndGet()); } return res; }
From source file:org.apache.oodt.cas.pge.PGETaskInstance.java
protected ProductCrawler createProductCrawler() throws MalformedURLException, IllegalAccessException, CrawlerActionException, MetExtractionException, InstantiationException, FileNotFoundException, ClassNotFoundException { /* create a ProductCrawler based on whether or not the output dir specifies a MIME_EXTRACTOR_REPO */ logger.info("Configuring ProductCrawler..."); ProductCrawler crawler;/* ww w .ja va 2s . c o m*/ if (pgeMetadata.getMetadata(MIME_EXTRACTOR_REPO) != null && !pgeMetadata.getMetadata(MIME_EXTRACTOR_REPO).equals("")) { crawler = new AutoDetectProductCrawler(); ((AutoDetectProductCrawler) crawler).setMimeExtractorRepo(pgeMetadata.getMetadata(MIME_EXTRACTOR_REPO)); } else { crawler = new StdProductCrawler(); } crawler.setClientTransferer(pgeMetadata.getMetadata(INGEST_CLIENT_TRANSFER_SERVICE_FACTORY)); crawler.setFilemgrUrl(pgeMetadata.getMetadata(INGEST_FILE_MANAGER_URL)); String crawlerConfigFile = pgeMetadata.getMetadata(CRAWLER_CONFIG_FILE); if (!Strings.isNullOrEmpty(crawlerConfigFile)) { crawler.setApplicationContext(new FileSystemXmlApplicationContext(crawlerConfigFile)); List<String> actionIds = pgeMetadata.getAllMetadata(ACTION_IDS); if (actionIds != null) { crawler.setActionIds(actionIds); } } crawler.setRequiredMetadata(pgeMetadata.getAllMetadata(REQUIRED_METADATA)); crawler.setCrawlForDirs(Boolean.parseBoolean(pgeMetadata.getMetadata(CRAWLER_CRAWL_FOR_DIRS))); crawler.setNoRecur(!Boolean.parseBoolean(pgeMetadata.getMetadata(CRAWLER_RECUR))); logger.fine("Passing Workflow Metadata to CAS-Crawler as global metadata . . ."); crawler.setGlobalMetadata(pgeMetadata.asMetadata(PgeMetadata.Type.DYNAMIC)); logger.fine("Created ProductCrawler [" + crawler.getClass().getCanonicalName() + "]"); return crawler; }
From source file:org.apache.oodt.cas.protocol.config.SpringProtocolConfig.java
public SpringProtocolConfig(String configFile) { Validate.notNull(configFile, "SpringProtocolConfig configFile cannnot be NULL"); factoryMap = new ConcurrentHashMap<String, List<ProtocolFactory>>(); loadFactories(new FileSystemXmlApplicationContext(configFile)); }
From source file:org.asqatasun.runner.Asqatasun.java
/** * * @param asqatasunHome/*from w w w .j a v a2 s . com*/ */ private void initServices(String asqatasunHome) { ApplicationContext springApplicationContext = new FileSystemXmlApplicationContext( asqatasunHome + "/" + APPLICATION_CONTEXT_FILE_PATH); BeanFactory springBeanFactory = springApplicationContext; auditService = (AuditService) springBeanFactory.getBean("auditService"); auditDataService = (AuditDataService) springBeanFactory.getBean("auditDataService"); webResourceDataService = (WebResourceDataService) springBeanFactory.getBean("webResourceDataService"); webResourceStatisticsDataService = (WebResourceStatisticsDataService) springBeanFactory .getBean("webResourceStatisticsDataService"); processResultDataService = (ProcessResultDataService) springBeanFactory.getBean("processResultDataService"); processRemarkDataService = (ProcessRemarkDataService) springBeanFactory.getBean("processRemarkDataService"); parameterDataService = (ParameterDataService) springBeanFactory.getBean("parameterDataService"); parameterElementDataService = (ParameterElementDataService) springBeanFactory .getBean("parameterElementDataService"); auditService.add(this); }
From source file:org.dd4t.test.DD4TModelConverter.java
public static void main(String[] args) throws IOException, XMLStreamException, SerializationException { // Load Spring ApplicationContext context = new FileSystemXmlApplicationContext( "dd4t-test/target/classes/application-context.xml"); // System.out.println(testXml + xml2 + xml3); String completeXml = FileUtils .readFileToString(new File("dd4t-test/target/classes/xml-without-java-xslt.xml")); ///*from ww w .j av a 2s .c om*/ String homepage = FileUtils.readFileToString(new File("dd4t-test/target/classes/homepage.json")); //System.out.println(completeXml); //deserializeXmlJackson(completeXml); deserializeJson(homepage); }
From source file:org.gridgain.grid.loaders.servlet.GridServletLoader.java
/** * {@inheritDoc}/*from w w w .ja va 2 s . c o m*/ */ @SuppressWarnings({ "unchecked" }) @Override public void init() throws ServletException { // Avoid multiple servlet instances. GridGain should be loaded once. if (loaded == true) { return; } log = new GridJclLogger(LogFactory.getLog("GridGain")); logo(); cfgFile = getServletConfig().getInitParameter(cfgFilePathParam); File path = GridUtils.resolveGridGainPath(cfgFile); if (path == null) { throw new ServletException("Spring XML configuration file path is invalid: " + new File(cfgFile) + ". Note that this path should be either absolute path or a relative path to GRIDGAIN_HOME."); } if (path.isFile() == false) { throw new ServletException("Provided file path is not a file: " + path); } ApplicationContext springCtx = null; try { springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); } catch (BeansException e) { throw new ServletException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); } catch (MalformedURLException e) { throw new ServletException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); } Map cfgMap = null; try { // Note: Spring is not generics-friendly. cfgMap = springCtx.getBeansOfType(GridConfiguration.class); } catch (BeansException e) { throw new ServletException("Failed to instantiate bean [type=" + GridConfiguration.class + ", error=" + e.getMessage() + ']', e); } if (cfgMap == null) { throw new ServletException("Failed to find a single grid factory configuration in: " + path); } if (cfgMap.size() == 0) { throw new ServletException("Can't find grid factory configuration in: " + path); } try { for (GridConfiguration cfg : (Collection<GridConfiguration>) cfgMap.values()) { assert cfg != null : "ASSERTION [line=221, file=src/java/org/gridgain/grid/loaders/servlet/GridServletLoader.java]"; GridConfigurationAdapter adapter = new GridConfigurationAdapter(cfg); // Set Glassfish logger. if (cfg.getGridLogger() == null) { adapter.setGridLogger(log); } Grid grid = GridFactory.start(adapter, springCtx); // Test if grid is not null - started properly. if (grid != null) { gridNames.add(grid.getName()); } } } catch (GridException e) { // Stop started grids only. for (String name : gridNames) { GridFactory.stop(name, true); } throw new ServletException("Failed to start GridGain.", e); } loaded = true; }
From source file:org.gridgain.startup.GridRandomCommandLineLoader.java
/** * Initializes configurations./*from w w w. ja v a2 s.c om*/ * * @param springCfgPath Configuration file path. * @param logCfgPath Log file name. * @return List of configurations. * @throws GridException If an error occurs. */ @SuppressWarnings("unchecked") private static GridConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) throws GridException { assert springCfgPath != null; File path = GridTestUtils.resolveGridGainPath(springCfgPath); if (path == null) throw new GridException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to GRIDGAIN_HOME."); if (!path.isFile()) throw new GridException("Provided file path is not a file: " + path); // Add no-op logger to remove no-appender warning. Appender app = new NullAppender(); Logger.getRootLogger().addAppender(app); ApplicationContext springCtx; try { springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); } catch (BeansException | MalformedURLException e) { throw new GridException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); } Map cfgMap; try { // Note: Spring is not generics-friendly. cfgMap = springCtx.getBeansOfType(GridConfiguration.class); } catch (BeansException e) { throw new GridException( "Failed to instantiate bean [type=" + GridConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null) throw new GridException("Failed to find a single grid factory configuration in: " + path); // Remove previously added no-op logger. Logger.getRootLogger().removeAppender(app); if (cfgMap.size() != 1) throw new GridException( "Spring configuration file should contain exactly 1 grid configuration: " + path); GridConfiguration cfg = (GridConfiguration) F.first(cfgMap.values()); assert cfg != null; if (logCfgPath != null) cfg.setGridLogger(new GridTestLog4jLogger(U.resolveGridGainUrl(logCfgPath))); return cfg; }
From source file:org.gridgain.startup.GridVmNodesStarter.java
/** * Initializes configurations./*from w ww . j a v a 2s.com*/ * * * @param springCfgPath Configuration file path. * @return List of configurations. * @throws GridException If an error occurs. */ @SuppressWarnings("unchecked") private static Iterable<GridConfiguration> getConfigurations(String springCfgPath) throws GridException { File path = GridTestUtils.resolveGridGainPath(springCfgPath); if (path == null) throw new GridException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to GRIDGAIN_HOME."); if (!path.isFile()) throw new GridException("Provided file path is not a file: " + path); // Add no-op logger to remove no-appender warning. Appender app = new NullAppender(); Logger.getRootLogger().addAppender(app); ApplicationContext springCtx; try { springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); } catch (BeansException | MalformedURLException e) { throw new GridException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); } Map cfgMap; try { // Note: Spring is not generics-friendly. cfgMap = springCtx.getBeansOfType(GridConfiguration.class); } catch (BeansException e) { throw new GridException( "Failed to instantiate bean [type=" + GridConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null) throw new GridException("Failed to find a single grid factory configuration in: " + path); // Remove previously added no-op logger. Logger.getRootLogger().removeAppender(app); if (cfgMap.isEmpty()) throw new GridException("Can't find grid factory configuration in: " + path); Collection<GridConfiguration> res = new ArrayList<>(); for (GridConfiguration cfg : (Collection<GridConfiguration>) cfgMap.values()) { res.add(cfg); cfg.setGridName(GRID_NAME_PREF + gridCnt.incrementAndGet()); } return res; }