KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > 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
24 /*
25  * ConnectorNode.java. This class is responsible for encapsulating all information specific to the Connector DTD
26  *
27  * Created on February 1, 2002, 3:07 PM
28  */

29
30 package com.sun.enterprise.deployment.node.connector;
31
32 import java.util.*;
33 import org.w3c.dom.Node JavaDoc;
34 import org.xml.sax.Attributes JavaDoc;
35 import java.util.logging.Level JavaDoc;
36
37 import com.sun.enterprise.deployment.EnvironmentProperty;
38 import com.sun.enterprise.deployment.ConnectorDescriptor;
39 import com.sun.enterprise.deployment.Descriptor;
40 import com.sun.enterprise.deployment.node.DescriptorFactory;
41 import com.sun.enterprise.deployment.AdminObject;
42 import com.sun.enterprise.deployment.node.BundleNode;
43 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
44 import com.sun.enterprise.deployment.xml.TagNames;
45 import com.sun.enterprise.deployment.node.XMLElement;
46 import com.sun.enterprise.deployment.node.RootXMLNode;
47 import com.sun.enterprise.deployment.node.XMLNode;
48 import com.sun.enterprise.deployment.MessageListener;
49 import com.sun.enterprise.deployment.node.connector.MessageListenerNode;
50 import com.sun.enterprise.deployment.util.DOLUtils;
51
52
53 /**
54  * The top connector node class
55  * @author Sheetal Vartak
56  * @version
57  */

58 public class ConnectorNode extends BundleNode implements RootXMLNode {
59
60     // Descriptor class we are using
61
private ConnectorDescriptor descriptor;
62     public static String JavaDoc VERSION_10 = "1.0";
63     public static String JavaDoc VERSION_15 = "1.5";
64     private String JavaDoc specVersion;
65
66     //connector1.0
67
public final static String JavaDoc PUBLIC_DTD_ID_10 = "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN";
68     public final static String JavaDoc SYSTEM_ID_10 = "http://java.sun.com/dtd/connector_1_0.dtd";
69
70     
71     //connector1.5
72
public final static String JavaDoc PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD Connector 1.5//EN";
73     public final static String JavaDoc SYSTEM_ID = "http://java.sun.com/dtd/connector_1_5.dtd";
74     
75     public final static String JavaDoc SCHEMA_ID = "connector_1_5.xsd";
76     public final static String JavaDoc SPEC_VERSION = VERSION_15;
77     private static List<String JavaDoc> systemIDs = null;
78
79     public final static XMLElement tag = new XMLElement(ConnectorTagNames.CONNECTOR);
80
81     /**
82      * register this node as a root node capable of loading entire DD files
83      *
84      * @param publicIDToDTD is a mapping between xml Public-ID to DTD
85      * @return the doctype tag name
86      */

87     public static String JavaDoc registerBundle(Map publicIDToDTD) {
88         publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID);
89         publicIDToDTD.put(PUBLIC_DTD_ID_10, SYSTEM_ID_10);
90         return tag.getQName();
91    }
92
93     public ConnectorNode() {
94         super();
95         registerElementHandler(new XMLElement(ConnectorTagNames.LICENSE),
96             LicenseNode.class, "setLicenseDescriptor");
97     }
98
99
100    /**
101     * @return the descriptor instance to associate with this XMLNode
102     */

