1 17 package org.apache.servicemix.jbi.config; 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.QNameElementProcessor; 23 import org.apache.servicemix.jbi.util.DOMUtil; 24 import org.springframework.beans.factory.BeanDefinitionStoreException; 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 import org.w3c.dom.NodeList ; 30 31 36 public class ComponentElementProcessor extends QNameElementProcessor implements ElementProcessor { 37 38 private static final transient Log log = LogFactory.getLog(ComponentElementProcessor.class); 39 40 public void processElement(Element element, BeanDefinitionReader beanDefinitionReader) { 41 Document document = element.getOwnerDocument(); 43 44 Element root = (Element ) element.getParentNode(); 45 String id = element.getAttribute("id"); 46 if (id == null || id.length() == 0) { 47 throw new BeanDefinitionStoreException("A <component> must have an id attribute"); 48 } 49 50 Element registration = addBeanElement(root, "org.apache.servicemix.jbi.container.ActivationSpec"); 51 addPropertyElement(registration, "id", id); 52 Element componentProperty = addPropertyElement(registration, "component"); 53 Element bean = document.createElement("bean"); 54 componentProperty.appendChild(bean); 55 56 String service = element.getAttribute("service"); 58 if (service != null) { 59 element.removeAttribute("service"); 60 addQNameProperty(registration, "service", service, element); 61 } 62 String interfaceName = element.getAttribute("interface"); 63 if (interfaceName != null) { 64 element.removeAttribute("interface"); 65 addQNameProperty(registration, "interfaceName", interfaceName, element); 66 } 67 String operation = element.getAttribute("operation"); 68 if (operation != null) { 69 element.removeAttribute("operation"); 70 addQNameProperty(registration, "operation", operation, element); 71 } 72 73 String endpoint = element.getAttribute("endpoint"); 74 if (endpoint != null) { 75 element.removeAttribute("endpoint"); 76 if (endpoint.length() > 0) { 77 addPropertyElement(registration, "endpoint", endpoint); 78 } 79 } 80 String destinationEndpoint = element.getAttribute("destinationEndpoint"); 81 if (destinationEndpoint != null) { 82 element.removeAttribute("destinationEndpoint"); 83 if (destinationEndpoint.length() > 0) { 84 addPropertyElement(registration, "destinationEndpoint", destinationEndpoint); 85 } 86 } 87 88 String destinationService = element.getAttribute("destinationService"); 89 if (destinationService != null) { 90 element.removeAttribute("destinationService"); 91 addQNameProperty(registration, "destinationService", destinationService, element); 92 } 93 String destinationInterface = element.getAttribute("destinationInterface"); 94 if (destinationInterface != null) { 95 element.removeAttribute("destinationInterface"); 96 addQNameProperty(registration, "destinationInterface", destinationInterface, element); 97 } 98 String destinationOperation = element.getAttribute("destinationOperation"); 99 if (destinationOperation != null) { 100 element.removeAttribute("destinationOperation"); 101 addQNameProperty(registration, "destinationOperation", destinationOperation, element); 102 } 103 String failOnNoEndpoint = element.getAttribute("failIfNoDestinationEndpoint"); 104 if (failOnNoEndpoint != null) { 105 element.removeAttribute("failIfNoDestinationEndpoint"); 106 if (failOnNoEndpoint.length() > 0) { 107 addPropertyElement(registration, "failIfNoDestinationEndpoint", failOnNoEndpoint); 108 } 109 } 110 String persistent = element.getAttribute("persistent"); 111 if (persistent != null) { 112 element.removeAttribute("persistent"); 113 if (persistent.length() > 0) { 114 addPropertyElement(registration, "persistent", persistent); 115 } 116 } 117 118 Element list = root.getOwnerDocument().createElement("list"); 120 boolean hasSubscriptions = false; 121 NodeList childNodes = element.getChildNodes(); 122 for (int index = 0; index < childNodes.getLength() - 1; ) { 123 Node node = childNodes.item(index); 124 if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals("subscription")) { 125 element.removeChild(node); 126 list.appendChild(node); 127 hasSubscriptions = true; 128 } 129 else { 130 index++; 131 } 132 133 } 134 if (hasSubscriptions) { 135 Element subscriptions = addPropertyElement(root, "subscriptions"); 136 subscriptions.appendChild(list); 137 registration.appendChild(subscriptions); 138 } 139 140 DOMUtil.copyAttributes(element, bean); 141 DOMUtil.moveContent(element, bean); 142 root.removeChild(element); 143 144 logXmlGenerated(log, "component generated", registration); 145 } 146 147 } 148 | Popular Tags |