KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > config > spring > ElementToPropertyProcessor


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.config.spring;
18
19 import org.apache.servicemix.jbi.util.DOMUtil;
20 import org.springframework.beans.factory.support.BeanDefinitionReader;
21 import org.w3c.dom.Attr JavaDoc;
22 import org.w3c.dom.Element JavaDoc;
23 import org.w3c.dom.NamedNodeMap JavaDoc;
24
25 /**
26  * Converts an XML element into a property declaration. The element name is used as the property
27  * name unless it is overloaded.
28  *
29  * @version $Revision: 426415 $
30  */

31 public class ElementToPropertyProcessor extends ElementProcessorSupport implements ElementProcessor {
32     private String JavaDoc propertyName;
33
34     public ElementToPropertyProcessor() {
35     }
36
37     public ElementToPropertyProcessor(String JavaDoc propertyName) {
38         this.propertyName = propertyName;
39     }
40
41     public void processElement(Element JavaDoc element, BeanDefinitionReader beanDefinitionReader) {
42         Element JavaDoc bean = (Element JavaDoc) element.getParentNode();
43         bean.removeChild(element);
44         
45         String JavaDoc name = propertyName;
46         if (name == null) {
47             name = getElementNameToPropertyName(element);
48         }
49
50         addPropertyElement(bean, name, DOMUtil.getElementText(element));
51
52         processAttributes(element, bean);
53
54     }
55
56     /**
57      * Lets add any other properties specified as attributes on this element
58      */

59     protected void processAttributes(Element JavaDoc element, Element JavaDoc bean) {
60         NamedNodeMap JavaDoc attributes = element.getAttributes();
61         for (int i = 0, size = attributes.getLength(); i < size; i++ ) {
62             Attr JavaDoc node = (Attr JavaDoc) attributes.item(i);
63             String JavaDoc value = node.getValue();
64             if (value != null && value.length() > 0) {
65             addPropertyElement(bean, node.getName(), value);
66             }
67         }
68     }
69
70 }
71
Popular Tags