List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:org.axiom_tools.context.SpringContext.java
/** * Configures this context to load data from the file system. * * @return this context/*w w w .ja v a 2s . c o m*/ */ public SpringContext fromFileSystem() { this.cachedContext = new FileSystemXmlApplicationContext(this.contextName); return this; }
From source file:org.intalio.deploy.deployment.ws.DeployWS.java
protected void initialize() { try {/* w w w .j av a 2s .c o m*/ synchronized (DeployWS.class) { if (_instance != null) return; LOG.debug("Initializing configuration."); String configDir = System.getProperty(CONFIG_DIR_PROPERTY); if (configDir == null) { throw new RuntimeException("System property " + CONFIG_DIR_PROPERTY + " not defined."); } _configDir = new File(configDir); if (!_configDir.exists()) { throw new RuntimeException( "Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist."); } ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { Collection<String> configPaths = new HashSet<String>(); File jmxConfigFile = new File(_configDir, "jmx.xml"); if (jmxConfigFile.exists()) { configPaths.add(String.valueOf(jmxConfigFile.toURI())); } File clusterConfigFile = new File(_configDir, "cluster-config.xml"); if (clusterConfigFile.exists()) { configPaths.add(String.valueOf(clusterConfigFile.toURI())); } configPaths.add(String.valueOf(new File(_configDir, "deploy-service.xml").toURI())); FileSystemXmlApplicationContext factory = new FileSystemXmlApplicationContext( configPaths.toArray(new String[] {})); if (_deployService != null) { _deployService.stop(); } _deployService = (DeploymentServiceImpl) factory.getBean("deploymentService"); if (LOG.isDebugEnabled()) LOG.debug("MBeanServer used: " + _deployService.getDeployMBeanServer()); Cluster cluster = null; try { cluster = (Cluster) factory.getBean("clusterConfig"); } catch (NoSuchBeanDefinitionException nsbde) { // not defined } if (cluster != null) { if (LOG.isInfoEnabled()) LOG.info("Found clustering configuration at:" + configPaths + "."); if (cluster.getListener() instanceof NullClusterListener) { cluster.setListener(_deployService); } _deployService.setCluster(cluster); } _deployService.init(); _deployService.start(); _instance = this; } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } } } catch (RuntimeException except) { LOG.error("Error during initialization of deployment service", except); throw except; } catch (Exception e) { LOG.error("Error during initialization of deployment service", e); throw new RuntimeException(e); } }
From source file:org.openspaces.security.ldap.ActiveDirectorySpringSecurityManager.java
/** * Initialize the security manager using the spring security configuration. *///from ww w . j a va2s .co m public void init(Properties properties) throws SecurityException { String configLocation = properties.getProperty(SPRING_SECURITY_CONFIG_LOCATION, "security-config.xml"); if (logger.isLoggable(Level.CONFIG)) { logger.config("spring-security-config-location: " + configLocation + ", absolute path: " + new File(configLocation).getAbsolutePath()); } /* * Extract Spring AuthenticationManager definition */ applicationContext = new FileSystemXmlApplicationContext(configLocation); Map<String, AuthenticationManager> beansOfType = applicationContext .getBeansOfType(AuthenticationManager.class); if (beansOfType.isEmpty()) { throw new SecurityException("No bean of type '" + AuthenticationManager.class.getName() + "' is defined in " + configLocation); } if (beansOfType.size() > 1) { throw new SecurityException("More than one bean of type '" + AuthenticationManager.class.getName() + "' is defined in " + configLocation); } authenticationManager = beansOfType.values().iterator().next(); /* * Extract Group mapper implementation */ groupMapper = (ActiveDirectoryGroupMapper) applicationContext.getBean(ActiveDirectoryGroupMapper.class); if (groupMapper == null) { throw new SecurityException("No bean for active directory group mapper defined"); } }
From source file:it.uniud.ailab.dcore.DistillerFactory.java
/** * Instantiates a Distiller object using the specified configuration and * returns it.//from w w w .ja va2s . c o m * * @param path the path where the config file is located * @return a Distiller ready to work. */ public static Distiller loadFromXML(File path) { // We add the file:// thing before because, for some ??? reason, // the Spring Framework decided that all paths are relative paths. // So, we get the file, retrieve is absolute path, and then add the // file:// prefix to be sure that the Spring Frameworks treats // all paths as absolute paths. // This is less problematic, because the Java platform will handle the // File and produce its absolute path, even if it has been created // using a relative one. ApplicationContext context = new FileSystemXmlApplicationContext("file://" + path.getAbsolutePath()); return (Distiller) context.getBean("distiller"); }
From source file:jmona.driver.MainTester.java
/** * Test method for {@link jmona.driver.Main#main(java.lang.String[])} with * multiple Processors./*from w w w .jav a 2s . c om*/ */ @Ignore @Test public void testMultipleProcessors() { Main.main(new String[] { CONFIG_MULTIPLE_PROCESSORS }); // TODO how can we access objects in the application context created in // Main? final ApplicationContext context = new FileSystemXmlApplicationContext(CONFIG_MULTIPLE_PROCESSORS_PATH); final ExampleProcessor processor1 = context.getBean("processor1", ExampleProcessor.class); final ExampleProcessor processor2 = context.getBean("processor2", ExampleProcessor.class); final int generations = context.getBean("maxGenerations", Integer.class); assertEquals(generations, processor1.count()); assertEquals(generations / 2, processor2.count()); }
From source file:edu.harvard.i2b2.pm.util.PMUtil.java
/** * Return the ontology spring config//from w ww . j ava 2 s. 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 + "/" + "PMApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + "PMApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }
From source file:com.espertech.esperio.SpringContextLoader.java
private AbstractXmlApplicationContext createSpringApplicationContext(String configuration, boolean fromClassPath) { if (fromClassPath) { log.debug("classpath configuration"); return new ClassPathXmlApplicationContext(configuration); }//w w w . java 2s . c om if (new File(configuration).exists()) { log.debug("File configuration"); return new FileSystemXmlApplicationContext(configuration); } else { throw new EPException("Spring configuration file not found."); } }
From source file:com.fusesource.forge.jmstest.config.SpringConfigHelper.java
public ApplicationContext getApplicationContext() { if (applicationContext == null) { String[] configLocations = new String[getSpringConfigLocations().size()]; int i = 0; for (String location : getSpringConfigLocations()) { System.err.println("spring location -> " + location); configLocations[i++] = "file://" + location; }/*ww w. ja va 2 s. co m*/ try { applicationContext = new FileSystemXmlApplicationContext(configLocations); } catch (BeansException be) { log().error("Could not create Application Context.", be); } if (log().isDebugEnabled()) { for (String beanName : applicationContext.getBeanDefinitionNames()) { log().debug("Found bean: " + beanName); } } } return applicationContext; }
From source file:com.sliu.framework.app.sys.security.DefaultInvocationSecurityMetadataSource.java
public void loadSecurityMetadataSource() throws Exception { ApplicationContext context = null;//from ww w.j a va2 s .c o m if (menu.getFile().getAbsolutePath().startsWith("/")) { context = new ClassPathXmlApplicationContext("/spring/menu.xml"); } else { context = new FileSystemXmlApplicationContext(menu.getFile().getPath()); } List<String> resourceList = (List<String>) context.getBean("resourceList"); Map<Long, List<Function>> functionChildMap = new HashMap<Long, List<Function>>(); Map<Long, Function> functionMap = new HashMap<Long, Function>(); functionChildMap.put(0L, new LinkedList<Function>()); idUrlMap = new HashMap<String, String>(); Map<Long, List<String>> resourceRoleMapList = new HashMap<Long, List<String>>(); try { List<Map<String, Object>> list = jsBO.listAllRoleResources(); for (Map<String, Object> resourceRole : list) { Long id = NumberUtils.toLong((String) resourceRole.get("resourceId")); List<String> rl = resourceRoleMapList.get(id); if (rl != null) { rl.add((String) resourceRole.get("roleName")); } else { rl = new ArrayList<String>(); rl.add((String) resourceRole.get("roleName")); resourceRoleMapList.put(id, rl); } } } catch (Exception e) { log.error("", "", e); } try { httpMap = new LinkedHashMap<Object, Collection<ConfigAttribute>>(); List<Function> functionList = new ArrayList<Function>(); for (String fun : resourceList) { String[] props = fun.split(","); Function function = new Function(); if (StringUtils.isNotBlank(props[0])) { function.setId(NumberUtils.toLong(props[0])); } if (StringUtils.isNotBlank(props[1])) { function.setParentId(NumberUtils.toLong(props[1])); } else { function.setParentId(0L); } if (StringUtils.isNotBlank(props[2])) { function.setName(props[2]); } if (StringUtils.isNotBlank(props[3])) { function.setUrl(props[3]); } function.setOrderno(NumberUtils.toInt(props[4], 0)); if (StringUtils.isNotBlank(props[5])) { function.setRolenames(Arrays.asList(StringUtils.split(props[5], "|"))); } if (props.length >= 7) function.setIconcls(props[6]); functionList.add(function); functionMap.put(function.getId(), function); functionChildMap.put(function.getId(), new LinkedList<Function>()); idUrlMap.put(function.getId().toString(), function.getUrl()); } for (Function function : functionList) { List<Function> childList = functionChildMap.get(function.getParentId()); if (childList != null) childList.add(function); if (function.getUrl() == null) continue; Collection<ConfigAttribute> attrs = new HashSet<ConfigAttribute>(); List<String> roles = resourceRoleMapList.get(function.getId()); if (roles != null) { for (String rolename : roles) { attrs.add(new SecurityConfig(rolename)); } } if (function.getRolenames() != null) { for (String rolename : function.getRolenames()) { attrs.add(new SecurityConfig(rolename)); } } function.setAuthorities(attrs); if (attrs.size() != 0) { httpMap.put(this.urlMatcher.compile(function.getUrl()), attrs); log.info("reload", function.getName() + "[" + function.getUrl() + "] - " + attrs); } } Cache cache = this.cacheManager.getCache("resources"); cache.put("FilterInvoSecMetaKey", this.httpMap); cache.put("FunctionChildMap", functionChildMap); cache.put("FunctionMap", functionMap); cache.put("functionList", functionList); lastmodified = menu.getFile().lastModified(); } catch (Exception e) { log.error("", "", e); } }
From source file:org.danann.cernunnos.runtime.web.CernunnosServlet.java
@SuppressWarnings("unchecked") @Override/*from ww w.jav a2s . c o m*/ public void init() throws ServletException { ServletConfig config = getServletConfig(); // Load the context, if present... try { // Bootstrap the servlet Grammar instance... final Grammar root = XmlGrammar.getMainGrammar(); final InputStream inpt = CernunnosServlet.class.getResourceAsStream("servlet.grammar"); // Can't rely on classpath:// protocol handler... final Document doc = new SAXReader().read(inpt); final Task k = new ScriptRunner(root).compileTask(doc.getRootElement()); final RuntimeRequestResponse req = new RuntimeRequestResponse(); final ReturnValueImpl rslt = new ReturnValueImpl(); req.setAttribute(Attributes.RETURN_VALUE, rslt); k.perform(req, new RuntimeRequestResponse()); Grammar g = (Grammar) rslt.getValue(); runner = new ScriptRunner(g); // Choose a context location & load it if it exists... String defaultLoc = "/WEB-INF/" + config.getServletName() + "-portlet.xml"; URL defaultUrl = getServletConfig().getServletContext().getResource(defaultLoc); URL u = Settings.locateContextConfig( getServletConfig().getServletContext().getResource("/").toExternalForm(), config.getInitParameter(CONFIG_LOCATION_PARAM), defaultUrl); if (u != null) { // There *is* a resource mapped to this path name... spring_context = new FileSystemXmlApplicationContext(u.toExternalForm()); } if (log.isDebugEnabled()) { log.debug("Location of spring context (null means none): " + u); } // Load the Settings... Map<String, String> settingsMap = new HashMap<String, String>(); // default... if (spring_context != null && spring_context.containsBean("settings")) { settingsMap = (Map<String, String>) spring_context.getBean("settings"); } settings = Settings.load(settingsMap); } catch (Throwable t) { String msg = "Failure in CernunnosServlet.init()"; throw new ServletException(msg, t); } }