KickJava   Java API By Example, From Geeks To Geeks.

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


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;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.logging.Level JavaDoc;
29
30 import java.util.List JavaDoc;
31 import org.w3c.dom.Node JavaDoc;
32 import org.xml.sax.Attributes JavaDoc;
33
34 import javax.xml.namespace.QName JavaDoc;
35
36 import com.sun.enterprise.deployment.util.DOLUtils;
37 import com.sun.enterprise.deployment.WebServiceHandler;
38 import com.sun.enterprise.deployment.NameValuePairDescriptor;
39 import com.sun.enterprise.deployment.xml.TagNames;
40 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
41
42 /**
43  * This node does xml marshalling to/from web service handlers.
44  *
45  * @author Kenneth Saks
46  */

47 public class WebServiceHandlerNode extends DisplayableComponentNode {
48
49     private final static XMLElement tag =
50         new XMLElement(WebServicesTagNames.HANDLER);
51
52     private NameValuePairDescriptor initParam = null;
53
54     public WebServiceHandlerNode() {
55         super();
56     }
57
58     /**
59      * @return the XML tag associated with this XMLNode
60      */

61     protected XMLElement getXMLRootTag() {
62         return tag;
63     }
64     
65     /**
66      * all sub-implementation of this class can use a dispatch table to map xml element to
67      * method name on the descriptor class for setting the element value.
68      *
69      * @return the map with the element name as a key, the setter method as a value
70      */

71     protected Map JavaDoc getDispatchTable() {
72         Map JavaDoc table = super.getDispatchTable();
73         table.put(WebServicesTagNames.SOAP_ROLE, "addSoapRole");
74         table.put(WebServicesTagNames.HANDLER_NAME, "setHandlerName");
75         table.put(WebServicesTagNames.HANDLER_CLASS, "setHandlerClass");
76         table.put(WebServicesTagNames.HANDLER_PORT_NAME, "addPortName");
77         return table;
78     }
79
80     /**
81      * receives notification of the value for a particular tag
82      *
83      * @param element the xml element
84      * @param value it's associated value
85      */

86     public void setElementValue(XMLElement element, String JavaDoc value) {
87         String JavaDoc qname = element.getQName();
88         WebServiceHandler handler = (WebServiceHandler) getDescriptor();
89         if (WebServicesTagNames.INIT_PARAM_NAME.equals(qname)) {
90             initParam = new NameValuePairDescriptor();
91             initParam.setName(value);
92         } else if (WebServicesTagNames.INIT_PARAM_VALUE.equals(qname)) {
93             initParam.setValue(value);
94             handler.addInitParam(initParam);
95         } else if (TagNames.DESCRIPTION.equals(qname)) {
96             if( initParam != null ) {
97                 // description for the init-param
98
initParam.setDescription(value);
99                 initParam = null;
100             } else {
101                 // must be the description element of the handler itself.
102
super.setElementValue(element, value);
103             }
104         } else if (WebServicesTagNames.SOAP_HEADER.equals(qname) ) {
105             String JavaDoc prefix = getPrefixFromQName(value);
106             String JavaDoc localPart = getLocalPartFromQName(value);
107             String JavaDoc namespaceUri = resolvePrefix(element, prefix);
108
109             if( namespaceUri == null) {
110                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
111                     new Object JavaDoc[] {prefix , handler.getHandlerName()});
112             } else {
113                 QName JavaDoc soapHeader = new QName JavaDoc(namespaceUri, localPart);
114                 handler.addSoapHeader(soapHeader);
115             }
116
117         } else super.setElementValue(element, value);
118     }
119     
120     /**
121      * write the method descriptor class to a query-method DOM tree and
122      * return it
123      *
124      * @param parent node in the DOM tree
125      * @param node name for the root element of this xml fragment
126      * @param the descriptor to write
127      * @return the DOM tree top node
128      */

129     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
130                                 WebServiceHandler handler) {
131         Node JavaDoc wshNode = super.writeDescriptor(parent, nodeName, handler);
132
133         writeDisplayableComponentInfo(wshNode, handler);
134         appendTextChild(wshNode,
135                         WebServicesTagNames.HANDLER_NAME,
136                         handler.getHandlerName());
137
138         appendTextChild(wshNode,
139                         WebServicesTagNames.HANDLER_CLASS,
140                         handler.getHandlerClass());
141         
142         for(Iterator JavaDoc iter = handler.getInitParams().iterator();iter.hasNext();){
143             NameValuePairDescriptor next = (NameValuePairDescriptor)iter.next();
144             Node JavaDoc initParamNode =
145                 appendChild(wshNode, WebServicesTagNames.INIT_PARAM);
146             appendTextChild(initParamNode, WebServicesTagNames.INIT_PARAM_NAME,
147                             next.getName());
148             appendTextChild(initParamNode, WebServicesTagNames.INIT_PARAM_VALUE,
149                             next.getValue());
150         }
151         
152         for(Iterator JavaDoc iter = handler.getSoapHeaders().iterator();
153             iter.hasNext();) {
154             QName JavaDoc next = (QName JavaDoc) iter.next();
155             // Append soap header QName. NOTE : descriptor does not contain
156
// a prefix so always generate one.
157
appendQNameChild(WebServicesTagNames.SOAP_HEADER, wshNode,
158                              next.getNamespaceURI(), next.getLocalPart(), null);
159         }
160
161         for(Iterator JavaDoc iter = handler.getSoapRoles().iterator(); iter.hasNext();){
162             String JavaDoc next = (String JavaDoc) iter.next();
163             appendTextChild(wshNode, WebServicesTagNames.SOAP_ROLE, next);
164         }
165
166         for(Iterator JavaDoc iter = handler.getPortNames().iterator(); iter.hasNext();){
167             String JavaDoc next = (String JavaDoc) iter.next();
168             appendTextChild(wshNode, WebServicesTagNames.HANDLER_PORT_NAME,
169                             next);
170         }
171
172         return wshNode;
173     }
174
175     public void writeWebServiceHandlers(Node JavaDoc parent, List JavaDoc handlerChain) {
176         for(Iterator JavaDoc iter = handlerChain.iterator(); iter.hasNext();) {
177             WebServiceHandler next = (WebServiceHandler) iter.next();
178             writeDescriptor(parent, WebServicesTagNames.HANDLER, next);
179         }
180     }
181
182 }
183
Popular Tags