1 24 package org.riotfamily.common.beans.xml; 25 26 import java.util.Collection ; 27 28 import org.springframework.beans.MutablePropertyValues; 29 import org.springframework.beans.PropertyValue; 30 import org.springframework.beans.factory.config.BeanDefinition; 31 import org.springframework.beans.factory.config.BeanDefinitionHolder; 32 import org.springframework.beans.factory.support.ManagedList; 33 import org.springframework.beans.factory.xml.BeanDefinitionDecorator; 34 import org.springframework.beans.factory.xml.ParserContext; 35 import org.w3c.dom.Element ; 36 import org.w3c.dom.Node ; 37 38 public class NestedListDecorator implements BeanDefinitionDecorator { 39 40 private String listPropertyName; 41 42 public NestedListDecorator(String listPropertyName) { 43 this.listPropertyName = listPropertyName; 44 } 45 46 public BeanDefinitionHolder decorate(Node node, 47 BeanDefinitionHolder definition, ParserContext parserContext) { 48 49 BeanDefinition bd = definition.getBeanDefinition(); 50 MutablePropertyValues pvs = bd.getPropertyValues(); 51 Collection c = null; 52 PropertyValue pv = pvs.getPropertyValue(listPropertyName); 53 if (pv != null) { 54 c = (Collection ) pv.getValue(); 55 } 56 if (c == null) { 57 c = new ManagedList(); 58 pvs.addPropertyValue(listPropertyName, c); 59 } 60 c.add(parserContext.getDelegate().parsePropertySubElement((Element ) node, bd)); 61 return definition; 62 } 63 } | Popular Tags |