List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer postProcessBeanFactory
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
From source file:org.cagrid.identifiers.namingauthority.util.SecurityUtil.java
public static void addAdmin(String naConfigurationFile, String naProperties, String adminUser) throws InvalidIdentifierException, URISyntaxException, NamingAuthorityConfigurationException, NamingAuthoritySecurityException, InvalidIdentifierValuesException { FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile); FileSystemResource naPropertiesResource = new FileSystemResource(naProperties); XmlBeanFactory factory = new XmlBeanFactory(naConfResource); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(naPropertiesResource); cfg.postProcessBeanFactory(factory); NamingAuthorityImpl na = (NamingAuthorityImpl) factory.getBean("NamingAuthority", MaintainerNamingAuthority.class); na.getIdentifierDao().createInitialAdministrator(adminUser); // KeyData kd = na.getKeyData(null, na.getSystemIdentifier(), Keys.ADMIN_USERS); // if (kd == null) { // System.err.println("KD IS NULL"); // kd = new KeyData(); // }// ww w.j a v a2 s . co m // // List<String> values = kd.getValues(); // if (values == null) { // System.err.println("VALUES IS NULL"); // values = new ArrayList<String>(); // } // // if (values.contains(adminUser)) { // throw new NamingAuthorityConfigurationException("Provided identity [" + adminUser + "] is already an administrator"); // } // // values.add(adminUser); // // IdentifierValues ivalues = new IdentifierValues(); // ivalues.put(Keys.ADMIN_USERS, kd); // na.replaceKeys(null, na.getSystemIdentifier(), ivalues); }
From source file:org.pmedv.core.util.ResourceUtils.java
/** * Configures a factory from a properties file read from an input stream * /*from www. j av a 2 s . co m*/ * @param is the stream to read the properties from * @param factory the factory to configure */ public static Properties configureFactoryFromInputStream(InputStream is, XmlBeanFactory factory) { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties p = new Properties(); try { p.load(is); } catch (IOException e) { e.printStackTrace(); } cfg.setProperties(p); cfg.postProcessBeanFactory(factory); return p; }
From source file:ch.tatool.app.util.ContextUtils.java
/** * Create a new BeanFactory using the main ApplicationContext as parent. * // w ww .java 2 s . c om * @param classpath the path to the bean definition file in the classpath * @param properties set of properties that should be replaced in the definitions * @return a BeanFactory instance */ public static BeanFactory createBeanFactory(String classpath, Properties properties) { // create an empty bean factory DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); // load the context file - has to be done here, otherwise properties won't get resolved XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); Resource resource = new ClassPathResource(classpath); reader.loadBeanDefinitions(resource); // apply the properties to the context PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(properties); configurer.setIgnoreUnresolvablePlaceholders(false); configurer.setIgnoreResourceNotFound(false); configurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK); configurer.postProcessBeanFactory(beanFactory); return beanFactory; }
From source file:org.investovator.agentsimulation.InvestovatorSimulationController.java
@Override public void afterPropertiesSet() throws Exception { //if(!isPropSet){ Object configurer = beanFactory.getBean("configurer"); if (configurer != null) { PropertyPlaceholderConfigurer test = (PropertyPlaceholderConfigurer) configurer; test.postProcessBeanFactory((ConfigurableListableBeanFactory) beanFactory); isPropSet = true;//w w w .ja v a 2s.co m } // } this.simulation = (Simulation) beanFactory.getBean(simulationBeanName); this.simulationScope = SimulationScope.getSingletonInstance(); if (this.simulationFactory == null) { this.simulationFactory = new SpringSimulationFactory(); } }
From source file:com.google.enterprise.connector.filenet4.FileNetConnectorFactory.java
/** * Creates a connector instance by loading the bean definitions and creating * the connector bean instance using Spring * * * @see com.google.enterprise.connector.spi.ConnectorFactory#makeConnector(java.util.Map) **///from w w w . j a v a 2s .c o m @Override public Connector makeConnector(Map<String, String> config) throws RepositoryException { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory); Resource connectorInstanceConfig = new ClassPathResource(CONNECTOR_DEFAULTS_XML); Resource connectorDefaultsConfig = new ClassPathResource(CONNECTOR_INSTANCE_XML); beanReader.loadBeanDefinitions(connectorInstanceConfig); beanReader.loadBeanDefinitions(connectorDefaultsConfig); Properties props = new Properties(); props.putAll(config); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); configurer.postProcessBeanFactory(factory); Connector connector = (Connector) factory.getBean("Filenet_P8"); if (connector == null) { throw new RepositoryException("Filenet_P8 bean could not be loaded"); } return connector; }
From source file:com.google.enterprise.connector.filesystem.ConfigTest.java
public void testInstantiation() { Properties props = new Properties(); props.putAll(goodConfig);// w w w. j a v a 2s .co m DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); // Refer to InstanceInfo.makeConnectorWithSpring //(com.google.enterprise.connector.instantiator) for more info on how // these files are loaded to instantiate connector. reader.loadBeanDefinitions(new ClassPathResource(DEFAULTS_CONFIG_FILE, ConfigTest.class)); reader.loadBeanDefinitions(new ClassPathResource(INSTANCE_CONFIG_FILE, ConfigTest.class)); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setProperties(props); cfg.postProcessBeanFactory(beanFactory); String[] beans = beanFactory.getBeanNamesForType(Connector.class); assertEquals(1, beans.length); Object obj = beanFactory.getBean(beans[0]); assertTrue("Expecting instance of Connector interface but the actual " + "instance: " + obj.getClass().toString(), obj instanceof Connector); }
From source file:com.google.enterprise.connector.db.MockDBConnectorFactory.java
/** * Creates a database connector./*from www . j av a 2 s. c o m*/ * * @param config map of configuration values. */ /* TODO(jlacey): Extract the Spring instantiation code in CM. */ @Override public Connector makeConnector(Map<String, String> config) throws RepositoryException { // TODO(jlacey): The placeholder values are in the EPPC bean in // connectorDefaults.xml, but we're not loading that, and doing so // would unravel a ball of string: using setLocation instead of // setProperties (since the EPPC bean already has properties), // which in turn requires the ByteArrayResource machinery in // InstanceInfo or writing the properties to a file. Properties props = new Properties(); for (String configKey : DBConnectorType.CONFIG_KEYS) { props.put(configKey, ""); } // Escape MyBatis syntax that looks like a Spring placeholder. // See https://jira.springsource.org/browse/SPR-4953 props.put("docIds", "#{'$'}{docIds}"); props.putAll(config); Resource prototype = new ClassPathResource("config/connectorInstance.xml", MockDBConnectorFactory.class); Resource defaults = new ClassPathResource("config/connectorDefaults.xml", MockDBConnectorFactory.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory); try { beanReader.loadBeanDefinitions(prototype); beanReader.loadBeanDefinitions(defaults); } catch (BeansException e) { throw new RepositoryException(e); } PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setProperties(props); cfg.postProcessBeanFactory(factory); String[] beanList = factory.getBeanNamesForType(DiffingConnector.class); Assert.assertEquals(Arrays.asList(beanList).toString(), 1, beanList.length); return (Connector) factory.getBean(beanList[0]); }
From source file:org.archive.wayback.webapp.RequestMapper.java
/** * @param configPath// w w w .j a va2 s . c om * @param servletContext * @throws ConfigurationException */ @SuppressWarnings("unchecked") public RequestMapper(ServletContext servletContext) throws ConfigurationException { String configPath = servletContext.getInitParameter(CONFIG_PATH); if (configPath == null) { throw new ConfigurationException("Missing " + CONFIG_PATH + " parameter"); } String resolvedPath = servletContext.getRealPath(configPath); Resource resource = new FileSystemResource(resolvedPath); factory = new XmlBeanFactory(resource); Map map = factory.getBeansOfType(PropertyPlaceholderConfigurer.class); if (map != null) { Collection<PropertyPlaceholderConfigurer> macros = map.values(); for (PropertyPlaceholderConfigurer macro : macros) { macro.postProcessBeanFactory(factory); } } factory.preInstantiateSingletons(); }
From source file:org.intalio.tempo.security.ws.BaseWS.java
protected void initStatics() { if (_initialized) return;// www .j ava 2 s . co m try { synchronized (BaseWS.class) { if (_initialized) return; LOG.debug("Initializing configuration."); String configDir = System.getProperty(Constants.CONFIG_DIR_PROPERTY); if (configDir == null) { throw new RuntimeException( "System property " + Constants.CONFIG_DIR_PROPERTY + " not defined."); } _configDir = new File(configDir); if (!_configDir.exists()) { throw new RuntimeException( "Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist."); } Thread thread = Thread.currentThread(); ClassLoader oldClassLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getClass().getClassLoader()); FileSystemResource config = new FileSystemResource(new File(_configDir, "securityConfig.xml")); XmlBeanFactory factory = new XmlBeanFactory(config); PropertyPlaceholderConfigurer propsCfg = new PropertyPlaceholderConfigurer(); propsCfg.setSearchSystemEnvironment(true); propsCfg.postProcessBeanFactory(factory); _securityProvider = (SecurityProvider) factory.getBean("securityProvider"); _tokenService = (org.intalio.tempo.security.token.TokenService) factory.getBean("tokenService"); _initialized = true; } finally { thread.setContextClassLoader(oldClassLoader); } } } catch (RuntimeException except) { LOG.error("Error during initialization of security service", except); throw except; } }
From source file:org.pegadi.webapp.spring.PropertyReplacer.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { ServletContextResourceLoader loader = new ServletContextResourceLoader(servletContext); Properties properties = new Properties(); File file = (File) servletContext.getAttribute(DataDirectoryPropertyReplacer.SERVLET_CONTEXT_ATTR); properties.setProperty("dataDir", file.getAbsolutePath()); List<Resource> resources = new ArrayList<Resource>(); resources.add(loader.getResource("/WEB-INF/pegadi.conf")); /* Check wether dataDir/pegadi.conf exist. If it does add it as a location * Also add /WEB-INF/pegadi.conf, so that if the file doesn't exist use default values */// w w w . jav a 2 s .c om File configFile = new File(file.getAbsolutePath(), "pegadi.conf"); if (configFile.exists()) { resources.add(loader.getResource("file:" + configFile.getAbsolutePath())); } PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocations(resources.toArray(new Resource[] {})); configurer.setProperties(properties); configurer.postProcessBeanFactory(configurableListableBeanFactory); }