KickJava   Java API By Example, From Geeks To Geeks.

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


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.MessageDestinationDescriptor;
30 import com.sun.enterprise.deployment.BundleDescriptor;
31 import com.sun.enterprise.deployment.node.XMLElement;
32 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
33 import com.sun.enterprise.deployment.node.MessageDestinationNode;
34 import com.sun.enterprise.deployment.node.runtime.web.WebBundleRuntimeNode;
35 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
36
37 /**
38  * This node is responsible for handling runtime descriptor
39  * message-destination tag.
40  *
41  * @author Kenneth Saks
42  * @version
43  */

44 public class MessageDestinationRuntimeNode extends DeploymentDescriptorNode {
45
46     private MessageDestinationDescriptor descriptor;
47     
48     /**
49     * @return the descriptor instance to associate with this XMLNode
50     */

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

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

73     public void setElementValue(XMLElement element, String JavaDoc value) {
74         if (RuntimeTagNames.MESSAGE_DESTINATION_NAME.equals(element.getQName())) {
75             // this is a hack but not much choice
76
Object JavaDoc parentNode = getParentNode();
77             Object JavaDoc parentDesc = null;
78             if (parentNode instanceof WebBundleRuntimeNode) {
79                 parentDesc = ((WebBundleRuntimeNode) parentNode).getWebBundleDescriptor();
80             } else {
81                 parentDesc = getParentNode().getDescriptor();
82             }
83             
84             if (parentDesc instanceof BundleDescriptor) {
85                 descriptor = ((BundleDescriptor) parentDesc).
86                     getMessageDestinationByName(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, MessageDestinationDescriptor msgDest) {
100         String JavaDoc jndiName = msgDest.getJndiName();
101         Node JavaDoc msgDestNode = null;
102         if( (jndiName != null) && (jndiName.length() > 0) ) {
103             msgDestNode = super.writeDescriptor(parent, nodeName, msgDest);
104             appendTextChild(msgDestNode,
105                             RuntimeTagNames.MESSAGE_DESTINATION_NAME,
106                             msgDest.getName());
107             appendTextChild(msgDestNode, RuntimeTagNames.JNDI_NAME,
108                             msgDest.getJndiName());
109         }
110         return msgDestNode;
111     }
112     
113 }
114
Popular Tags