KickJava   Java API By Example, From Geeks To Geeks.

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


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.node.runtime.web.WebBundleRuntimeNode;
32 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer;
33 import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor;
34 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
35
36 /**
37  * This node is responsible for handling runtime descriptor
38  * message-destination-ref tag
39  *
40  */

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

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

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

72     public void setElementValue(XMLElement element, String JavaDoc value) {
73         if (RuntimeTagNames.MESSAGE_DESTINATION_REFERENCE_NAME.equals(
74             element.getQName())) {
75             Object JavaDoc parentNode = getParentNode();
76             Object JavaDoc parentDesc = null;
77             // in case of web
78
if (parentNode instanceof WebBundleRuntimeNode) {
79                 parentDesc = ((WebBundleRuntimeNode) parentNode).getWebBundleDescriptor();
80             // in case of appclient and ejb
81
} else {
82                 parentDesc = getParentNode().getDescriptor();
83             }
84
85             if (parentDesc instanceof MessageDestinationReferenceContainer) {
86                 descriptor = ((MessageDestinationReferenceContainer) parentDesc).getMessageDestinationReferenceByName(value);
87             }
88         } else super.setElementValue(element, value);
89     }
90     
91     /**
92      * write the descriptor class to a DOM tree and return it
93      *
94      * @param parent node for the DOM tree
95      * @param node name for the descriptor
96      * @param the descriptor to write
97      * @return the DOM tree top node
98      */

99     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
100         MessageDestinationReferenceDescriptor msgDestRef) {
101         Node JavaDoc msgDestRefNode = super.writeDescriptor(parent, nodeName,
102             msgDestRef);
103         appendTextChild(msgDestRefNode,
104             RuntimeTagNames.MESSAGE_DESTINATION_REFERENCE_NAME,
105             msgDestRef.getName());
106         appendTextChild(msgDestRefNode, RuntimeTagNames.JNDI_NAME,
107             msgDestRef.getJndiName());
108         return msgDestRefNode;
109     }
110     
111     /**
112      * writes all the runtime information for JMS destination references
113      *
114      * @param parent node to add the runtime xml info
115      * @param the J2EE component containing message destination references
116      */

117     public static void writeMessageDestinationReferences(Node JavaDoc parent,
118         MessageDestinationReferenceContainer descriptor) {
119         // message-destination-ref*
120
Iterator JavaDoc msgDestRefs =
121             descriptor.getMessageDestinationReferenceDescriptors().iterator();
122         if (msgDestRefs.hasNext()) {
123             MessageDestinationRefNode messageDestinationRefNode =
124                 new MessageDestinationRefNode();
125             while (msgDestRefs.hasNext()) {
126                 messageDestinationRefNode.writeDescriptor(parent,
127                     RuntimeTagNames.MESSAGE_DESTINATION_REFERENCE,
128                     (MessageDestinationReferenceDescriptor) msgDestRefs.next());
129             }
130         }
131     }
132 }
133
Popular Tags