KickJava   Java API By Example, From Geeks To Geeks.

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


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.Set JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30
31 import java.net.URL JavaDoc;
32 import java.net.MalformedURLException JavaDoc;
33 import javax.xml.namespace.QName JavaDoc;
34 import com.sun.enterprise.deployment.JndiNameEnvironment;
35 import com.sun.enterprise.deployment.node.XMLElement;
36 import com.sun.enterprise.deployment.node.NameValuePairNode;
37 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
38 import com.sun.enterprise.deployment.node.runtime.web.WebBundleRuntimeNode;
39 import com.sun.enterprise.deployment.NameValuePairDescriptor;
40 import com.sun.enterprise.deployment.WebBundleDescriptor;
41 import com.sun.enterprise.deployment.runtime.web.SunWebApp;
42 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
43 import com.sun.enterprise.deployment.ServiceRefPortInfo;
44 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
45
46 import com.sun.enterprise.deployment.util.DOLUtils;
47
48 /**
49  * This node is responsible for handling runtime info for
50  * service references
51  *
52  * @author Kenneth Saks
53  * @version
54  */

55 public class ServiceRefNode extends DeploymentDescriptorNode {
56
57     private ServiceReferenceDescriptor descriptor;
58
59     public ServiceRefNode() {
60         super();
61         registerElementHandler
62             (new XMLElement(WebServicesTagNames.PORT_INFO),
63              ServiceRefPortInfoRuntimeNode.class);
64         registerElementHandler
65             (new XMLElement(WebServicesTagNames.CALL_PROPERTY),
66              NameValuePairNode.class, "addCallProperty");
67     }
68     
69     public void addDescriptor(Object JavaDoc desc) {
70         if( desc instanceof ServiceRefPortInfo ) {
71             ServiceRefPortInfo newPortInfo = (ServiceRefPortInfo) desc;
72             ServiceReferenceDescriptor serviceRef =
73                 (ServiceReferenceDescriptor) getDescriptor();
74             serviceRef.addRuntimePortInfo(newPortInfo);
75         }
76     }
77
78     /**
79     * @return the descriptor instance to associate with this XMLNode
80     */

81     public Object JavaDoc getDescriptor() {
82         return descriptor;
83     }
84     
85     /**
86      * all sub-implementation of this class can use a dispatch table to map xml element to
87      * method name on the descriptor class for setting the element value.
88      *
89      * @return the map with the element name as a key, the setter method as a value
90      */

91     protected Map JavaDoc getDispatchTable() {
92         Map JavaDoc table = super.getDispatchTable();
93         table.put(WebServicesTagNames.SERVICE_IMPL_CLASS,
94                   "setServiceImplClassName");
95         return table;
96     }
97     
98     /**
99      * receives notiification of the value for a particular tag
100      *
101      * @param element the xml element
102      * @param value it's associated value
103      */

104
105     public void setElementValue(XMLElement element, String JavaDoc value) {
106         String JavaDoc name = element.getQName();
107         if (WebServicesTagNames.SERVICE_REF_NAME.equals(name)) {
108             Object JavaDoc parentDesc = getParentNode().getDescriptor();
109             if (parentDesc instanceof JndiNameEnvironment) {
110                 descriptor = ((JndiNameEnvironment) parentDesc).
111                     getServiceReferenceByName(value);
112             } else if (parentDesc instanceof SunWebApp) {
113                 WebBundleDescriptor desc = ((WebBundleRuntimeNode) getParentNode()).getWebBundleDescriptor();
114                 descriptor = desc.getServiceReferenceByName(value);
115             }
116         } else if (WebServicesTagNames.NAMESPACE_URI.equals(name)) {
117             // Any service-qname set in standard DD takes precedence
118
if( descriptor.getServiceNamespaceUri() == null ) {
119                 descriptor.setServiceNamespaceUri(value);
120             }
121         } else if (WebServicesTagNames.LOCAL_PART.equals(name)) {
122             // Any service-qname set in standard DD takes precedence
123
if( descriptor.getServiceLocalPart() == null ) {
124                 descriptor.setServiceLocalPart(value);
125             }
126         } else if (WebServicesTagNames.WSDL_OVERRIDE.equals(name)) {
127             try {
128                 URL JavaDoc url = new URL JavaDoc(value);
129                 descriptor.setWsdlOverride(url);
130             } catch(MalformedURLException JavaDoc mue) {
131                 DOLUtils.getDefaultLogger().log(Level.INFO,
132                   "Warning : Invalid wsdl override url=" + value, mue);
133             }
134         } else {
135             super.setElementValue(element, value);
136         }
137         
138     }
139     
140     /**
141      * write the descriptor class to a DOM tree and return it
142      *
143      * @param parent node for the DOM tree
144      * @param node name for the descriptor
145      * @param the descriptor to write
146      * @return the DOM tree top node
147      */

148     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
149                                 ServiceReferenceDescriptor serviceRef) {
150         Node JavaDoc serviceRefNode =
151             super.writeDescriptor(parent, nodeName, serviceRef);
152
153         appendTextChild(serviceRefNode, WebServicesTagNames.SERVICE_REF_NAME,
154                         serviceRef.getName());
155
156         ServiceRefPortInfoRuntimeNode portInfoRuntimeNode =
157             new ServiceRefPortInfoRuntimeNode();
158
159         Set JavaDoc portsInfo = serviceRef.getPortsInfo();
160         for(Iterator JavaDoc iter = portsInfo.iterator(); iter.hasNext();) {
161             ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next();
162             portInfoRuntimeNode.writeDescriptor
163                 (serviceRefNode, WebServicesTagNames.PORT_INFO, next);
164         }
165
166         NameValuePairNode nameValueNode = new NameValuePairNode();
167         for(Iterator JavaDoc iter = serviceRef.getCallProperties().iterator();
168             iter.hasNext();) {
169             NameValuePairDescriptor next = (NameValuePairDescriptor)iter.next();
170             nameValueNode.writeDescriptor
171                 (serviceRefNode, WebServicesTagNames.CALL_PROPERTY, next);
172         }
173
174         if( serviceRef.hasWsdlOverride() ) {
175             URL JavaDoc wsdlOverride = serviceRef.getWsdlOverride();
176             appendTextChild(serviceRefNode, WebServicesTagNames.WSDL_OVERRIDE,
177                             wsdlOverride.toExternalForm());
178         }
179
180         appendTextChild(serviceRefNode, WebServicesTagNames.SERVICE_IMPL_CLASS,
181                         serviceRef.getServiceImplClassName());
182
183         if( serviceRef.hasServiceName() ) {
184             Node JavaDoc serviceNameNode = appendChild
185                 (serviceRefNode, WebServicesTagNames.SERVICE_QNAME);
186             QName JavaDoc serviceName = serviceRef.getServiceName();
187             appendTextChild(serviceNameNode,
188                             WebServicesTagNames.NAMESPACE_URI,
189                             serviceName.getNamespaceURI());
190             appendTextChild(serviceNameNode,
191                             WebServicesTagNames.LOCAL_PART,
192                             serviceName.getLocalPart());
193         }
194
195         return serviceRefNode;
196     }
197     
198     /**
199      * writes all the runtime information for service references
200      *
201      * @param parent node to add the runtime xml info
202      * @param the J2EE component containing service references
203      */

204     public static void writeServiceReferences(Node JavaDoc parent,
205                                               JndiNameEnvironment descriptor) {
206         Iterator JavaDoc serviceRefs =
207             descriptor.getServiceReferenceDescriptors().iterator();
208         if (serviceRefs.hasNext()) {
209             ServiceRefNode serviceRefNode = new ServiceRefNode();
210             while (serviceRefs.hasNext()) {
211                 ServiceReferenceDescriptor next =
212                     (ServiceReferenceDescriptor) serviceRefs.next();
213                 // Only write runtime service-ref entry if there IS
214
// some runtime info...
215
if( next.hasServiceImplClassName() ||
216                     !next.getPortsInfo().isEmpty() ||
217                     !next.getCallProperties().isEmpty() ||
218                     next.hasWsdlOverride()) {
219                     serviceRefNode.writeDescriptor
220                         (parent, WebServicesTagNames.SERVICE_REF, next);
221                 }
222             }
223         }
224     }
225     
226 }
227
Popular Tags