1 23 package com.sun.enterprise.deployment; 24 25 import java.util.Iterator ; 26 import java.util.StringTokenizer ; 27 import java.util.Collection ; 28 import java.util.Map ; 29 import java.util.HashMap ; 30 31 import java.io.*; 32 import java.net.*; 33 34 35 41 42 public class WebService extends Descriptor { 43 44 private String wsdlFileUri; 45 46 50 private URL wsdlFileUrl; 51 52 private String mappingFileUri; 53 54 58 private File mappingFile; 59 60 private HashMap <String , WebServiceEndpoint> endpoints; 61 62 private WebServicesDescriptor webServicesDesc; 64 65 69 private URL publishUrl; 73 74 77 public WebService() { 78 this(""); 79 } 80 81 84 public WebService(WebService other) { 85 super(other); 86 wsdlFileUri = other.wsdlFileUri; wsdlFileUrl = other.wsdlFileUrl; 88 mappingFileUri = other.mappingFileUri; mappingFile = other.mappingFile; 90 publishUrl = other.publishUrl; 91 webServicesDesc = other.webServicesDesc; if (other.endpoints != null) { 93 endpoints = new HashMap <String , WebServiceEndpoint>(); 94 for (WebServiceEndpoint wsep : other.endpoints.values()) { 95 wsep.setWebService(this); 96 endpoints.put(wsep.getEndpointName(), wsep); 97 } 98 } else { 99 endpoints = null; 100 } 101 } 102 103 public WebService(String name) { 104 setName(name); 105 endpoints = new HashMap (); 106 } 107 108 public void setWebServicesDescriptor(WebServicesDescriptor webServices) { 109 webServicesDesc = webServices; 110 } 111 112 public WebServicesDescriptor getWebServicesDescriptor() { 113 return webServicesDesc; 114 } 115 116 public BundleDescriptor getBundleDescriptor() { 117 return webServicesDesc.getBundleDescriptor(); 118 } 119 120 public boolean hasWsdlFile() { 121 return (wsdlFileUri != null); 122 } 123 124 public void setWsdlFileUri(String uri) { 125 wsdlFileUri = uri; 126 super.changed(); 127 } 128 129 public String getWsdlFileUri() { 130 if (wsdlFileUri==null && wsdlFileUrl!=null) { 131 return getBundleDescriptor().getWsdlDir() + "/" 134 + (new File(wsdlFileUrl.getFile())).getName(); 135 } 136 return wsdlFileUri; 137 } 138 139 public URL getWsdlFileUrl() { 140 return wsdlFileUrl; 141 } 142 143 public void setWsdlFileUrl(URL url) { 144 wsdlFileUrl = url; 145 super.changed(); 146 } 147 148 public String getGeneratedWsdlFilePath() { 149 if (hasWsdlFile()) { 150 String xmlDir = getBundleDescriptor().getApplication().getGeneratedXMLDirectory(); 151 if(!getBundleDescriptor().getModuleDescriptor().isStandalone()) { 152 String uri = getBundleDescriptor().getModuleDescriptor().getArchiveUri(); 153 xmlDir = xmlDir + File.separator + uri.replaceAll("\\.", "_"); 154 } 155 if(xmlDir == null) { 156 return null; 157 } 158 return xmlDir + File.separator + wsdlFileUri; 159 } else { 160 return getWsdlFileUrl().getPath(); 161 } 162 } 163 164 public boolean hasMappingFile() { 165 return (mappingFileUri != null); 166 } 167 168 public void setMappingFileUri(String uri) { 169 mappingFileUri = uri; 170 super.changed(); 171 } 172 173 public String getMappingFileUri() { 174 return mappingFileUri; 175 } 176 177 public File getMappingFile() { 178 return mappingFile; 179 } 180 181 public void setMappingFile(File file) { 182 mappingFile = file; 183 super.changed(); 184 } 185 186 public void addEndpoint(WebServiceEndpoint endpoint) { 187 endpoint.setWebService(this); 188 endpoints.put(endpoint.getEndpointName(), endpoint); 189 super.changed(); 190 } 191 192 public void removeEndpointByName(String endpointName) { 193 WebServiceEndpoint endpoint = (WebServiceEndpoint) 194 endpoints.remove(endpointName); 195 endpoint.setWebService(null); 196 super.changed(); 197 } 198 199 public void removeEndpoint(WebServiceEndpoint endpoint) { 200 removeEndpointByName(endpoint.getEndpointName()); 201 super.changed(); 202 } 203 204 public Collection <WebServiceEndpoint> getEndpoints() { 205 HashMap shallowCopy = new HashMap (endpoints); 206 return shallowCopy.values(); 207 } 208 209 public boolean hasClientPublishUrl() { 210 return (publishUrl != null); 211 } 212 213 public void setClientPublishUrl(URL url) { 214 publishUrl = url; 215 super.changed(); 216 } 217 218 public URL getClientPublishUrl() { 219 return publishUrl; 220 } 221 222 public boolean hasUrlPublishing() { 223 return (!hasFilePublishing()); 224 } 225 226 public boolean hasFilePublishing() { 227 return (hasClientPublishUrl() && 228 publishUrl.getProtocol().equals("file")); 229 } 230 231 235 public WebServiceEndpoint pickEndpointForRelativeImports() { 236 WebServiceEndpoint pick = null; 237 238 for(WebServiceEndpoint wse : endpoints.values()) { 240 if( wse.isSecure() ) { 241 pick = wse; 242 break; 243 } 244 pick = wse; 245 } 246 return pick; 247 } 248 249 252 public void print(StringBuffer toStringBuffer) { 253 super.print(toStringBuffer); 254 toStringBuffer.append( "\n wsdl file : ").append( wsdlFileUri); 255 toStringBuffer.append( "\n mapping file ").append(mappingFileUri); 256 toStringBuffer.append( "\n publish url ").append(publishUrl); 257 toStringBuffer.append( "\n final wsdl ").append(wsdlFileUrl); 258 toStringBuffer.append( "\n endpoints ").append(endpoints); 259 } 260 261 } 262 | Popular Tags |