103     public Object JavaDoc getDescriptor() {
104         if (descriptor == null) {
105             descriptor = (ConnectorDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
106         }
107         return descriptor;
108     }
109
110     /**
111      * parsed an attribute of an element
112      *
113      * @param the element name
114      * @param the attribute name
115      * @param the attribute value
116      * @return true if the attribute was processed
117      */

118     protected boolean setAttributeValue(XMLElement elementName,
119         XMLElement attributeName, String JavaDoc value) {
120         getDescriptor();
121         if (descriptor==null) {
122             throw new RuntimeException JavaDoc(
123                 "Trying to set values on a null descriptor");
124         }
125         // the version attribute value is the spec version we use
126
// and it's only available from schema based xml
127
if (attributeName.getQName().equals(ConnectorTagNames.VERSION)) {
128         descriptor.setSpecVersion(value);
129             specVersion = value;
130             return true;
131         } else if (attributeName.getQName().equals(TagNames.ID)) {
132             // we do not support id attribute for the moment
133
return true;
134         }
135
136         return false;
137     }
138
139     /**
140      * receives notification of the value for a particular tag
141      *
142      * @param element the xml element
143      * @param value it's associated value
144      */

145     public void setElementValue(XMLElement element, String JavaDoc value) {
146         getDescriptor();
147         if (descriptor==null) {
148             throw new RuntimeException JavaDoc(
149                 "Trying to set values on a null descriptor");
150         } if (ConnectorTagNames.SPEC_VERSION.equals(element.getQName())) {
151         descriptor.setSpecVersion(value);
152             specVersion = value;
153         // the version element value is the resourve adapter version
154
// and it's only available from dtd based xml
155
} else if (ConnectorTagNames.VERSION.equals(element.getQName())) {
156             descriptor.setResourceAdapterVersion(value);
157         } else
158     super.setElementValue(element, value);
159     }
160
161     /**
162      * @return true if the element tag can be handled by any registered sub nodes of the
163      * current XMLNode
164      */

165     public boolean handlesElement(XMLElement element) {
166     if (ConnectorTagNames.RESOURCE_ADAPTER.equals(element.getQName())) {
167             return false;
168     }
169     return super.handlesElement(element);
170     }
171
172     /**
173      * @return the handler registered for the subtag element of the curent XMLNode
174      */

175     public XMLNode getHandlerFor(XMLElement element) {
176     if (ConnectorTagNames.RESOURCE_ADAPTER.equals(element.getQName())) {
177         /** For resourceadapter tag, we need to find out what version of DTD we are handling
178         * in order to correctly read/write the XML file
179         */

180         if (VERSION_10.equals(specVersion)) {
181         OutBoundRANode outboundRANode = new OutBoundRANode(element);
182         outboundRANode.setParentNode(this);
183         outboundRANode.createConDefDescriptorFor10();
184         return outboundRANode;
185         } else {
186         RANode raNode = new RANode(element);
187         raNode.setParentNode(this);
188         return raNode;
189         }
190     } else {
191         return super.getHandlerFor(element);
192     }
193     }
194     
195     /**
196      * @return the XML tag associated with this XMLNode
197      */

198     protected XMLElement getXMLRootTag() {
199         return tag;
200     }
201     
202     /**
203      * Adds a new DOL descriptor instance to the descriptor instance associated with
204      * this XMLNode
205      *
206      * @param descriptor the new descriptor
207      */

208     public void addDescriptor(Object JavaDoc newDescriptor) {
209     }
210         
211     /**
212      * all sub-implementation of this class can use a dispatch table to map xml element to
213      * method name on the descriptor class for setting the element value.
214      *
215      * @return the map with the element name as a key, the setter method as a value
216      */

217     protected Map getDispatchTable() {
218         // no need to be synchronized for now
219
Map table = super.getDispatchTable();
220         table.put(ConnectorTagNames.VENDOR_NAME, "setVendorName");
221     table.put(ConnectorTagNames.EIS_TYPE, "setEisType");
222
223     // support for 1.0 DTD and 1.5 schema and not 1.5 DTD
224
table.put(ConnectorTagNames.RESOURCEADAPTER_VERSION, "setResourceAdapterVersion");
225
226         return table;
227     }
228
229     /**
230      * @return the DOCTYPE of the XML file
231      */

232     public String JavaDoc getDocType() {
233     return null;
234     }
235     
236     /**
237      * @return the SystemID of the XML file
238      */

239     public String JavaDoc getSystemID() {
240         return SCHEMA_ID;
241     }
242
243     /**
244      * @return the list of SystemID of the XML schema supported
245      */

246     public List<String JavaDoc> getSystemIDs() {
247         if (systemIDs != null) {
248             return systemIDs;
249         }
250
251         systemIDs = new ArrayList<String JavaDoc>();
252         systemIDs.add(SCHEMA_ID);
253         return systemIDs;
254     }
255
256     /**
257      * write the descriptor class to a DOM tree and return it
258      *
259      * @param parent node for the DOM tree
260      * @param the descriptor to write
261      * @return the DOM tree top node
262      */

263     public Node JavaDoc writeDescriptor(Node JavaDoc parent, Descriptor descriptor) {
264
265         if (! (descriptor instanceof ConnectorDescriptor)) {
266             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
267         }
268         ConnectorDescriptor conDesc = (ConnectorDescriptor) descriptor;
269     conDesc.setSpecVersion(VERSION_15);
270         Node JavaDoc connectorNode = super.writeDescriptor(parent, conDesc);
271     appendTextChild(connectorNode, ConnectorTagNames.VENDOR_NAME, conDesc.getVendorName());
272     appendTextChild(connectorNode, ConnectorTagNames.EIS_TYPE, conDesc.getEisType());
273     appendTextChild(connectorNode, ConnectorTagNames.RESOURCEADAPTER_VERSION, conDesc.getResourceAdapterVersion());
274
275     //license info
276
LicenseNode licenseNode = new LicenseNode();
277         connectorNode = licenseNode.writeDescriptor(connectorNode, conDesc);
278
279     // resource adapter node
280
RANode raNode = new RANode();
281     connectorNode = raNode.writeDescriptor(connectorNode, conDesc);
282     return connectorNode;
283     }
284     
285     /**
286      * @return the default spec version level this node complies to
287      */

288     public String JavaDoc getSpecVersion() {
289         return SPEC_VERSION;
290     }
291
292     /**
293      * @return the schema URL
294      */

295     protected String JavaDoc getSchemaURL() {
296         return TagNames.J2EE_NAMESPACE + "/" + getSystemID();
297     }
298 }
299
Popular Tags