assertTargetPresent();
String beanClass = bean.getBeanDefinition().getBeanClassName();
PropertyValues sourceProperties = bean.getRawBeanDefinition().getPropertyValues();
String newName = bestGuessName(targetConfig, oldName, target.getBeanClassName());
MutablePropertyValues targetProperties = target.getPropertyValues();
PropertyValue pv = targetProperties.getPropertyValue(newName);
Object oldValue = null == pv ? null : pv.getValue();
if (! targetConfig.isIgnored(oldName))
{
if (targetConfig.isCollection(oldName) ||
beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName()))
{
if (null == oldValue)
{
if (beanClass.equals(ChildMapEntryDefinitionParser.KeyValuePair.class.getName()) ||
beanClass.equals(MapEntryCombiner.class.getName()) ||
beanClass.equals(MapFactoryBean.class.getName()))
{
// a collection of maps requires an extra intermediate object that does the
// lazy combination/caching of maps when first used
BeanDefinitionBuilder combiner = BeanDefinitionBuilder.rootBeanDefinition(MapCombiner.class);
targetProperties.addPropertyValue(newName, combiner.getBeanDefinition());
MutablePropertyValues combinerProperties = combiner.getBeanDefinition().getPropertyValues();
oldValue = new ManagedList();
pv = new PropertyValue(MapCombiner.LIST, oldValue);
combinerProperties.addPropertyValue(pv);
}
else
{
oldValue = new ManagedList();
pv = new PropertyValue(newName, oldValue);
targetProperties.addPropertyValue(pv);
}
}
List list = retrieveList(oldValue);
if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass))
{
list.add(new ManagedMap());
retrieveMap(list.get(list.size() - 1)).put(
sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(),
sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue());
}
else if (beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName()))
{
list.add(sourceProperties.getPropertyValue(ChildListEntryDefinitionParser.VALUE).getValue());
}
else
{
list.add(bean.getBeanDefinition());
}
}
else
{
// not a collection
if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass))
{
if (null == pv || null == oldValue)
{
pv = new PropertyValue(newName, new ManagedMap());
targetProperties.addPropertyValue(pv);
}
retrieveMap(pv.getValue()).put(
sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(),
sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue());
}
else
{