1 17 package org.apache.servicemix.jbi.config.spring; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.jbi.util.DOMUtil; 22 import org.springframework.beans.factory.support.BeanDefinitionReader; 23 import org.w3c.dom.Element ; 24 25 import javax.xml.namespace.QName ; 26 27 32 public class QNameElementProcessor extends ElementProcessorSupport implements ElementProcessor { 33 private static final transient Log log = LogFactory.getLog(QNameElementProcessor.class); 34 35 public void processElement(Element element, BeanDefinitionReader beanDefinitionReader) { 36 Element root = (Element ) element.getParentNode(); 37 QName qname = DOMUtil.createQName(element, DOMUtil.getElementText(element)); 38 Element bean = addQNameBeanElement(root, qname); 39 40 root.removeChild(element); 42 43 logXmlGenerated(log, "qname generated", bean); 44 } 45 46 49 protected Element addQNameBeanElement(Element owner, QName qname) { 50 Element bean = addBeanElement(owner, "javax.xml.namespace.QName"); 51 52 String uri = qname.getNamespaceURI(); 53 boolean hasURI = uri != null && uri.length() > 0; 54 if (hasURI) { 55 addConstructorValueNode(bean, uri); 56 } 57 addConstructorValueNode(bean, qname.getLocalPart()); 58 if (hasURI) { 59 String prefix = qname.getPrefix(); 60 if (prefix != null && prefix.length() > 0) { 61 addConstructorValueNode(bean, prefix); 62 } 63 } 64 return bean; 65 } 66 67 protected void addQNameProperty(Element registration, String propertyName, String qnameText, Element namespaceContext) { 68 if (qnameText != null && qnameText.length() > 0) { 69 Element property = addPropertyElement(registration, propertyName); 70 QName qname = DOMUtil.createQName(namespaceContext, qnameText); 71 addQNameBeanElement(property, qname); 72 } 73 } 74 75 } 76 | Popular Tags |