org.springframework.core.io.support.PropertiesLoaderUtils#fillProperties ( )源码实例Demo

下面列出了org.springframework.core.io.support.PropertiesLoaderUtils#fillProperties ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring4-understanding   文件: KeyNamingStrategy.java
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 * @throws IOException
 */
@Override
public void afterPropertiesSet() throws IOException {
	this.mergedMappings = new Properties();

	CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

	if (this.mappingLocations != null) {
		for (int i = 0; i < this.mappingLocations.length; i++) {
			Resource location = this.mappingLocations[i];
			if (logger.isInfoEnabled()) {
				logger.info("Loading JMX object name mappings file from " + location);
			}
			PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
		}
	}
}
 
源代码2 项目: spring-analysis-note   文件: KeyNamingStrategy.java
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 */
@Override
public void afterPropertiesSet() throws IOException {
	this.mergedMappings = new Properties();
	CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

	if (this.mappingLocations != null) {
		for (Resource location : this.mappingLocations) {
			if (logger.isDebugEnabled()) {
				logger.debug("Loading JMX object name mappings file from " + location);
			}
			PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
		}
	}
}
 
源代码3 项目: java-technology-stack   文件: KeyNamingStrategy.java
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 */
@Override
public void afterPropertiesSet() throws IOException {
	this.mergedMappings = new Properties();
	CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

	if (this.mappingLocations != null) {
		for (Resource location : this.mappingLocations) {
			if (logger.isDebugEnabled()) {
				logger.debug("Loading JMX object name mappings file from " + location);
			}
			PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
		}
	}
}
 
源代码4 项目: lams   文件: KeyNamingStrategy.java
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 */
@Override
public void afterPropertiesSet() throws IOException {
	this.mergedMappings = new Properties();
	CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

	if (this.mappingLocations != null) {
		for (Resource location : this.mappingLocations) {
			if (logger.isInfoEnabled()) {
				logger.info("Loading JMX object name mappings file from " + location);
			}
			PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
		}
	}
}
 
/**
 * @param config the config to set
 */
public void setConfig(Resource config) {
    this.config = config;
    try {
        PropertiesLoaderUtils.fillProperties(props, this.config);
    } catch (IOException e) {
        logger.error("Fill properties failed.", e);
    }
}
 
/**
 * Sets config.
 *
 * @param config the config
 */
public void setConfig(Resource config) {
    this.config = config;
    try {
        PropertiesLoaderUtils.fillProperties(props, this.config);
    } catch (IOException e) {
        logger.error("Fill properties failed.", e);
    }
}
 
/**
 * Sets config.
 *
 * @param config the config
 */
public void setConfig(Resource config) {
    this.config = config;
    try {
        PropertiesLoaderUtils.fillProperties(props, this.config);
    } catch (IOException e) {
        logger.error("Fill properties failed.", e);
    }
}
 
/**
 * @param config the config to set
 */
public void setConfig(Resource config) {
    this.config = config;
    try {
        PropertiesLoaderUtils.fillProperties(props, this.config);
    } catch (IOException e) {
        logger.error("Fill properties failed.", e);
    }
}
 
/**
 * Initialize the given SchedulerFactory, applying locally defined Quartz properties to it.
 * @param schedulerFactory the SchedulerFactory to initialize
 */
private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws SchedulerException, IOException {
	Properties mergedProps = new Properties();
	if (this.resourceLoader != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
				ResourceLoaderClassLoadHelper.class.getName());
	}

	if (this.taskExecutor != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
				LocalTaskExecutorThreadPool.class.getName());
	}
	else {
		// Set necessary default properties here, as Quartz will not apply
		// its default configuration when explicitly given properties.
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
		mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
	}

	if (this.configLocation != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Loading Quartz config from [" + this.configLocation + "]");
		}
		PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
	}

	CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
	if (this.dataSource != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
	}

	// Determine scheduler name across local settings and Quartz properties...
	if (this.schedulerName != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
	}
	else {
		String nameProp = mergedProps.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
		if (nameProp != null) {
			this.schedulerName = nameProp;
		}
		else if (this.beanName != null) {
			mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.beanName);
			this.schedulerName = this.beanName;
		}
	}

	schedulerFactory.initialize(mergedProps);
}
 
