KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import java.util.Map JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28
29 import com.sun.enterprise.deployment.node.XMLElement;
30 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
31 import com.sun.enterprise.deployment.types.ResourceEnvReferenceContainer;
32 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor;
33 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
34
35 /**
36  * This node is responsible for handling runtime descriptor
37  * resource-env-ref tag
38  *
39  * @author Jerome Dochez
40  * @version
41  */

42 public class ResourceEnvRefNode extends DeploymentDescriptorNode {
43
44     private JmsDestinationReferenceDescriptor descriptor;
45     
46        /**
47     * @return the descriptor instance to associate with this XMLNode
48     */

49     public Object JavaDoc getDescriptor() {
50         return descriptor;
51     }
52     
53     /**
54      * all sub-implementation of this class can use a dispatch table to map xml element to
55      * method name on the descriptor class for setting the element value.
56      *
57      * @return the map with the element name as a key, the setter method as a value
58      */

59     protected Map JavaDoc getDispatchTable() {
60         Map JavaDoc table = super.getDispatchTable();
61         table.put(RuntimeTagNames.JNDI_NAME, "setJndiName");
62         return table;
63     }
64     
65     /**
66      * receives notiification of the value for a particular tag
67      *
68      * @param element the xml element
69      * @param value it's associated value
70      */

71     public void setElementValue(XMLElement element, String JavaDoc value) {
72         if (RuntimeTagNames.RESOURCE_ENV_REFERENCE_NAME.equals(element.getQName())) {
73             Object JavaDoc parentDesc = getParentNode().getDescriptor();
74             if (parentDesc instanceof ResourceEnvReferenceContainer) {
75                 descriptor = ((ResourceEnvReferenceContainer) parentDesc).getJmsDestinationReferenceByName(value);
76             }
77         } else super.setElementValue(element, value);
78     }
79     
80     /**
81      * write the descriptor class to a DOM tree and return it
82      *
83      * @param parent node for the DOM tree
84      * @param node name for the descriptor
85      * @param the descriptor to write
86      * @return the DOM tree top node
87      */

88     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, JmsDestinationReferenceDescriptor ejbRef) {
89         Node JavaDoc resRefNode = super.writeDescriptor(parent, nodeName, ejbRef);
90         appendTextChild(resRefNode, RuntimeTagNames.RESOURCE_ENV_REFERENCE_NAME, ejbRef.getName());
91         appendTextChild(resRefNode, RuntimeTagNames.JNDI_NAME, ejbRef.getJndiName());
92         return resRefNode;
93     }
94     
95     /**
96      * writes all the runtime information for JMS destination references
97      *
98      * @param parent node to add the runtime xml info
99      * @param the J2EE component containing ejb references
100      */

101     public static void writeResoureEnvReferences(Node JavaDoc parent, ResourceEnvReferenceContainer descriptor) {
102         // resource-env-ref*
103
Iterator JavaDoc resRefs = descriptor.getJmsDestinationReferenceDescriptors().iterator();
104         if (resRefs.hasNext()) {
105             ResourceEnvRefNode resourceEnvRefNode = new ResourceEnvRefNode();
106             while (resRefs.hasNext()) {
107                 resourceEnvRefNode.writeDescriptor(parent, RuntimeTagNames.RESOURCE_ENV_REFERENCE,
108                     (JmsDestinationReferenceDescriptor) resRefs.next());
109             }
110         }
111     }
112     
113 }
114
Popular Tags