1 16 17 package org.springframework.beans.factory.xml; 18 19 import org.w3c.dom.Attr ; 20 import org.w3c.dom.Element ; 21 import org.w3c.dom.NamedNodeMap ; 22 23 import org.springframework.beans.factory.support.BeanDefinitionBuilder; 24 import org.springframework.core.Conventions; 25 import org.springframework.util.Assert; 26 import org.springframework.util.StringUtils; 27 28 108 public abstract class AbstractSimpleBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { 109 110 126 protected final void doParse(Element element, BeanDefinitionBuilder builder) { 127 NamedNodeMap attributes = element.getAttributes(); 128 for (int x = 0; x < attributes.getLength(); x++) { 129 Attr attribute = (Attr ) attributes.item(x); 130 String name = attribute.getLocalName(); 131 if (isEligibleAttribute(name)) { 132 String propertyName = extractPropertyName(name); 133 Assert.state(StringUtils.hasText(propertyName), 134 "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); 135 builder.addPropertyValue(propertyName, attribute.getValue()); 136 } 137 } 138 postProcess(builder, element); 139 } 140 141 149 protected boolean isEligibleAttribute(String attributeName) { 150 return !ID_ATTRIBUTE.equals(attributeName); 151 } 152 153 166 protected String extractPropertyName(String attributeName) { 167 return Conventions.attributeNameToPropertyName(attributeName); 168 } 169 170 177 protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { 178 } 179 180 } 181 | Popular Tags |