1 17 package org.apache.servicemix.jbi.deployment.impl; 18 19 import org.apache.servicemix.jbi.config.spring.BeanPropertyElementProcessor; 20 import org.apache.servicemix.jbi.deployment.Component; 21 import org.apache.servicemix.jbi.deployment.InstallationDescriptorExtension; 22 import org.springframework.beans.MutablePropertyValues; 23 import org.springframework.beans.factory.support.BeanDefinitionReader; 24 import org.springframework.beans.factory.support.RootBeanDefinition; 25 import org.w3c.dom.DocumentFragment ; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.Node ; 28 29 import java.util.HashMap ; 30 import java.util.Map ; 31 32 37 public class ComponentElementProcessor extends BeanPropertyElementProcessor { 38 39 public static final String JBI_NAMESPACE = ""; 40 41 private JbiNamespaceProcessor jbiProcessor; 42 43 public ComponentElementProcessor(JbiNamespaceProcessor childProcessor) { 44 super(Component.class, null, childProcessor); 45 this.jbiProcessor = childProcessor; 46 } 47 48 public void processElement(Element element, BeanDefinitionReader beanDefinitionReader) { 49 Element property = addPropertyElement(element, "sharedLibraries"); 51 Element list = addElement(property, "list"); 52 53 DocumentFragment fragment = null; 54 55 Node current = element.getFirstChild(); 56 while (current != null) { 57 Node node = current; 58 current = current.getNextSibling(); 59 if (node.getNodeType() == Node.ELEMENT_NODE) { 60 String uri = node.getNamespaceURI(); 61 if (!JbiNamespaceProcessor.JBI_NAMESPACE.equals(uri) && node != property) { 62 element.removeChild(node); 63 if (fragment == null) { 64 fragment = element.getOwnerDocument().createDocumentFragment(); 65 } 66 fragment.appendChild(node); 67 } 68 else if ("shared-library".equals(node.getNodeName())) { 69 Element child = (Element ) node; 70 element.removeChild(child); 71 list.appendChild(child); 72 jbiProcessor.getSharedListProcessor().processElement(child, beanDefinitionReader); 73 } 74 } 75 } 76 77 if (fragment != null) { 78 Element descriptorProperty = addPropertyElement(element, "descriptorExtension"); 79 descriptorProperty.setAttribute("ref", "installationDescriptorExtension"); 80 81 Map propertiesMap = new HashMap (); 83 propertiesMap.put("descriptorExtension", fragment); 84 RootBeanDefinition definition = new RootBeanDefinition(InstallationDescriptorExtension.class, new MutablePropertyValues(propertiesMap)); 85 beanDefinitionReader.getBeanFactory().registerBeanDefinition("installationDescriptorExtension", definition); 86 } 87 88 super.processElement(element, beanDefinitionReader); 89 } 90 } 91 | Popular Tags |