KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > PropertiesNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * PropertiesNode.java
26  *
27  * Created on March 24, 2003, 12:39 PM
28  */

29
30 package com.sun.enterprise.deployment.node;
31
32 import java.util.Properties JavaDoc;
33 import java.util.Enumeration JavaDoc;
34 import org.w3c.dom.Node JavaDoc;
35 import com.sun.enterprise.deployment.xml.TagNames;
36 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
37
38 /**
39  * This node is responsible for handling property (name, value)
40  * DTD elements to java.util.Properties mapping
41  *
42  * @author Jerome Dochez
43  */

44 public class PropertiesNode extends DeploymentDescriptorNode {
45     
46     private String JavaDoc name=null;
47     private Properties JavaDoc descriptor= new Properties JavaDoc();
48    
49    /**
50     * @return the descriptor instance to associate with this XMLNode
51     */

52     public Object JavaDoc getDescriptor() {
53         return descriptor;
54     }
55  
56     /**
57      * receives notification of the value for a particular tag
58      *
59      * @param element the xml element
60      * @param value it's associated value
61      */

62     public void setElementValue(XMLElement element, String JavaDoc value) {
63         if (TagNames.NAME_VALUE_PAIR_NAME.equals(element.getQName())) {
64             name = value;
65         } else if (TagNames.NAME_VALUE_PAIR_VALUE.equals(element.getQName())) {
66             descriptor.put(name, value);
67         }
68     }
69     
70     
71     /**
72      * write the descriptor class to a DOM tree and return it
73      *
74      * @param parent node in the DOM tree
75      * @param node name for the root element of this xml fragment
76      * @param the descriptor to write
77      * @return the DOM tree top node
78      */

79     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, Properties JavaDoc descriptor) {
80         
81         Node JavaDoc propertiesNode = super.appendChild(parent, nodeName);
82         for (Enumeration JavaDoc keys = descriptor.propertyNames(); keys.hasMoreElements();) {
83             Node JavaDoc aProperty = this.appendChild(propertiesNode, RuntimeTagNames.PROPERTY);
84             String JavaDoc key = (String JavaDoc) keys.nextElement();
85             appendTextChild(aProperty, TagNames.NAME_VALUE_PAIR_NAME, key);
86             appendTextChild(aProperty, TagNames.NAME_VALUE_PAIR_VALUE,
87                         descriptor.getProperty(key));
88         }
89         return propertiesNode;
90     }
91 }
92
Popular Tags