KickJava   Java API By Example, From Geeks To Geeks.

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


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  * OutBoundRANode.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.AuthMechanism;
37 import com.sun.enterprise.deployment.EnvironmentProperty;
38 import com.sun.enterprise.deployment.SecurityPermission;
39 import com.sun.enterprise.deployment.ConnectorDescriptor;
40 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
41 import com.sun.enterprise.deployment.xml.TagNames;
42 import com.sun.enterprise.deployment.node.DescriptorFactory;
43 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
44 import com.sun.enterprise.deployment.node.ConfigurableNode;
45 import com.sun.enterprise.deployment.node.XMLElement;
46 import com.sun.enterprise.deployment.util.DOLUtils;
47 import com.sun.enterprise.deployment.ConnectorDescriptor;
48 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
49 import com.sun.enterprise.deployment.node.XMLNode;
50
51 import org.xml.sax.Attributes JavaDoc;
52 import org.w3c.dom.Node JavaDoc;
53
54 /**
55  * This node signifies the outbound-resourceadapter tag in Connector DTD
56  *
57  * @author Sheetal Vartak
58  * @version
59  */

60 public class OutBoundRANode extends DeploymentDescriptorNode {
61
62     OutboundResourceAdapter descriptor = null;
63    
64     public final static XMLElement tag = new XMLElement(ConnectorTagNames.OUTBOUND_RESOURCE_ADAPTER);
65     
66     //default constructor...for normal operation in case of 1.5 DTD
67
public OutBoundRANode() {
68     register();
69     }
70
71     public OutBoundRANode(XMLElement element) {
72     this.setXMLRootTag(element);
73     register();
74     }
75
76     /**
77      * This method is required for 1.0 DTD so that there will be 1 instance of
78      * ConnectionDefDescriptor available
79      * I know that this constructor will be called only when it is a 1.0 DD
80      * dont want to rely on whether 1.0 or 1.5 spec version
81      * So this method is called when the ConnectorNode knows that it is for 1.0 DTD
82      */

83     public void createConDefDescriptorFor10() {
84     ConnectionDefDescriptor conDef = new ConnectionDefDescriptor();
85     ((OutboundResourceAdapter)getDescriptor()).addConnectionDefDescriptor(conDef);
86     }
87
88     /**
89      * method for registering the handlers with the various tags
90      */

91     private void register() {
92     registerElementHandler(new XMLElement(ConnectorTagNames.AUTH_MECHANISM),
93                    AuthMechNode.class);
94     registerElementHandler(new XMLElement(ConnectorTagNames.CONNECTION_DEFINITION),
95                    ConnectionDefNode.class);
96     registerElementHandler(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY),
97                    ConfigPropertyNode.class);
98         registerElementHandler(new XMLElement(ConnectorTagNames.SECURITY_PERMISSION),
99                                SecurityPermissionNode.class);
100     }
101
102     /**
103     * @return the descriptor instance to associate with this XMLNode
104     */

105     public Object JavaDoc getDescriptor() {
106         if (descriptor==null) {
107         // the descriptor associated with the OutBoundRANode is a OutboundResourceAdapter
108
// This descriptor is available with the parent node of the OutBoundRANode
109
descriptor = (OutboundResourceAdapter)DescriptorFactory.getDescriptor(getXMLPath());
110         ((ConnectorDescriptor)(getParentNode().getDescriptor())).setOutboundResourceAdapter(descriptor);
111     }
112     return descriptor;
113     }
114
115     /**
116      * Adds a new DOL descriptor instance to the descriptor instance associated with
117      * this XMLNode
118      *
119      * @param descriptor the new descriptor
120      */

121     public void addDescriptor(Object JavaDoc obj) {
122     if (obj instanceof AuthMechanism) {
123         boolean flag = descriptor.addAuthMechanism((AuthMechanism)obj);
124         if (flag == false)
125         DOLUtils.getDefaultLogger().finer("The AuthMechanism object already exists in the Descriptor");
126     } else if (obj instanceof ConnectionDefDescriptor) {
127         descriptor.addConnectionDefDescriptor((ConnectionDefDescriptor)obj);
128     } else if (obj instanceof EnvironmentProperty) {
129         descriptor.addConfigProperty((EnvironmentProperty)obj);
130     } else if (obj instanceof SecurityPermission) {
131             // security-permission element is a direct sub element of
132
// resourceadapter, so set the value in ConnectorDescriptor
133
ConnectorDescriptor connDesc =
134                 (ConnectorDescriptor)getParentNode().getDescriptor();
135         connDesc.addSecurityPermission((SecurityPermission)obj);
136     }
137     }
138     
139     /**
140      * all sub-implementation of this class can use a dispatch table to map xml element to
141      * method name on the descriptor class for setting the element value.
142      *
143      * @return the map with the element name as a key, the setter method as a value
144      */

145     protected Map getDispatchTable() {
146         // no need to be synchronized for now
147
Map table = super.getDispatchTable();
148     
149     table.put(ConnectorTagNames.TRANSACTION_SUPPORT, "setTransactionSupport");
150     table.put(ConnectorTagNames.REAUTHENTICATION_SUPPORT, "setReauthenticationSupport");
151     
152     /** The following setXXX methods are required for 1.0 DTD. For 1.5 DTD, These methods
153      * will never be used since the control will be transferred to ConnectionDefNode
154      * classes.
155      */

156     table.put(ConnectorTagNames.MANAGED_CONNECTION_FACTORY, "setManagedConnectionFactoryImpl");
157     
158     table.put(ConnectorTagNames.CONNECTION_FACTORY_INTF, "setConnectionFactoryIntf");
159     table.put(ConnectorTagNames.CONNECTION_FACTORY_IMPL, "setConnectionFactoryImpl");
160     table.put(ConnectorTagNames.CONNECTION_INTF, "setConnectionIntf");
161     table.put(ConnectorTagNames.CONNECTION_IMPL, "setConnectionImpl");
162     
163         return table;
164     }
165
166     /**
167      * write the descriptor class to a DOM tree and return it
168      *
169      * @param parent node for the DOM tree
170      * @param the descriptor to write
171      * @return the DOM tree top node
172      */

173     public Node writeDescriptor(Node connectorNode, Descriptor descriptor) {
174     //outbound RA info
175

176     Node raNode = appendChild(connectorNode, ConnectorTagNames.OUTBOUND_RESOURCE_ADAPTER);
177     append(raNode, (OutboundResourceAdapter)((ConnectorDescriptor)descriptor).getOutboundResourceAdapter());
178     return connectorNode;
179     }
180     
181     /**
182      * SAX Parser API implementation, we don't really care for now.
183      */

184     public void startElement(XMLElement element, Attributes JavaDoc attributes) {
185     }
186
187     /**
188      * method to add the child nodes of RESOURCE_ADAPTER and OUTBOUND_RESOURCE_ADAPTER
189      */

190     private void append (Node raNode, OutboundResourceAdapter conDesc) {
191
192     ConnectionDefNode conDef = new ConnectionDefNode();
193     raNode = conDef.writeDescriptor(raNode, conDesc);
194
195     appendTextChild(raNode, ConnectorTagNames.TRANSACTION_SUPPORT, conDesc.getTransSupport());
196
197     AuthMechNode auth = new AuthMechNode();
198     raNode = auth.writeDescriptor(raNode, conDesc);
199
200     appendTextChild(raNode, ConnectorTagNames.REAUTHENTICATION_SUPPORT, conDesc.getReauthenticationSupport());
201
202     }
203 }
204
Popular Tags