/**
 * Prepare the FreeMarker Configuration and return it.
 * @return the FreeMarker Configuration object
 * @throws IOException if the config file wasn't found
 * @throws TemplateException on FreeMarker initialization failure
 */
public Configuration createConfiguration() throws IOException, TemplateException {
	Configuration config = newConfiguration();
	Properties props = new Properties();

	// Load config file if specified.
	if (this.configLocation != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Loading FreeMarker configuration from " + this.configLocation);
		}
		PropertiesLoaderUtils.fillProperties(props, this.configLocation);
	}

	// Merge local properties if specified.
	if (this.freemarkerSettings != null) {
		props.putAll(this.freemarkerSettings);
	}

	// FreeMarker will only accept known keys in its setSettings and
	// setAllSharedVariables methods.
	if (!props.isEmpty()) {
		config.setSettings(props);
	}

	if (!CollectionUtils.isEmpty(this.freemarkerVariables)) {
		config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
	}

	if (this.defaultEncoding != null) {
		config.setDefaultEncoding(this.defaultEncoding);
	}

	List<TemplateLoader> templateLoaders = new ArrayList<>(this.templateLoaders);

	// Register template loaders that are supposed to kick in early.
	if (this.preTemplateLoaders != null) {
		templateLoaders.addAll(this.preTemplateLoaders);
	}

	// Register default template loaders.
	if (this.templateLoaderPaths != null) {
		for (String path : this.templateLoaderPaths) {
			templateLoaders.add(getTemplateLoaderForPath(path));
		}
	}
	postProcessTemplateLoaders(templateLoaders);

	// Register template loaders that are supposed to kick in late.
	if (this.postTemplateLoaders != null) {
		templateLoaders.addAll(this.postTemplateLoaders);
	}

	TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
	if (loader != null) {
		config.setTemplateLoader(loader);
	}

	postProcessConfiguration(config);
	return config;
}
 
/**
 * Initialize the given SchedulerFactory, applying locally defined Quartz properties to it.
 * @param schedulerFactory the SchedulerFactory to initialize
 */
private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws SchedulerException, IOException {
	Properties mergedProps = new Properties();
	if (this.resourceLoader != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
				ResourceLoaderClassLoadHelper.class.getName());
	}

	if (this.taskExecutor != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
				LocalTaskExecutorThreadPool.class.getName());
	}
	else {
		// Set necessary default properties here, as Quartz will not apply
		// its default configuration when explicitly given properties.
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
		mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
	}

	if (this.configLocation != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Loading Quartz config from [" + this.configLocation + "]");
		}
		PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
	}

	CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
	if (this.dataSource != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
	}

	// Determine scheduler name across local settings and Quartz properties...
	if (this.schedulerName != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
	}
	else {
		String nameProp = mergedProps.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
		if (nameProp != null) {
			this.schedulerName = nameProp;
		}
		else if (this.beanName != null) {
			mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.beanName);
			this.schedulerName = this.beanName;
		}
	}

	schedulerFactory.initialize(mergedProps);
}
 
/**
 * Prepare the FreeMarker Configuration and return it.
 * @return the FreeMarker Configuration object
 * @throws IOException if the config file wasn't found
 * @throws TemplateException on FreeMarker initialization failure
 */
