KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.BundleDescriptor;
26 import com.sun.enterprise.deployment.Descriptor;
27 import com.sun.enterprise.deployment.EjbBundleDescriptor;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.deployment.NameValuePairDescriptor;
30 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
31 import com.sun.enterprise.deployment.node.runtime.common.MessageSecurityBindingNode;
32 import com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode;
33 import com.sun.enterprise.deployment.node.runtime.web.WebBundleRuntimeNode;
34 import com.sun.enterprise.deployment.node.XMLElement;
35 import com.sun.enterprise.deployment.runtime.common.MessageSecurityBindingDescriptor;
36 import com.sun.enterprise.deployment.runtime.web.Servlet;
37 import com.sun.enterprise.deployment.util.DOLUtils;
38 import com.sun.enterprise.deployment.WebBundleDescriptor;
39 import com.sun.enterprise.deployment.WebComponentDescriptor;
40 import com.sun.enterprise.deployment.WebServiceEndpoint;
41 import com.sun.enterprise.deployment.WebServicesDescriptor;
42 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
43 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
44 import java.util.*;
45 import java.util.logging.Level JavaDoc;
46 import javax.xml.namespace.QName JavaDoc;
47 import org.w3c.dom.Node JavaDoc;
48
49 /**
50  * This node is responsible for handling runtime info for
51  * web service endpoints.
52  *
53  * @author Kenneth Saks
54  * @version
55  */

56 public class WebServiceEndpointRuntimeNode extends DeploymentDescriptorNode {
57
58     private Descriptor descriptor;
59
60     public WebServiceEndpointRuntimeNode() {
61         registerElementHandler(
62             new XMLElement(WebServicesTagNames.MESSAGE_SECURITY_BINDING),
63             MessageSecurityBindingNode.class, "setMessageSecurityBinding");
64
65         registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
66                                RuntimeNameValuePairNode.class, "addProperty");
67     }
68
69     public Object JavaDoc getDescriptor() {
70         return descriptor;
71     }
72
73     /**
74      * all sub-implementation of this class can use a dispatch table to map xml element to
75      * method name on the descriptor class for setting the element value.
76      *
77      * @return the map with the element name as a key, the setter method as a value
78      */

79     protected Map getDispatchTable() {
80         Map table = super.getDispatchTable();
81         table.put(WebServicesTagNames.ENDPOINT_ADDRESS_URI,
82                   "setEndpointAddressUri");
83         table.put(WebServicesTagNames.TIE_CLASS, "setTieClassName");
84         table.put(WebServicesTagNames.SERVLET_IMPL_CLASS,
85                   "setServletImplClass");
86         table.put(WebServicesTagNames.DEBUGGING_ENABLED, "setDebugging");
87         table.put(WebServicesTagNames.NAMESPACE_URI, "setServiceNamespaceUri");
88         table.put(WebServicesTagNames.LOCAL_PART, "setServiceLocalPart");
89         table.put(RuntimeTagNames.AUTH_METHOD, "setAuthMethod");
90         table.put(RuntimeTagNames.REALM, "setRealm");
91         table.put(WebServicesTagNames.TRANSPORT_GUARANTEE,
92                   "setTransportGuarantee");
93
94         return table;
95     }
96     
97     /**
98      * receives notiification of the value for a particular tag
99      *
100      * @param element the xml element
101      * @param value it's associated value
102      */

103
104     public void setElementValue(XMLElement element, String JavaDoc value) {
105         if (WebServicesTagNames.PORT_COMPONENT_NAME.equals
106             (element.getQName())) {
107             Object JavaDoc parentDesc = getParentNode().getDescriptor();
108             if (parentDesc instanceof EjbDescriptor) {
109                 EjbBundleDescriptor bundle =
110                     ((EjbDescriptor) parentDesc).getEjbBundleDescriptor();
111                 WebServicesDescriptor webServices = bundle.getWebServices();
112                 descriptor = webServices.getEndpointByName(value);
113             } else if( parentDesc instanceof WebComponentDescriptor) {
114                 WebBundleDescriptor bundle = ((WebComponentDescriptor) parentDesc).getWebBundleDescriptor();
115                 WebServicesDescriptor webServices = bundle.getWebServices();
116                 descriptor = webServices.getEndpointByName(value);
117             }
118             if (descriptor==null) {
119                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.port_component_name_unknown",
120                     new Object JavaDoc[] { value });
121             }
122         } else super.setElementValue(element, value);
123     }
124     
125     /**
126      * write the descriptor class to a DOM tree and return it
127      *
128      * @param parent node for the DOM tree
129      * @param node name for the descriptor
130      * @param the descriptor to write
131      * @return the DOM tree top node
132      */

