KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > common > MessageNode


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.common;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 import org.w3c.dom.Node JavaDoc;
30
31 import com.sun.enterprise.deployment.node.XMLElement;
32 import com.sun.enterprise.deployment.node.XMLNode;
33 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
34 import com.sun.enterprise.deployment.node.MethodNode;
35 import com.sun.enterprise.deployment.node.runtime.web.WebBundleRuntimeNode;
36 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
37 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
38 import com.sun.enterprise.deployment.MethodDescriptor;
39 import com.sun.enterprise.deployment.runtime.common.MessageDescriptor;
40 import com.sun.enterprise.deployment.ServiceRefPortInfo;
41 import com.sun.enterprise.deployment.WebServiceEndpoint;
42 import com.sun.enterprise.deployment.BundleDescriptor;
43 import com.sun.enterprise.deployment.WebBundleDescriptor;
44 import com.sun.enterprise.deployment.EjbDescriptor;
45 import com.sun.enterprise.deployment.EjbBundleDescriptor;
46
47 /**
48  * This node handles message element
49  *
50  */

51 public class MessageNode extends DeploymentDescriptorNode {
52
53     MessageDescriptor descriptor = null;
54     private static final String JavaDoc ALL_METHODS = "*";
55
56     public MessageNode() {
57         registerElementHandler(new XMLElement(
58             RuntimeTagNames.JAVA_METHOD), MethodNode.class,
59             "setMethodDescriptor");
60     }
61     
62     /**
63     * @return the descriptor instance to associate with this XMLNode
64     */

65     public Object JavaDoc getDescriptor() {
66         if (descriptor == null) {
67             descriptor = new MessageDescriptor();
68             setMiscDescriptors();
69         }
70         return descriptor;
71     }
72
73         
74     /**
75      * receives notification of the value for a particular tag
76      *
77      * @param element the xml element
78      * @param value it's associated value
79      */

80     public void setElementValue(XMLElement element, String JavaDoc value) {
81         if (WebServicesTagNames.OPERATION_NAME.equals(element.getQName())) {
82             descriptor.setOperationName(value);
83         } else {
84             super.setElementValue(element, value);
85         }
86     }
87     
88     /**
89      * write the descriptor class to a DOM tree and return it
90      *
91      * @param parent node for the DOM tree
92      * @param node name for
93      * @param the descriptor to write
94      * @return the DOM tree top node
95      */

96     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
97         MessageDescriptor messageDesc) {
98         Node JavaDoc messageNode = super.writeDescriptor(parent, nodeName,
99            messageDesc);
100
101         // for empty message case, set the method descriptor
102
// to a method descriptor with "*" as name
103
if (messageDesc.getOperationName() == null &&
104             messageDesc.getMethodDescriptor() == null) {
105             MethodDescriptor allMethodDesc = new MethodDescriptor();
106             allMethodDesc.setName(ALL_METHODS);
107             messageDesc.setMethodDescriptor(allMethodDesc);
108         }
109
110         // java-method
111
MethodDescriptor methodDesc = messageDesc.getMethodDescriptor();
112         if (methodDesc != null) {
113             MethodNode methodNode = new MethodNode();
114             methodNode.writeJavaMethodDescriptor(messageNode,
115                 RuntimeTagNames.JAVA_METHOD, methodDesc);
116         }
117
118         // operation-name
119
appendTextChild(messageNode, WebServicesTagNames.OPERATION_NAME,
120             messageDesc.getOperationName());
121
122         return messageNode;
123     }
124
125     private void setMiscDescriptors() {
126         XMLNode parentNode =
127             getParentNode().getParentNode().getParentNode();
128
129         // get the endpoint or portinfo descriptor
130
Object JavaDoc parentDesc = parentNode.getDescriptor();
131
132         if (parentDesc instanceof ServiceRefPortInfo) {
133             descriptor.setServiceRefPortInfo((ServiceRefPortInfo)parentDesc);
134         } else if(parentDesc instanceof WebServiceEndpoint) {
135             descriptor.setWebServiceEndpoint((WebServiceEndpoint)parentDesc);
136         }
137
138         // Get the bundle descriptor of which this belongs
139
BundleDescriptor bundleDesc = null;
140         parentNode = parentNode.getParentNode().getParentNode();
141         if (parentNode instanceof WebBundleRuntimeNode) {
142             // In the cases of used in
143
// 1. webservice-endpoint for web component
144
// 2. port-info for web component
145
bundleDesc =
146                 ((WebBundleRuntimeNode)parentNode).getWebBundleDescriptor();
147         } else if (parentNode.getDescriptor() instanceof BundleDescriptor) {
148             // In the cases of used in port-info for app client
149
bundleDesc = (BundleDescriptor)parentNode.getDescriptor();
150         } else {
151             // In the case of used in webservice-endpoint for ejb component
152
if (parentNode.getDescriptor() instanceof EjbDescriptor) {
153                 EjbDescriptor ejbDesc =
154                     (EjbDescriptor)parentNode.getDescriptor();
155                 bundleDesc = ejbDesc.getEjbBundleDescriptor();
156             } else {
157                 // In the case of used in port-info for ejb component
158
parentNode = parentNode.getParentNode();
159                 if (parentNode.getDescriptor() instanceof EjbDescriptor) {
160                     EjbDescriptor ejbDesc =
161                         (EjbDescriptor)parentNode.getDescriptor();
162                     bundleDesc = ejbDesc.getEjbBundleDescriptor();
163                 }
164             }
165         }
166         descriptor.setBundleDescriptor(bundleDesc);
167     }
168 }
169
Popular Tags