public Configuration createConfiguration() throws IOException, TemplateException {
	Configuration config = newConfiguration();
	Properties props = new Properties();

	// Load config file if specified.
	if (this.configLocation != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Loading FreeMarker configuration from " + this.configLocation);
		}
		PropertiesLoaderUtils.fillProperties(props, this.configLocation);
	}

	// Merge local properties if specified.
	if (this.freemarkerSettings != null) {
		props.putAll(this.freemarkerSettings);
	}

	// FreeMarker will only accept known keys in its setSettings and
	// setAllSharedVariables methods.
	if (!props.isEmpty()) {
		config.setSettings(props);
	}

	if (!CollectionUtils.isEmpty(this.freemarkerVariables)) {
		config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
	}

	if (this.defaultEncoding != null) {
		config.setDefaultEncoding(this.defaultEncoding);
	}

	List<TemplateLoader> templateLoaders = new ArrayList<>(this.templateLoaders);

	// Register template loaders that are supposed to kick in early.
	if (this.preTemplateLoaders != null) {
		templateLoaders.addAll(this.preTemplateLoaders);
	}

	// Register default template loaders.
	if (this.templateLoaderPaths != null) {
		for (String path : this.templateLoaderPaths) {
			templateLoaders.add(getTemplateLoaderForPath(path));
		}
	}
	postProcessTemplateLoaders(templateLoaders);

	// Register template loaders that are supposed to kick in late.
	if (this.postTemplateLoaders != null) {
		templateLoaders.addAll(this.postTemplateLoaders);
	}

	TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
	if (loader != null) {
		config.setTemplateLoader(loader);
	}

	postProcessConfiguration(config);
	return config;
}
 
源代码13 项目: lams   文件: SchedulerFactoryBean.java
/**
 * Load and/or apply Quartz properties to the given SchedulerFactory.
 * @param schedulerFactory the SchedulerFactory to initialize
 */
private void initSchedulerFactory(SchedulerFactory schedulerFactory) throws SchedulerException, IOException {
	if (!(schedulerFactory instanceof StdSchedulerFactory)) {
		if (this.configLocation != null || this.quartzProperties != null ||
				this.taskExecutor != null || this.dataSource != null) {
			throw new IllegalArgumentException(
					"StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory);
		}
		// Otherwise assume that no initialization is necessary...
		return;
	}

	Properties mergedProps = new Properties();

	if (this.resourceLoader != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
				ResourceLoaderClassLoadHelper.class.getName());
	}

	if (this.taskExecutor != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
				LocalTaskExecutorThreadPool.class.getName());
	}
	else {
		// Set necessary default properties here, as Quartz will not apply
		// its default configuration when explicitly given properties.
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
		mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
	}

	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading Quartz config from [" + this.configLocation + "]");
		}
		PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
	}

	CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);

	if (this.dataSource != null) {
		mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
	}

	// Make sure to set the scheduler name as configured in the Spring configuration.
	if (this.schedulerName != null) {
		mergedProps.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
	}

	((StdSchedulerFactory) schedulerFactory).initialize(mergedProps);
}
 
源代码14 项目: lams   文件: FreeMarkerConfigurationFactory.java
/**
 * Prepare the FreeMarker Configuration and return it.
 * @return the FreeMarker Configuration object
 * @throws IOException if the config file wasn't found
 * @throws TemplateException on FreeMarker initialization failure
 */
public Configuration createConfiguration() throws IOException, TemplateException {
	Configuration config = newConfiguration();
	Properties props = new Properties();

	// Load config file if specified.
	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading FreeMarker configuration from " + this.configLocation);
		}
		PropertiesLoaderUtils.fillProperties(props, this.configLocation);
	}

	// Merge local properties if specified.
	if (this.freemarkerSettings != null) {
		props.putAll(this.freemarkerSettings);
	}

	// FreeMarker will only accept known keys in its setSettings and
	// setAllSharedVariables methods.
	if (!props.isEmpty()) {
		config.setSettings(props);
	}

	if (!CollectionUtils.isEmpty(this.freemarkerVariables)) {
		config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
	}

	if (this.defaultEncoding != null) {
		config.setDefaultEncoding(this.defaultEncoding);
	}

	List<TemplateLoader> templateLoaders = new LinkedList<TemplateLoader>(this.templateLoaders);

	// Register template loaders that are supposed to kick in early.
	if (this.preTemplateLoaders != null) {
		templateLoaders.addAll(this.preTemplateLoaders);
	}

	// Register default template loaders.
	if (this.templateLoaderPaths != null) {
		for (String path : this.templateLoaderPaths) {
			templateLoaders.add(getTemplateLoaderForPath(path));
		}
	}
	postProcessTemplateLoaders(templateLoaders);

	// Register template loaders that are supposed to kick in late.
	if (this.postTemplateLoaders != null) {
		templateLoaders.addAll(this.postTemplateLoaders);
	}

	TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
	if (loader != null) {
		config.setTemplateLoader(loader);
	}

	postProcessConfiguration(config);
	return config;
}
 
