KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > ResourceRefNode


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 package com.sun.enterprise.deployment.node.runtime;
25
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31
32 import com.sun.enterprise.deployment.types.ResourceReferenceContainer;
33 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
34 import com.sun.enterprise.deployment.MailConfiguration;
35 import com.sun.enterprise.deployment.node.XMLElement;
36 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
37 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
38 import com.sun.enterprise.deployment.ResourcePrincipal;
39 import com.sun.enterprise.deployment.util.DOLUtils;
40
41 /**
42  * This node handles the runtime deployment descriptors for resource-ref tag
43  *
44  * @author Jerome Dochez
45  * @version
46  */

47 public class ResourceRefNode extends DeploymentDescriptorNode {
48
49     ResourceReferenceDescriptor descriptor=null;
50     
51     /** Creates new ResourceRefNode */
52     public ResourceRefNode() {
53         registerElementHandler(new XMLElement(RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL),
54                                DefaultResourcePrincipalNode.class, "setResourcePrincipal");
55     }
56
57    /**
58     * @return the descriptor instance to associate with this XMLNode
59     */

60     public Object JavaDoc getDescriptor() {
61         return descriptor;
62     }
63     
64     /**
65      * all sub-implementation of this class can use a dispatch table to map xml element to
66      * method name on the descriptor class for setting the element value.
67      *
68      * @return the map with the element name as a key, the setter method as a value
69      */

70     protected Map JavaDoc getDispatchTable() {
71         Map JavaDoc table = super.getDispatchTable();
72         table.put(RuntimeTagNames.JNDI_NAME, "setJndiName");
73         return table;
74     }
75     
76     /**
77      * receives notiification of the value for a particular tag
78      *
79      * @param element the xml element
80      * @param value it's associated value
81      */

82     public void setElementValue(XMLElement element, String JavaDoc value) {
83         if (RuntimeTagNames.RESOURCE_REFERENCE_NAME.equals(element.getQName())) {
84             Object JavaDoc parentDesc = getParentNode().getDescriptor();
85             if (parentDesc instanceof ResourceReferenceContainer) {
86                 descriptor = ((ResourceReferenceContainer) parentDesc).getResourceReferenceByName(value);
87                 DOLUtils.getDefaultLogger().fine("Applying res-ref " + value + " runtime settings to " + descriptor);
88             }
89         } else super.setElementValue(element, value);
90     }
91     
92     /**
93      * Adds a new DOL descriptor instance to the descriptor instance associated with
94      * this XMLNode
95      *
96      * @param descriptor the new descriptor
97      */

98     public void addDescriptor(Object JavaDoc newDescriptor) {
99         if (newDescriptor instanceof ResourcePrincipal) {
100             descriptor.setResourcePrincipal((ResourcePrincipal) newDescriptor);
101         } else if (newDescriptor instanceof MailConfiguration) {
102             descriptor.setMailConfiguration((MailConfiguration) newDescriptor);
103         } else {
104             DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
105                     new Object JavaDoc[]{"In " + this + " do not know what to do with " + newDescriptor});
106         }
107     }
108     
109     /**
110      * write the descriptor class to a DOM tree and return it
111      *
112      * @param parent node for the DOM tree
113      * @param node name for the descriptor
114      * @param the descriptor to write
115      * @return the DOM tree top node
116      */

117     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, ResourceReferenceDescriptor rrDescriptor) {
118         Node JavaDoc rrNode = super.writeDescriptor(parent, nodeName, descriptor);
119         appendTextChild(rrNode, RuntimeTagNames.RESOURCE_REFERENCE_NAME, rrDescriptor.getName());
120         appendTextChild(rrNode, RuntimeTagNames.JNDI_NAME, rrDescriptor.getJndiName());
121         if (rrDescriptor.getResourcePrincipal() != null) {
122             DefaultResourcePrincipalNode drpNode = new DefaultResourcePrincipalNode();
123             drpNode.writeDescriptor(rrNode, RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL,
124                                     rrDescriptor.getResourcePrincipal());
125         }
126         return rrNode;
127     }
128     
129     /**
130      * writes all the runtime information for resources references
131      *
132      * @param parent node to add the runtime xml info
133      * @param the J2EE component containing ejb references
134      */

135     public static void writeResourceReferences(Node JavaDoc parent, ResourceReferenceContainer descriptor) {
136         
137         // resource-ref*
138
Iterator JavaDoc rrs = descriptor.getResourceReferenceDescriptors().iterator();
139         if (rrs.hasNext()) {
140             
141             ResourceRefNode rrNode = new ResourceRefNode();
142             while (rrs.hasNext()) {
143                 rrNode.writeDescriptor(parent, RuntimeTagNames.RESOURCE_REFERENCE,
144                     (ResourceReferenceDescriptor) rrs.next());
145             }
146         }
147     }
148 }
149
Popular Tags