Java Code Examples for org.springframework.util.CollectionUtils#mergePropertiesIntoMap()

The following examples show how to use org.springframework.util.CollectionUtils#mergePropertiesIntoMap() . 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: SakaiProperties.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Return a merged Properties instance containing both the loaded properties 
 * and properties set on this FactoryBean.
 */
protected Properties mergeProperties() throws IOException {
    Properties result = new Properties();

    if (this.localOverride) {
        // Load properties from file upfront, to let local properties override.
        loadProperties(result);
    }

    if (this.localProperties != null) {
        for (int i = 0; i < this.localProperties.length; i++) {
            loadedProperties.put("local"+i, this.localProperties[i]);
            CollectionUtils.mergePropertiesIntoMap(this.localProperties[i], result);
        }
    }

    if (!this.localOverride) {
        // Load properties from file afterwards, to let those properties override.
        loadProperties(result);
    }

    if (log.isInfoEnabled()) log.info("Loaded a total of "+result.size()+" properties");
    return result;
}
 
Example 2
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 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: LocalPersistenceManagerFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the PersistenceManagerFactory for the given location.
 * @throws IllegalArgumentException in case of illegal property values
 * @throws IOException if the properties could not be loaded from the given location
 * @throws JDOException in case of JDO initialization errors
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, IOException, JDOException {
	if (this.persistenceManagerFactoryName != null) {
		if (this.configLocation != null || !this.jdoPropertyMap.isEmpty()) {
			throw new IllegalStateException("'configLocation'/'jdoProperties' not supported in " +
					"combination with 'persistenceManagerFactoryName' - specify one or the other, not both");
		}
		if (logger.isInfoEnabled()) {
			logger.info("Building new JDO PersistenceManagerFactory for name '" +
					this.persistenceManagerFactoryName + "'");
		}
		this.persistenceManagerFactory = newPersistenceManagerFactory(this.persistenceManagerFactoryName);
	}

	else {
		Map<String, Object> mergedProps = new HashMap<String, Object>();
		if (this.configLocation != null) {
			if (logger.isInfoEnabled()) {
				logger.info("Loading JDO config from [" + this.configLocation + "]");
			}
			CollectionUtils.mergePropertiesIntoMap(
					PropertiesLoaderUtils.loadProperties(this.configLocation), mergedProps);
		}
		mergedProps.putAll(this.jdoPropertyMap);
		logger.info("Building new JDO PersistenceManagerFactory");
		this.persistenceManagerFactory = newPersistenceManagerFactory(mergedProps);
	}

	// Build default JdoDialect if none explicitly specified.
	if (this.jdoDialect == null) {
		this.jdoDialect = new DefaultJdoDialect(this.persistenceManagerFactory.getConnectionFactory());
	}
}
 
Example 5
Source File: JndiTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new JNDI initial context. Invoked by {@link #getContext}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 * @return the initial Context instance
 * @throws NamingException in case of initialization errors
 */
protected Context createInitialContext() throws NamingException {
	Hashtable<?, ?> icEnv = null;
	Properties env = getEnvironment();
	if (env != null) {
		icEnv = new Hashtable<>(env.size());
		CollectionUtils.mergePropertiesIntoMap(env, icEnv);
	}
	return new InitialContext(icEnv);
}
 
Example 6
Source File: ScriptVariableGeneratorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean(name = "variableGenerator")
public ScriptVariableGenerator scriptVariableGenerator() throws IOException {
	Map<String, Object> variables = new HashMap<>();
	CollectionUtils.mergePropertiesIntoMap(properties.getVariables(), variables);
	if (properties.getVariablesLocation() != null) {
		CollectionUtils.mergePropertiesIntoMap(
				PropertiesLoaderUtils.loadProperties(properties.getVariablesLocation()), variables);
	}
	return new DefaultScriptVariableGenerator(variables);
}
 
Example 7
Source File: ScriptVariableGeneratorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean(name = "variableGenerator")
public ScriptVariableGenerator scriptVariableGenerator() throws IOException {
	Map<String, Object> variables = new HashMap<>();
	CollectionUtils.mergePropertiesIntoMap(properties.getVariables(), variables);
	if (properties.getVariablesLocation() != null) {
		CollectionUtils.mergePropertiesIntoMap(
				PropertiesLoaderUtils.loadProperties(properties.getVariablesLocation()), variables);
	}
	return new DefaultScriptVariableGenerator(variables);
}
 
Example 8
Source File: JndiTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new JNDI initial context. Invoked by {@link #getContext}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 * @return the initial Context instance
 * @throws NamingException in case of initialization errors
 */
protected Context createInitialContext() throws NamingException {
	Hashtable<?, ?> icEnv = null;
	Properties env = getEnvironment();
	if (env != null) {
		icEnv = new Hashtable<>(env.size());
		CollectionUtils.mergePropertiesIntoMap(env, icEnv);
	}
	return new InitialContext(icEnv);
}
 
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: 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 11
Source File: AbstractView.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set static attributes for this view from a
 * {@code java.util.Properties} object.
 * <p>"Static" attributes are fixed attributes that are specified in
 * the View instance configuration. "Dynamic" attributes, on the other hand,
 * are values passed in as part of the model.
 * <p>This is the most convenient way to set static attributes. Note that
 * static attributes can be overridden by dynamic attributes, if a value
 * with the same name is included in the model.
 * <p>Can be populated with a String "value" (parsed via PropertiesEditor)
 * or a "props" element in XML bean definitions.
 * @see org.springframework.beans.propertyeditors.PropertiesEditor
 */
public void setAttributes(Properties attributes) {
	CollectionUtils.mergePropertiesIntoMap(attributes, this.staticAttributes);
}
 
Example 12
Source File: VelocityEngineFactory.java    From MaxKey with Apache License 2.0 2 votes vote down vote up
/**
 * Set Velocity properties, like "file.resource.loader.path".
 * Can be used to override values in a Velocity config file,
 * or to specify all necessary properties locally.
 * <p>Note that the Velocity resource loader path also be set to any
 * Spring resource location via the "resourceLoaderPath" property.
 * Setting it here is just necessary when using a non-file-based
 * resource loader.
 * @see #setVelocityPropertiesMap
 * @see #setConfigLocation
 * @see #setResourceLoaderPath
 */
public void setVelocityProperties(Properties velocityProperties) {
	CollectionUtils.mergePropertiesIntoMap(velocityProperties, this.velocityProperties);
}
 
Example 13
Source File: JpaTransactionManager.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Specify JPA properties, to be passed into
 * {@code EntityManagerFactory.createEntityManager(Map)} (if any).
 * <p>Can be populated with a String "value" (parsed via PropertiesEditor)
 * or a "props" element in XML bean definitions.
 * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map)
 */
public void setJpaProperties(@Nullable Properties jpaProperties) {
	CollectionUtils.mergePropertiesIntoMap(jpaProperties, this.jpaPropertyMap);
}
 
Example 14
Source File: JpaTransactionManager.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Specify JPA properties, to be passed into
 * {@code EntityManagerFactory.createEntityManager(Map)} (if any).
 * <p>Can be populated with a String "value" (parsed via PropertiesEditor)
 * or a "props" element in XML bean definitions.
 * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map)
 */
