KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > connector > ConfigPropertyNode


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 package com.sun.enterprise.deployment.node.connector;
25
26 import java.util.*;
27 import org.xml.sax.Attributes JavaDoc;
28 import com.sun.enterprise.deployment.Descriptor;
29 import com.sun.enterprise.deployment.ConnectorDescriptor;
30 import com.sun.enterprise.deployment.OutboundResourceAdapter;
31 import com.sun.enterprise.deployment.AdminObject;
32 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
33 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
34 import com.sun.enterprise.deployment.xml.TagNames;
35 import com.sun.enterprise.deployment.EnvironmentProperty;
36 import com.sun.enterprise.deployment.node.DescriptorFactory;
37 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
38 import com.sun.enterprise.deployment.node.ConfigurableNode;
39 import com.sun.enterprise.deployment.node.XMLElement;
40
41 import org.xml.sax.Attributes JavaDoc;
42 import org.w3c.dom.Node JavaDoc;
43
44 /**
45  * This node is responsible for handling the Connector DTD related config-property XML tag
46  *
47  * @author Sheetal Vartak
48  * @version
49  */

50 public class ConfigPropertyNode extends DeploymentDescriptorNode {
51
52     private EnvironmentProperty config = null;
53
54    /**
55      * all sub-implementation of this class can use a dispatch table to map xml element to
56      * method name on the descriptor class for setting the element value.
57      *
58      * @return the map with the element name as a key, the setter method as a value
59      */

60     protected Map getDispatchTable() {
61         Map table = super.getDispatchTable();
62         table.put(ConnectorTagNames.CONFIG_PROPERTY_NAME, "setName");
63         table.put(ConnectorTagNames.CONFIG_PROPERTY_VALUE, "setValue");
64         table.put(ConnectorTagNames.CONFIG_PROPERTY_TYPE, "setType");
65         return table;
66     }
67
68     /**
69     * @return the descriptor instance to associate with this XMLNode
70     */

71     public Object JavaDoc getDescriptor() {
72         if (config == null) {
73             config = (EnvironmentProperty) DescriptorFactory.getDescriptor(getXMLPath());
74         }
75         return config;
76     }
77
78     /**
79      * write the descriptor class to a DOM tree and return it
80      *
81      * @param parent node for the DOM tree
82      * @param the descriptor to write
83      * @return the DOM tree top node
84      */

85     public Node writeDescriptor(Node parent, Descriptor descriptor) {
86
87         if (! (descriptor instanceof ConnectorDescriptor) &&
88         ! (descriptor instanceof AdminObject) &&
89         ! (descriptor instanceof ConnectionDefDescriptor) &&
90         ! (descriptor instanceof OutboundResourceAdapter)) {
91             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
92         }
93     Iterator configProps = null;
94     if (descriptor instanceof ConnectorDescriptor) {
95         configProps = ((ConnectorDescriptor)descriptor).getConfigProperties().iterator();
96     } else if (descriptor instanceof ConnectionDefDescriptor) {
97         configProps = ((ConnectionDefDescriptor)descriptor).getConfigProperties().iterator();
98     } else if (descriptor instanceof AdminObject) {
99         configProps = ((AdminObject)descriptor).getConfigProperties().iterator();
100     } else if (descriptor instanceof OutboundResourceAdapter) {
101         configProps = ((OutboundResourceAdapter)descriptor).getConfigProperties().iterator();
102     }
103     //config property info
104
for (;configProps.hasNext();) {
105         EnvironmentProperty config = (EnvironmentProperty) configProps.next();
106         Node configNode = appendChild(parent, ConnectorTagNames.CONFIG_PROPERTY);
107         writeLocalizedDescriptions(configNode, config);
108         appendTextChild(configNode, ConnectorTagNames.CONFIG_PROPERTY_NAME, config.getName());
109         appendTextChild(configNode, ConnectorTagNames.CONFIG_PROPERTY_TYPE, config.getType());
110         appendTextChild(configNode, ConnectorTagNames.CONFIG_PROPERTY_VALUE, config.getValue());
111     }
112     return parent;
113     }
114 }
115
Popular Tags