KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > connector > ConnectorNode


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 package com.sun.enterprise.deployment.node.runtime.connector;
24
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28
29 import com.sun.enterprise.deployment.Descriptor;
30 import com.sun.enterprise.deployment.ConnectorDescriptor;
31 import com.sun.enterprise.deployment.node.XMLElement;
32 import com.sun.enterprise.deployment.node.runtime.RuntimeBundleNode;
33 import com.sun.enterprise.deployment.runtime.connector.SunConnector;
34 import com.sun.enterprise.deployment.runtime.connector.ResourceAdapter;
35 import com.sun.enterprise.deployment.runtime.connector.RoleMap;
36 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
37 import com.sun.enterprise.deployment.xml.DTDRegistry;
38
39 /**
40  * This node handles the sun-connector runtime deployment descriptors
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public class ConnectorNode extends RuntimeBundleNode {
46
47     protected SunConnector descriptor=null;
48     protected ConnectorDescriptor connector=null;
49     /**
50      * Initialize the child handlers
51      */

52     public ConnectorNode(ConnectorDescriptor connector) {
53         
54         // we do not care about our standard DDS handles
55
handlers = null;
56         
57     this.connector = connector;
58     
59         registerElementHandler(new XMLElement(RuntimeTagNames.RESOURCE_ADAPTER),
60                                ResourceAdapterNode.class, "setResourceAdapter");
61         registerElementHandler(new XMLElement(RuntimeTagNames.ROLE_MAP),
62                                RoleMapNode.class,"setRoleMap");
63     }
64     
65     /**
66      * @return the DOCTYPE that should be written to the XML file
67      */

68     public String JavaDoc getDocType() {
69     return DTDRegistry.SUN_CONNECTOR_100_DTD_PUBLIC_ID;
70     }
71     
72     /**
73      * @return the SystemID of the XML file
74      */

75     public String JavaDoc getSystemID() {
76     return DTDRegistry.SUN_CONNECTOR_100_DTD_SYSTEM_ID;
77     }
78
79     /**
80      * @return NULL for all runtime nodes.
81      */

82     public List JavaDoc<String JavaDoc> getSystemIDs() {
83         return null;
84     }
85     
86     protected XMLElement getXMLRootTag() {
87         return new XMLElement(RuntimeTagNames.S1AS_CONNECTOR_RUNTIME_TAG);
88     }
89     
90    /**
91     * register this node as a root node capable of loading entire DD files
92     *
93     * @param publicIDToDTD is a mapping between xml Public-ID to DTD
94     * @return the doctype tag name
95     */

96    public static String JavaDoc registerBundle(Map JavaDoc publicIDToDTD) {
97        publicIDToDTD.put(DTDRegistry.SUN_CONNECTOR_100_DTD_PUBLIC_ID, DTDRegistry.SUN_CONNECTOR_100_DTD_SYSTEM_ID);
98        return RuntimeTagNames.S1AS_CONNECTOR_RUNTIME_TAG;
99    }
100    
101    /**
102     * @return the descriptor instance to associate with this XMLNode
103     */

104     public Object JavaDoc getDescriptor() {
105         if (descriptor==null) {
106         descriptor = new SunConnector();
107             connector.setSunDescriptor(descriptor);
108     }
109         return descriptor;
110     }
111     
112     /**
113      * write the descriptor class to a DOM tree and return it
114      *
115      * @param parent node for the DOM tree
116      * @param node name for the descriptor
117      * @param the descriptor to write
118      * @return the DOM tree top node
119      */

120     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, Descriptor descriptor) {
121         if (!(descriptor instanceof ConnectorDescriptor)) {
122             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
123         }
124         ConnectorDescriptor connector = (ConnectorDescriptor) descriptor;
125             
126     Node JavaDoc connectorNode = super.writeDescriptor(parent, nodeName, descriptor);
127     
128     // resource-adapter
129
SunConnector sunDesc = connector.getSunDescriptor();
130         if (sunDesc!=null) {
131             ResourceAdapterNode ran = new ResourceAdapterNode();
132             ran.writeDescriptor(connectorNode, RuntimeTagNames.RESOURCE_ADAPTER, sunDesc.getResourceAdapter());
133     
134             // role-map ?
135
if (sunDesc.getRoleMap()!=null) {
136                 RoleMapNode rmn = new RoleMapNode();
137                 rmn.writeDescriptor(connectorNode, RuntimeTagNames.ROLE_MAP, sunDesc.getRoleMap());
138             }
139         }
140     return connectorNode;
141     }
142 }
143
Popular Tags