133     public Node writeDescriptor(Node parent, String JavaDoc nodeName,
134                                 WebServiceEndpoint endpoint) {
135         Node endpointNode =
136             super.writeDescriptor(parent, nodeName, endpoint);
137
138         appendTextChild(endpointNode, WebServicesTagNames.PORT_COMPONENT_NAME,
139                         endpoint.getEndpointName());
140         appendTextChild(endpointNode, WebServicesTagNames.ENDPOINT_ADDRESS_URI,
141                         endpoint.getEndpointAddressUri());
142         
143         // login config only makes sense for ejbs. For web components,
144
// this info is described in web application itself.
145
if( endpoint.implementedByEjbComponent() &&
146             endpoint.hasAuthMethod() ) {
147             Node loginConfigNode = appendChild(endpointNode,
148                                                RuntimeTagNames.LOGIN_CONFIG);
149             
150             appendTextChild(loginConfigNode, RuntimeTagNames.AUTH_METHOD,
151                             endpoint.getAuthMethod());
152             appendTextChild(loginConfigNode, RuntimeTagNames.REALM,
153                             endpoint.getRealm());
154         }
155
156         // message-security-binding
157
MessageSecurityBindingDescriptor messageSecBindingDesc =
158             endpoint.getMessageSecurityBinding();
159         if (messageSecBindingDesc != null) {
160             MessageSecurityBindingNode messageSecBindingNode =
161                 new MessageSecurityBindingNode();
162             messageSecBindingNode.writeDescriptor(endpointNode, WebServicesTagNames.MESSAGE_SECURITY_BINDING, messageSecBindingDesc);
163         }
164
165         appendTextChild(endpointNode, WebServicesTagNames.TRANSPORT_GUARANTEE,
166                         endpoint.getTransportGuarantee());
167
168         QName JavaDoc serviceName = endpoint.getServiceName();
169         if( serviceName != null ) {
170             Node serviceQnameNode = appendChild
171                 (endpointNode, WebServicesTagNames.SERVICE_QNAME);
172                                                 
173             appendTextChild(serviceQnameNode, WebServicesTagNames.NAMESPACE_URI,
174                             serviceName.getNamespaceURI());
175             appendTextChild(serviceQnameNode, WebServicesTagNames.LOCAL_PART,
176                             serviceName.getLocalPart());
177         }
178
179         appendTextChild(endpointNode, WebServicesTagNames.TIE_CLASS,
180                         endpoint.getTieClassName());
181         
182         if( endpoint.implementedByWebComponent() &&
183             (endpoint.getServletImplClass() != null) ) {
184             appendTextChild(endpointNode,
185                             WebServicesTagNames.SERVLET_IMPL_CLASS,
186                             endpoint.getServletImplClass());
187         }
188         
189         //debugging-enabled?
190
appendTextChild(endpointNode, WebServicesTagNames.DEBUGGING_ENABLED,
191                         endpoint.getDebugging());
192
193         //property*
194
Iterator properties = endpoint.getProperties();
195         if (properties!=null) {
196             RuntimeNameValuePairNode propNode = new RuntimeNameValuePairNode();
197             while (properties.hasNext()) {
198                 NameValuePairDescriptor aProp = (NameValuePairDescriptor) properties.next();
199                 propNode.writeDescriptor(endpointNode, RuntimeTagNames.PROPERTY, aProp);
200             }
201         }
202                             
203         return endpointNode;
204     }
205     
206     /**
207      * writes all the runtime information for web service endpoints for
208      * a given ejb
209      *
210      * @param parent node to add the runtime xml info
211      * @param the ejb endpoint
212      */

213     public void writeWebServiceEndpointInfo(Node parent, EjbDescriptor ejb) {
214                                             
215         EjbBundleDescriptor bundle = ejb.getEjbBundleDescriptor();
216         WebServicesDescriptor webServices = bundle.getWebServices();
217         Collection endpoints = webServices.getEndpointsImplementedBy(ejb);
218         for(Iterator iter = endpoints.iterator(); iter.hasNext();) {
219             WebServiceEndpoint next = (WebServiceEndpoint) iter.next();
220             writeDescriptor(parent, WebServicesTagNames.WEB_SERVICE_ENDPOINT,
221                             next);
222         }
223     }
224
225     /**
226      * writes all the runtime information for web service endpoints for
227      * a given web component
228      *
229      * @param parent node to add the runtime xml info
230      * @param the web component
231      */

232     public void writeWebServiceEndpointInfo
233         (Node parent, WebComponentDescriptor webComp) {
234         
235         WebBundleDescriptor bundle = webComp.getWebBundleDescriptor();
236         WebServicesDescriptor webServices = bundle.getWebServices();
237         Collection endpoints = webServices.getEndpointsImplementedBy(webComp);
238         for(Iterator iter = endpoints.iterator(); iter.hasNext();) {
239             WebServiceEndpoint next = (WebServiceEndpoint) iter.next();
240             writeDescriptor(parent, WebServicesTagNames.WEB_SERVICE_ENDPOINT,
241                             next);
242         }
243     }
244     
245 }
246
Popular Tags