/**
* Given a bean name (assumed to implement {@link org.springframework.core.io.support.PropertiesLoaderSupport})
* checks whether it already references the <code>global-properties</code> bean. If not, 'upgrades' the bean by
* appending all additional resources it mentions in its <code>locations</code> property to
* <code>globalPropertyLocations</code>, except for those resources mentioned in <code>newLocations</code>. A
* reference to <code>global-properties</code> will then be added and the resource list in
* <code>newLocations<code> will then become the new <code>locations</code> list for the bean.
*
* @param beanFactory
* the bean factory
* @param globalPropertyLocations
* the list of global property locations to be appended to
* @param beanName
* the bean name
* @param newLocations
* the new locations to be set on the bean
* @return the mutable property values
*/
@SuppressWarnings("unchecked")
private MutablePropertyValues processLocations(ConfigurableListableBeanFactory beanFactory,
Collection<Object> globalPropertyLocations, String beanName, String[] newLocations)
{
// Get the bean an check its existing properties value
MutablePropertyValues beanProperties = beanFactory.getBeanDefinition(beanName).getPropertyValues();
PropertyValue pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES);
Object value;
// If the properties value already references the global-properties bean, we have nothing else to do. Otherwise,
// we have to 'upgrade' the bean definition.
if (pv == null || (value = pv.getValue()) == null || !(value instanceof BeanReference)
|| ((BeanReference) value).getBeanName().equals(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES))
{
// Convert the array of new locations to a managed list of type string values, so that it is
// compatible with a bean definition
Collection<Object> newLocationList = new ManagedList(newLocations.length);
if (newLocations != null && newLocations.length > 0)
{
for (String preserveLocation : newLocations)
{
newLocationList.add(new TypedStringValue(preserveLocation));
}
}
// If there is currently a locations list, process it
pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
if (pv != null && (value = pv.getValue()) != null && value instanceof Collection)
{
Collection<Object> locations = (Collection<Object>) value;
// Compute the set of locations that need to be added to globalPropertyLocations (preserving order) and
// warn about each
Set<Object> addedLocations = new LinkedHashSet<Object>(locations);
addedLocations.removeAll(globalPropertyLocations);
addedLocations.removeAll(newLocationList);
for (Object location : addedLocations)
{
LegacyConfigPostProcessor.logger.warn("Legacy configuration detected: adding "
+ (location instanceof TypedStringValue ? ((TypedStringValue) location).getValue()
: location.toString()) + " to global-properties definition");
globalPropertyLocations.add(location);
}
}
// Ensure the bean now references global-properties
beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES, new RuntimeBeanReference(
LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES));
// Ensure the new location list is now set on the bean
if (newLocationList.size() > 0)
{
beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, newLocationList);
}
else
{
beanProperties.removePropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
}
}
return beanProperties;
}
LegacyConfigPostProcessor.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:alfresco-repository
作者:
评论列表
文章目录