1 17 package org.apache.servicemix.jbi.config.spring; 18 19 import org.apache.servicemix.jbi.util.DOMUtil; 20 import org.springframework.beans.factory.support.BeanDefinitionReader; 21 import org.w3c.dom.Attr ; 22 import org.w3c.dom.Element ; 23 import org.w3c.dom.NamedNodeMap ; 24 25 31 public class ElementToPropertyProcessor extends ElementProcessorSupport implements ElementProcessor { 32 private String propertyName; 33 34 public ElementToPropertyProcessor() { 35 } 36 37 public ElementToPropertyProcessor(String propertyName) { 38 this.propertyName = propertyName; 39 } 40 41 public void processElement(Element element, BeanDefinitionReader beanDefinitionReader) { 42 Element bean = (Element ) element.getParentNode(); 43 bean.removeChild(element); 44 45 String name = propertyName; 46 if (name == null) { 47 name = getElementNameToPropertyName(element); 48 } 49 50 addPropertyElement(bean, name, DOMUtil.getElementText(element)); 51 52 processAttributes(element, bean); 53 54 } 55 56 59 protected void processAttributes(Element element, Element bean) { 60 NamedNodeMap attributes = element.getAttributes(); 61 for (int i = 0, size = attributes.getLength(); i < size; i++ ) { 62 Attr node = (Attr ) attributes.item(i); 63 String value = node.getValue(); 64 if (value != null && value.length() > 0) { 65 addPropertyElement(bean, node.getName(), value); 66 } 67 } 68 } 69 70 } 71 | Popular Tags |