/**
 * Load and/or apply Quartz properties to the given SchedulerFactory.
 * @param schedulerFactory the SchedulerFactory to initialize
 */
private void initSchedulerFactory(SchedulerFactory schedulerFactory) throws SchedulerException, IOException {
	if (!(schedulerFactory instanceof StdSchedulerFactory)) {
		if (this.configLocation != null || this.quartzProperties != null ||
				this.taskExecutor != null || this.dataSource != null) {
			throw new IllegalArgumentException(
					"StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory);
		}
		// Otherwise assume that no initialization is necessary...
		return;
	}

	Properties mergedProps = new Properties();

	if (this.resourceLoader != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
				ResourceLoaderClassLoadHelper.class.getName());
	}

	if (this.taskExecutor != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
				LocalTaskExecutorThreadPool.class.getName());
	}
	else {
		// Set necessary default properties here, as Quartz will not apply
		// its default configuration when explicitly given properties.
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
		mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
	}

	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading Quartz config from [" + this.configLocation + "]");
		}
		PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
	}

	CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);

	if (this.dataSource != null) {
		mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
	}

	// Make sure to set the scheduler name as configured in the Spring configuration.
	if (this.schedulerName != null) {
		mergedProps.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
	}

	((StdSchedulerFactory) schedulerFactory).initialize(mergedProps);
}
 
/**
 * Prepare the FreeMarker Configuration and return it.
 * @return the FreeMarker Configuration object
 * @throws IOException if the config file wasn't found
 * @throws TemplateException on FreeMarker initialization failure
 */
public Configuration createConfiguration() throws IOException, TemplateException {
	Configuration config = newConfiguration();
	Properties props = new Properties();

	// Load config file if specified.
	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading FreeMarker configuration from " + this.configLocation);
		}
		PropertiesLoaderUtils.fillProperties(props, this.configLocation);
	}

	// Merge local properties if specified.
	if (this.freemarkerSettings != null) {
		props.putAll(this.freemarkerSettings);
	}

	// FreeMarker will only accept known keys in its setSettings and
	// setAllSharedVariables methods.
	if (!props.isEmpty()) {
		config.setSettings(props);
	}

	if (!CollectionUtils.isEmpty(this.freemarkerVariables)) {
		config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
	}

	if (this.defaultEncoding != null) {
		config.setDefaultEncoding(this.defaultEncoding);
	}

	List<TemplateLoader> templateLoaders = new LinkedList<TemplateLoader>(this.templateLoaders);

	// Register template loaders that are supposed to kick in early.
	if (this.preTemplateLoaders != null) {
		templateLoaders.addAll(this.preTemplateLoaders);
	}

	// Register default template loaders.
	if (this.templateLoaderPaths != null) {
		for (String path : this.templateLoaderPaths) {
			templateLoaders.add(getTemplateLoaderForPath(path));
		}
	}
	postProcessTemplateLoaders(templateLoaders);

	// Register template loaders that are supposed to kick in late.
	if (this.postTemplateLoaders != null) {
		templateLoaders.addAll(this.postTemplateLoaders);
	}

	TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
	if (loader != null) {
		config.setTemplateLoader(loader);
	}

	postProcessConfiguration(config);
	return config;
}