Java Code Examples for org.springframework.core.io.support.PropertiesLoaderUtils#fillProperties()

The following examples show how to use org.springframework.core.io.support.PropertiesLoaderUtils#fillProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyNamingStrategy.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 2
Source File: KeyNamingStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 3
Source File: KeyNamingStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 4
Source File: KeyNamingStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 5
Source File: KafkaMessageSenderPool.java    From message-queue-client-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
    }
}
 
Example 6
Source File: KafkaMessageNewReceiverPool.java    From message-queue-client-framework with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 7
Source File: KafkaMessageNewSenderPool.java    From message-queue-client-framework with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 8
Source File: KafkaMessageReceiverPool.java    From message-queue-client-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
    }
}
 
Example 9
Source File: SchedulerFactoryBean.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: FreeMarkerConfigurationFactory.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: SchedulerFactoryBean.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: FreeMarkerConfigurationFactory.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: SchedulerFactoryBean.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: FreeMarkerConfigurationFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: SchedulerFactoryBean.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: FreeMarkerConfigurationFactory.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}