org.springframework.util.CollectionUtils#mergePropertiesIntoMap ( )源码实例Demo

下面列出了org.springframework.util.CollectionUtils#mergePropertiesIntoMap ( ) 实例代码,或者点击链接到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 项目: sakai   文件: SakaiProperties.java
/**
 * 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;
}
 
/**
 * 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());
	}
}
 
源代码4 项目: spring-analysis-note   文件: JndiTemplate.java
/**
 * 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);
}
 
@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);
}
 
@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);
}
 
源代码7 项目: java-technology-stack   文件: JndiTemplate.java
/**
 * 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);
}
 
源代码8 项目: 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);
		}
	}
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码13 项目: lams   文件: AbstractView.java
/**
 * 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);
}
 
源代码14 项目: MaxKey   文件: VelocityEngineFactory.java
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码17 项目: spring-analysis-note   文件: AbstractView.java
/**
 * 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);
}
 
源代码18 项目: java-technology-stack   文件: AbstractView.java
/**
 * 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);
}
 
源代码19 项目: scoold   文件: VelocityEngineFactory.java
/**
 * 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);
}
 
源代码20 项目: lams   文件: VelocityEngineFactory.java
/**
 * 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);
}