KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > WebServiceEndpointNode


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 /*
25  * WebServiceEndpointNode.java
26  *
27  * Created on March 21, 2002, 4:16 PM
28  */

29
30 package com.sun.enterprise.deployment.node;
31
32 import java.util.Map JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import org.w3c.dom.Node JavaDoc;
36 import org.w3c.dom.Element JavaDoc;
37
38 import java.util.logging.Level JavaDoc;
39 import javax.xml.namespace.QName JavaDoc;
40
41 import com.sun.enterprise.deployment.util.DOLUtils;
42 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
43 import com.sun.enterprise.deployment.WebServiceEndpoint;
44
45 /**
46  * This node handles the web service endpoint definition
47  *
48  * @author Jerome Dochez
49  */

50 public class WebServiceEndpointNode extends DisplayableComponentNode {
51
52     private final static XMLElement tag =
53         new XMLElement(WebServicesTagNames.PORT_COMPONENT);
54
55     /** Creates a new instance of WebServiceEndpointNode */
56     public WebServiceEndpointNode() {
57         super();
58         registerElementHandler
59             (new XMLElement(WebServicesTagNames.HANDLER),
60              WebServiceHandlerNode.class, "addHandler");
61         registerElementHandler
62             (new XMLElement(WebServicesTagNames.HANDLER_CHAIN),
63              WebServiceHandlerChainNode.class, "addHandlerChain");
64     }
65
66     /**
67      * @return the XML tag associated with this XMLNode
68      */

69     protected XMLElement getXMLRootTag() {
70         return tag;
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 JavaDoc getDispatchTable() {
80         Map JavaDoc table = super.getDispatchTable();
81         table.put(WebServicesTagNames.PORT_COMPONENT_NAME, "setEndpointName");
82         table.put(WebServicesTagNames.SERVICE_ENDPOINT_INTERFACE,
83                   "setServiceEndpointInterface");
84         table.put(WebServicesTagNames.PROTOCOL_BINDING, "setProtocolBinding");
85         table.put(WebServicesTagNames.ENABLE_MTOM, "setMtomEnabled");
86         return table;
87     }
88     
89     /**
90      * receives notification of the value for a particular tag
91      *
92      * @param element the xml element
93      * @param value it's associated value
94      */

95     public void setElementValue(XMLElement element, String JavaDoc value) {
96         String JavaDoc elementName = element.getQName();
97         WebServiceEndpoint endpoint = (WebServiceEndpoint) getDescriptor();
98         if (WebServicesTagNames.EJB_LINK.equals(elementName)) {
99             endpoint.setEjbLink(value);
100         } else if (WebServicesTagNames.SERVLET_LINK.equals(elementName)) {
101             endpoint.setWebComponentLink(value);
102         } else if (WebServicesTagNames.WSDL_PORT.equals(elementName)) {
103             String JavaDoc prefix = getPrefixFromQName(value);
104             String JavaDoc localPart = getLocalPartFromQName(value);
105             String JavaDoc namespaceUri = resolvePrefix(element, prefix);
106             if( namespaceUri == null) {
107                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
108                     new Object JavaDoc[] {prefix , value });
109             } else {
110                 QName JavaDoc wsdlPort = new QName JavaDoc(namespaceUri, localPart);
111                 endpoint.setWsdlPort(wsdlPort, prefix);
112             }
113         } else if(WebServicesTagNames.WSDL_SERVICE.equals(elementName)) {
114             String JavaDoc prefix = getPrefixFromQName(value);
115             String JavaDoc localPart = getLocalPartFromQName(value);
116             String JavaDoc namespaceUri = resolvePrefix(element, prefix);
117             if( namespaceUri == null) {
118                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
119                     new Object JavaDoc[] {prefix , value });
120             } else {
121                 QName JavaDoc wsdlSvc = new QName JavaDoc(namespaceUri, localPart);
122                 endpoint.setWsdlService(wsdlSvc, prefix);
123             }
124         } else super.setElementValue(element, value);
125     }
126     
127     /**
128      * write the method descriptor class to a query-method DOM tree
129      * and return it
130      *
131      * @param parent node in the DOM tree
132      * @param node name for the root element of this xml fragment
133      * @param the descriptor to write
134      * @return the DOM tree top node
135      */

136     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
137                                 WebServiceEndpoint descriptor) {
138         Node JavaDoc wseNode = super.writeDescriptor(parent, nodeName, descriptor);
139
140         writeDisplayableComponentInfo(wseNode, descriptor);
141
142         appendTextChild(wseNode,
143                         WebServicesTagNames.PORT_COMPONENT_NAME,
144                         descriptor.getEndpointName());
145         
146         QName JavaDoc wsdlService = descriptor.getWsdlService();
147         if((wsdlService!=null) &&
148             (wsdlService.getLocalPart().length() != 0)) {
149             appendQNameChild(WebServicesTagNames.WSDL_SERVICE, wseNode,
150                          wsdlService.getNamespaceURI(), wsdlService.getLocalPart(),
151                          descriptor.getWsdlServiceNamespacePrefix());
152         }
153         
154         QName JavaDoc wsdlPort = descriptor.getWsdlPort();
155         if((wsdlPort!=null) &&
156             (wsdlPort.getLocalPart().length() != 0)) {
157             appendQNameChild(WebServicesTagNames.WSDL_PORT, wseNode,
158                          wsdlPort.getNamespaceURI(), wsdlPort.getLocalPart(),
159                          descriptor.getWsdlPortNamespacePrefix());
160         }
161
162         appendTextChild(wseNode,
163                         WebServicesTagNames.ENABLE_MTOM,
164                         descriptor.getMtomEnabled());
165         if(descriptor.hasUserSpecifiedProtocolBinding()) {
166             appendTextChild(wseNode,
167                         WebServicesTagNames.PROTOCOL_BINDING,
168                         descriptor.getProtocolBinding());
169         }
170         
171         appendTextChild(wseNode,
172                         WebServicesTagNames.SERVICE_ENDPOINT_INTERFACE,
173                         descriptor.getServiceEndpointInterface());
174         
175         if( descriptor.implementedByWebComponent() ) {
176             Node JavaDoc linkNode =
177                 appendChild(wseNode, WebServicesTagNames.SERVICE_IMPL_BEAN);
178             appendTextChild(linkNode, WebServicesTagNames.SERVLET_LINK,
179                             descriptor.getWebComponentLink());
180         } else if( descriptor.implementedByEjbComponent() ) {
181             Node JavaDoc linkNode =
182                 appendChild(wseNode, WebServicesTagNames.SERVICE_IMPL_BEAN);
183             appendTextChild(linkNode, WebServicesTagNames.EJB_LINK,
184                             descriptor.getEjbLink());
185         } else {
186             DOLUtils.getDefaultLogger().log
187                 (Level.INFO, "Warning : Web service endpoint " +
188                  descriptor.getEndpointName() + " is not tied to a component");
189         }
190
191         WebServiceHandlerNode handlerNode = new WebServiceHandlerNode();
192         handlerNode.writeWebServiceHandlers(wseNode,
193                                             descriptor.getHandlers());
194
195         WebServiceHandlerChainNode handlerChainNode = new WebServiceHandlerChainNode();
196         handlerChainNode.writeWebServiceHandlerChains(wseNode, descriptor.getHandlerChain());
197         return wseNode;
198     }
199 }
200
Popular Tags