1 23 package com.sun.enterprise.deployment.node.runtime; 24 25 import java.util.Map ; 26 import java.util.Set ; 27 import java.util.Iterator ; 28 import java.util.logging.Level ; 29 import org.w3c.dom.Node ; 30 31 import java.net.URL ; 32 import java.net.MalformedURLException ; 33 import javax.xml.namespace.QName ; 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 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 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 81 public Object getDescriptor() { 82 return descriptor; 83 } 84 85 91 protected Map getDispatchTable() { 92 Map table = super.getDispatchTable(); 93 table.put(WebServicesTagNames.SERVICE_IMPL_CLASS, 94 "setServiceImplClassName"); 95 return table; 96 } 97 98 104 105 public void setElementValue(XMLElement element, String value) { 106 String name = element.getQName(); 107 if (WebServicesTagNames.SERVICE_REF_NAME.equals(name)) { 108 Object 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 if( descriptor.getServiceNamespaceUri() == null ) { 119 descriptor.setServiceNamespaceUri(value); 120 } 121 } else if (WebServicesTagNames.LOCAL_PART.equals(name)) { 122 if( descriptor.getServiceLocalPart() == null ) { 124 descriptor.setServiceLocalPart(value); 125 } 126 } else if (WebServicesTagNames.WSDL_OVERRIDE.equals(name)) { 127 try { 128 URL url = new URL (value); 129 descriptor.setWsdlOverride(url); 130 } catch(MalformedURLException 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 148 public Node writeDescriptor(Node parent, String nodeName, 149 ServiceReferenceDescriptor serviceRef) { 150 Node 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 portsInfo = serviceRef.getPortsInfo(); 160 for(Iterator 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 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 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 serviceNameNode = appendChild 185 (serviceRefNode, WebServicesTagNames.SERVICE_QNAME); 186 QName 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 204 public static void writeServiceReferences(Node parent, 205 JndiNameEnvironment descriptor) { 206 Iterator 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 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 |