1 17 package org.apache.servicemix.jbi.deployment.impl; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.jbi.config.spring.ElementProcessor; 22 import org.apache.servicemix.jbi.config.spring.ElementProcessorSupport; 23 import org.apache.servicemix.jbi.deployment.Descriptor; 24 import org.apache.servicemix.jbi.util.DOMUtil; 25 import org.springframework.beans.factory.support.BeanDefinitionReader; 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 30 33 public class JbiElementProcessor extends ElementProcessorSupport implements ElementProcessor { 34 private static final transient Log log = LogFactory.getLog(JbiElementProcessor.class); 35 36 private static final JbiNamespaceProcessor compositeProcessor = new JbiNamespaceProcessor(); 37 38 39 public void processElement(Element element, BeanDefinitionReader beanDefinitionReader) { 40 Document document = element.getOwnerDocument(); 41 Element beans = document.createElement("beans"); 42 document.removeChild(element); 43 document.appendChild(beans); 44 45 Element bean = addBeanElement(beans, Descriptor.class.getName()); 46 DOMUtil.copyAttributes(element, beans); 47 DOMUtil.moveContent(element, bean); 48 49 beans.removeAttribute("xmlns"); 51 52 String version = beans.getAttribute("version"); 53 if (version != null && version.length() != 0) { 54 addPropertyElement(bean, "version", version); 55 beans.removeAttribute("version"); 56 } 57 58 String id = bean.getAttribute("id"); 59 if (id == null || id.length() == 0) { 60 bean.setAttribute("id", "jbi"); 61 } 62 bean.setAttribute("singleton", "true"); 63 64 moveToProperyListElement(bean, "path-element", "pathElements"); 65 moveToProperyListElement(bean, "service-unit", "serviceUnits"); 66 moveToProperyListElement(bean, "connection", "connections"); 67 moveToProperyListElement(bean, "provides", "provides"); 68 moveToProperyListElement(bean, "consumes", "consumes"); 69 70 processChildren(compositeProcessor, bean, beanDefinitionReader); 71 72 logXmlGenerated(log, "Adding new beans", beans); 73 } 74 75 83 protected void moveToProperyListElement(Element bean, String elementName, String propertyName) { 84 Element property = null; 85 Element to = null; 86 Node node = bean.getFirstChild(); 87 while (node != null) { 88 Node current = node; 89 node = node.getNextSibling(); 90 if (current.getNodeType() == Node.ELEMENT_NODE) { 91 if (elementName.equals(current.getNodeName())) { 92 bean.removeChild(current); 93 if (to == null) { 94 property = addPropertyElement(bean, propertyName); 95 to = addElement(property, "list"); 96 97 bean.removeChild(property); 99 } 100 to.appendChild(current); 101 } 102 else { 103 moveToProperyListElement((Element ) current, elementName, propertyName); 104 } 105 } 106 } 107 if (property != null) { 108 bean.appendChild(property); 109 } 110 } 111 } 112 | Popular Tags |