public void setJpaProperties(Properties jpaProperties) {
	CollectionUtils.mergePropertiesIntoMap(jpaProperties, this.jpaPropertyMap);
}
 
Example 15
Source File: AbstractView.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set static attributes for this view from a
 * {@code java.util.Properties} object.
 * <p>"Static" attributes are fixed attributes that are specified in
 * the View instance configuration. "Dynamic" attributes, on the other hand,
 * are values passed in as part of the model.
 * <p>This is the most convenient way to set static attributes. Note that
 * static attributes can be overridden by dynamic attributes, if a value
 * with the same name is included in the model.
 * <p>Can be populated with a String "value" (parsed via PropertiesEditor)
 * or a "props" element in XML bean definitions.
 * @see org.springframework.beans.propertyeditors.PropertiesEditor
 */
public void setAttributes(Properties attributes) {
	CollectionUtils.mergePropertiesIntoMap(attributes, this.staticAttributes);
}
 
Example 16
Source File: AbstractView.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Set static attributes for this view from a
 * {@code java.util.Properties} object.
 * <p>"Static" attributes are fixed attributes that are specified in
 * the View instance configuration. "Dynamic" attributes, on the other hand,
 * are values passed in as part of the model.
 * <p>This is the most convenient way to set static attributes. Note that
 * static attributes can be overridden by dynamic attributes, if a value
 * with the same name is included in the model.
 * <p>Can be populated with a String "value" (parsed via PropertiesEditor)
 * or a "props" element in XML bean definitions.
 * @see org.springframework.beans.propertyeditors.PropertiesEditor
 */
public void setAttributes(Properties attributes) {
	CollectionUtils.mergePropertiesIntoMap(attributes, this.staticAttributes);
}
 
Example 17
Source File: VelocityEngineFactory.java    From scoold with Apache License 2.0 2 votes vote down vote up
/**
 * Set Velocity properties, like "file.resource.loader.path". Can be used to override values in a Velocity config
 * file, or to specify all necessary properties locally.
 * <p>
 * Note that the Velocity resource loader path also be set to any Spring resource location via the
 * "resourceLoaderPath" property. Setting it here is just necessary when using a non-file-based resource loader.
 *
 * @see #setVelocityPropertiesMap
 * @see #setConfigLocation
 * @see #setResourceLoaderPath
 * @param velocityProperties props
 */
public void setVelocityProperties(Properties velocityProperties) {
	CollectionUtils.mergePropertiesIntoMap(velocityProperties, this.velocityProperties);
}
 
Example 18
Source File: MBeanServerConnectionFactoryBean.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set the environment properties used to construct the {@code JMXConnector}
 * as {@code java.util.Properties} (String key/value pairs).
 */
public void setEnvironment(Properties environment) {
	CollectionUtils.mergePropertiesIntoMap(environment, this.environment);
}
 
Example 19
Source File: SimpleUrlHandlerMapping.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Map URL paths to handler bean names.
 * This is the typical way of configuring this HandlerMapping.
 * <p>Supports direct URL matches and Ant-style pattern matches. For syntax
 * details, see the {@link org.springframework.util.AntPathMatcher} javadoc.
 * @param mappings properties with URLs as keys and bean names as values
 * @see #setUrlMap
 */
public void setMappings(Properties mappings) {
	CollectionUtils.mergePropertiesIntoMap(mappings, this.urlMap);
}
 
Example 20
Source File: VelocityEngineFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set Velocity properties, like "file.resource.loader.path".
 * Can be used to override values in a Velocity config file,
 * or to specify all necessary properties locally.
 * <p>Note that the Velocity resource loader path also be set to any
 * Spring resource location via the "resourceLoaderPath" property.
 * Setting it here is just necessary when using a non-file-based
 * resource loader.
 * @see #setVelocityPropertiesMap
 * @see #setConfigLocation
 * @see #setResourceLoaderPath
 */
public void setVelocityProperties(Properties velocityProperties) {
	CollectionUtils.mergePropertiesIntoMap(velocityProperties, this.velocityProperties);
}