KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28
29 import com.sun.enterprise.deployment.NameValuePairDescriptor;
30 import com.sun.enterprise.deployment.node.XMLElement;
31 import com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode;
32 import com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode;
33 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor;
34 import com.sun.enterprise.deployment.runtime.connector.ResourceAdapter;
35 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
36
37 /**
38  * This node handles the resource-adapter runtime deployment descriptors
39  *
40  * @author Jerome Dochez
41  * @version
42  */

43 public class ResourceAdapterNode extends RuntimeDescriptorNode {
44     
45     protected RuntimeDescriptor descriptor=null;
46     
47     /**
48      * Initialize the child handlers
49      */

50     public ResourceAdapterNode() {
51         
52         // we do not care about our standard DDS handles
53
handlers = null;
54         
55         registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
56                                RuntimeNameValuePairNode.class, "addPropertyElement");
57     }
58     
59    /**
60     * @return the descriptor instance to associate with this XMLNode
61     */

62     public Object JavaDoc getDescriptor() {
63         if (descriptor==null) {
64         descriptor = (RuntimeDescriptor) super.getDescriptor();
65         descriptor.setValue(ResourceAdapter.MAX_POOL_SIZE, "32");
66         descriptor.setValue(ResourceAdapter.STEADY_POOL_SIZE, "4");
67         descriptor.setValue(ResourceAdapter.MAX_WAIT_TIME_IN_MILLIS, "10000");
68         descriptor.setValue(ResourceAdapter.IDLE_TIMEOUT_IN_SECONDS, "1000");
69         
70     }
71         return descriptor;
72     }
73     
74     /**
75      * parsed an attribute of an element
76      *
77      * @param the element name
78      * @param the attribute name
79      * @param the attribute value
80      * @return true if the attribute was processed
81      */

82     protected boolean setAttributeValue(XMLElement elementName, XMLElement attributeName, String JavaDoc value) {
83     getDescriptor();
84     if (descriptor==null) {
85         throw new RuntimeException JavaDoc("Trying to set values on a null descriptor");
86     }
87     if (attributeName.getQName().equals(RuntimeTagNames.JNDI_NAME)) {
88         descriptor.setAttributeValue(ResourceAdapter.JNDI_NAME, value);
89         return true;
90     }
91     if (attributeName.getQName().equals(RuntimeTagNames.MAX_POOL_SIZE)) {
92         descriptor.setAttributeValue(ResourceAdapter.MAX_POOL_SIZE, value);
93         return true;
94     }
95     if (attributeName.getQName().equals(RuntimeTagNames.STEADY_POOL_SIZE)) {
96         descriptor.setAttributeValue(ResourceAdapter.STEADY_POOL_SIZE, value);
97         return true;
98     }
99     if (attributeName.getQName().equals(RuntimeTagNames.MAX_WAIT_TIME_IN_MILLIS)) {
100         descriptor.setAttributeValue(ResourceAdapter.MAX_WAIT_TIME_IN_MILLIS, value);
101         return true;
102     }
103     if (attributeName.getQName().equals(RuntimeTagNames.IDLE_TIMEOUT_IN_SECONDS)) {
104         descriptor.setAttributeValue(ResourceAdapter.IDLE_TIMEOUT_IN_SECONDS, value);
105         return true;
106     }
107     return false;
108     }
109     
110     /**
111      * write the descriptor class to a DOM tree and return it
112      *
113      * @param parent node for the DOM tree
114      * @param node name for the descriptor
115      * @param the descriptor to write
116      * @return the DOM tree top node
117      */

118     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, ResourceAdapter descriptor) {
119     Element JavaDoc raNode = (Element JavaDoc) super.writeDescriptor(parent, nodeName, descriptor);
120     appendTextChild(raNode, RuntimeTagNames.DESCRIPTION, descriptor.getDescription());
121     setAttribute(raNode, RuntimeTagNames.JNDI_NAME, (String JavaDoc) descriptor.getValue(ResourceAdapter.JNDI_NAME));
122     setAttribute(raNode, RuntimeTagNames.MAX_POOL_SIZE, (String JavaDoc) descriptor.getValue(ResourceAdapter.MAX_POOL_SIZE));
123     setAttribute(raNode, RuntimeTagNames.STEADY_POOL_SIZE, (String JavaDoc) descriptor.getValue(ResourceAdapter.STEADY_POOL_SIZE));
124     setAttribute(raNode, RuntimeTagNames.MAX_WAIT_TIME_IN_MILLIS, (String JavaDoc) descriptor.getValue(ResourceAdapter.MAX_WAIT_TIME_IN_MILLIS));
125     setAttribute(raNode, RuntimeTagNames.IDLE_TIMEOUT_IN_SECONDS, (String JavaDoc) descriptor.getValue(ResourceAdapter.IDLE_TIMEOUT_IN_SECONDS));
126
127     // properties...
128
NameValuePairDescriptor[] properties = descriptor.getPropertyElement();
129     if (properties!=null && properties.length>0) {
130         RuntimeNameValuePairNode subNode = new RuntimeNameValuePairNode();
131         for (int i=0;i<properties.length;i++) {
132         subNode.writeDescriptor(raNode, RuntimeTagNames.PROPERTY, properties[i]);
133         }
134     }
135     
136     return raNode;
137     }
138 }
139
Popular Tags