KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > deployment > impl > ComponentElementProcessor


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28
29 import java.util.HashMap JavaDoc;
30 import java.util.Map JavaDoc;
31
32 /**
33  * Represents the 'component' element.
34  *
35  * @version $Revision: 426415 $
36  */

37 public class ComponentElementProcessor extends BeanPropertyElementProcessor {
38
39     public static final String JavaDoc 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 JavaDoc element, BeanDefinitionReader beanDefinitionReader) {
49         // lets rename any shared-library elements
50
Element JavaDoc property = addPropertyElement(element, "sharedLibraries");
51         Element JavaDoc list = addElement(property, "list");
52
53         DocumentFragment JavaDoc fragment = null;
54
55         Node JavaDoc current = element.getFirstChild();
56         while (current != null) {
57             Node JavaDoc node = current;
58             current = current.getNextSibling();
59             if (node.getNodeType() == Node.ELEMENT_NODE) {
60                 String JavaDoc 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 JavaDoc child = (Element JavaDoc) 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 JavaDoc descriptorProperty = addPropertyElement(element, "descriptorExtension");
79             descriptorProperty.setAttribute("ref", "installationDescriptorExtension");
80     
81             // lets find all elements which are not in the JBI namespace
82
Map JavaDoc propertiesMap = new HashMap JavaDoc();
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