KickJava   Java API By Example, From Geeks To Geeks.

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


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  * EjbRelationRole.java
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.xml.sax.Attributes JavaDoc;
34 import com.sun.enterprise.deployment.Descriptor;
35 import com.sun.enterprise.deployment.OutboundResourceAdapter;
36 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
37 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
38 import com.sun.enterprise.deployment.xml.TagNames;
39 import com.sun.enterprise.deployment.EnvironmentProperty;
40 import com.sun.enterprise.deployment.node.DescriptorFactory;
41 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
42 import com.sun.enterprise.deployment.node.ConfigurableNode;
43 import com.sun.enterprise.deployment.node.XMLElement;
44 import com.sun.enterprise.deployment.util.DOLUtils;
45 import com.sun.enterprise.deployment.ConnectorDescriptor;
46 import com.sun.enterprise.deployment.node.XMLElement;
47
48 import org.xml.sax.Attributes JavaDoc;
49 import org.w3c.dom.Node JavaDoc;
50
51 /**
52  * This node signifies the connection-definition tag in Connector DTD
53  *
54  * @author Sheetal Vartak
55  * @version
56  */

57 public class ConnectionDefNode extends DeploymentDescriptorNode {
58
59     ConnectionDefDescriptor descriptor = null;
60    
61     public final static XMLElement tag = new XMLElement(ConnectorTagNames.CONNECTION_DEFINITION);
62     
63     //default constructor...for normal operation in case of 1.5 DTD
64
public ConnectionDefNode() {
65     register();
66     }
67
68     public ConnectionDefNode(XMLElement element) {
69     this.setXMLRootTag(element);
70     register();
71     }
72     
73     /**
74      * method for registering the handlers with the various tags
75      */

76     private void register() {
77     registerElementHandler(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY),
78                    ConfigPropertyNode.class);
79     }
80         
81    /**
82     * @return the descriptor instance to associate with this XMLNode
83     */

84     public Object JavaDoc getDescriptor() {
85         if (descriptor==null) {
86         // the descriptor associated with the ConnectionDefNode is a ConnectionDefDescriptor
87
// This descriptor is available with the parent node of the ConnectionDefNode
88

89         descriptor = (ConnectionDefDescriptor)DescriptorFactory.getDescriptor(getXMLPath());
90         ((OutboundResourceAdapter)(getParentNode().getDescriptor())).addConnectionDefDescriptor(descriptor);
91
92     }
93         return descriptor;
94     }
95
96     /**
97      * Adds a new DOL descriptor instance to the descriptor instance associated with
98      * this XMLNode
99      *
100      * @param descriptor the new descriptor
101      */

102     public void addDescriptor(Object JavaDoc obj) {
103     if (obj instanceof EnvironmentProperty) {
104         descriptor.addConfigProperty((EnvironmentProperty)obj);
105     }
106     }
107     
108     /**
109      * all sub-implementation of this class can use a dispatch table to map xml element to
110      * method name on the descriptor class for setting the element value.
111      *
112      * @return the map with the element name as a key, the setter method as a value
113      */

114     protected Map getDispatchTable() {
115         // no need to be synchronized for now
116
Map table = super.getDispatchTable();
117             
118     table.put(ConnectorTagNames.MANAGED_CONNECTION_FACTORY, "setManagedConnectionFactoryImpl");
119     table.put(ConnectorTagNames.CONNECTION_FACTORY_INTF, "setConnectionFactoryIntf");
120     table.put(ConnectorTagNames.CONNECTION_FACTORY_IMPL, "setConnectionFactoryImpl");
121     table.put(ConnectorTagNames.CONNECTION_INTF, "setConnectionIntf");
122     table.put(ConnectorTagNames.CONNECTION_IMPL, "setConnectionImpl");
123
124         return table;
125     }
126
127     
128     
129     /**
130      * SAX Parser API implementation, we don't really care for now.
131      */

132     public void startElement(XMLElement element, Attributes JavaDoc attributes) {
133     //FIXME : remove the foll line once connector stuff works properly
134
//((ConnectionDefDescriptor)getDescriptor()).setOutBoundDefined(true);
135
super.startElement(element, attributes);
136     }
137
138 /**
139      * write the descriptor class to a DOM tree and return it
140      *
141      * @param parent node for the DOM tree
142      * @param the descriptor to write
143      * @return the DOM tree top node
144      */

145     public Node writeDescriptor(Node parent, Descriptor desc) {
146     //connection definition info
147

148     if (!(desc instanceof OutboundResourceAdapter)) {
149             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
150         }
151     Iterator connectionDefs = null;
152     connectionDefs = ((OutboundResourceAdapter)desc).getConnectionDefs().iterator();
153     
154     //connection-definitions
155
for (;connectionDefs.hasNext();) {
156         ConnectionDefDescriptor con = (ConnectionDefDescriptor) connectionDefs.next();
157         Node conNode = appendChild(parent, ConnectorTagNames.CONNECTION_DEFINITION);
158         appendTextChild(conNode, ConnectorTagNames.MANAGED_CONNECTION_FACTORY, con.getManagedConnectionFactoryImpl());
159         
160         ConfigPropertyNode config = new ConfigPropertyNode();
161         conNode = config.writeDescriptor(conNode, con);
162         
163         appendTextChild(conNode, ConnectorTagNames.CONNECTION_FACTORY_INTF, con.getConnectionFactoryIntf());
164         appendTextChild(conNode, ConnectorTagNames.CONNECTION_FACTORY_IMPL, con.getConnectionFactoryImpl());
165         appendTextChild(conNode, ConnectorTagNames.CONNECTION_INTF, con.getConnectionIntf());
166         appendTextChild(conNode, ConnectorTagNames.CONNECTION_IMPL, con.getConnectionImpl());
167     }
168     return parent;
169     }
170 }
171
Popular Tags