1 25 26 package org.objectweb.jonas_ws.deployment.api; 27 28 import java.io.File ; 29 import java.io.InputStream ; 30 import java.net.MalformedURLException ; 31 import java.net.URL ; 32 import java.util.HashMap ; 33 import java.util.Hashtable ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.Map ; 37 import java.util.Set ; 38 import java.util.Vector ; 39 40 import org.objectweb.jonas_lib.I18n; 41 42 import org.objectweb.jonas_ws.deployment.lib.MappingFileManager; 43 import org.objectweb.jonas_ws.deployment.lib.wrapper.MappingFileManagerWrapper; 44 import org.objectweb.jonas_ws.deployment.xml.JonasPortComponent; 45 import org.objectweb.jonas_ws.deployment.xml.JonasWebserviceDescription; 46 import org.objectweb.jonas_ws.deployment.xml.PortComponent; 47 import org.objectweb.jonas_ws.deployment.xml.WebserviceDescription; 48 49 import org.objectweb.jonas.common.Log; 50 51 import org.objectweb.util.monolog.api.BasicLevel; 52 import org.objectweb.util.monolog.api.Logger; 53 54 62 public class ServiceDesc { 63 64 67 private static I18n i18n = I18n.getInstance(ServiceDesc.class); 68 69 72 private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX); 73 74 77 private String name; 78 79 82 private Hashtable namePCDescBindings = new Hashtable (); 83 84 87 private WSDLFile wsdl = null; 88 89 92 private MappingFile mapping = null; 93 94 97 private String endpointURI = null; 98 99 102 private File publicationDirectory = null; 103 104 107 private URL mappingFileURL; 108 109 112 private URL localWSDLURL; 113 114 117 private String mappingFilename = null; 118 119 122 private String wsdlFilename = null; 123 124 131 public ServiceDesc(ClassLoader jarCL, WebserviceDescription wsd, JonasWebserviceDescription jwsd) throws WSDeploymentDescException { 132 133 name = wsd.getWebserviceDescriptionName(); 135 if ("".equals(name)) { throw new WSDeploymentDescException(getI18n().getMessage("ServiceDesc.noServiceName")); } 138 139 if (jwsd != null) { 140 String uri = jwsd.getDefaultEndpointURI(); 142 if (uri != null && !"".equals(uri)) { 143 endpointURI = uri; 144 } 145 146 String wsdlPubDir = jwsd.getWsdlPublishDirectory(); 148 if (wsdlPubDir != null) { 149 URL pub; 150 try { 151 pub = new URL (wsdlPubDir); 152 } catch (MalformedURLException e) { 153 throw new WSDeploymentDescException("Cannot create URL : " + wsdlPubDir, e); 154 } 155 publicationDirectory = new File (pub.getPath()); 156 } 157 } 158 159 160 wsdlFilename = wsd.getWsdlFile(); 162 163 if ("".equals(wsdlFilename)) { String err = getI18n().getMessage("ServiceDesc.noWSDL", name); throw new WSDeploymentDescException(err); 167 } 168 169 wsdl = new WSDLFile(jarCL, wsdlFilename); 171 localWSDLURL = jarCL.getResource(wsdlFilename); 172 173 mappingFilename = wsd.getJaxrpcMappingFile(); 175 176 if (mappingFilename.equals("")) { String err = getI18n().getMessage("ServiceDesc.noJAXRPCMapping", name); throw new WSDeploymentDescException(err); 180 } 181 182 InputStream isMapping = jarCL.getResourceAsStream(mappingFilename); 183 184 if (isMapping == null) { 186 String err = getI18n().getMessage("ServiceDesc.MappingNotFound", mappingFilename, name); throw new WSDeploymentDescException(err); 188 } 189 190 mappingFileURL = jarCL.getResource(mappingFilename); 191 192 if (isRunningInClientContainer()) { 194 mapping = MappingFileManager.getInstance(isMapping, mappingFilename); 196 } else { 197 mapping = MappingFileManagerWrapper.getMappingFile(isMapping, mappingFilename); 199 } 200 201 Map links = associatePCAndJPC(wsd, jwsd); 203 204 List pcl = wsd.getPortComponentList(); 206 207 for (int i = 0; i < pcl.size(); i++) { 208 PortComponent pc = (PortComponent) pcl.get(i); 210 JonasPortComponent jpc = (JonasPortComponent) links.get(pc.getPortComponentName()); 211 212 PortComponentDesc pcd = PortComponentDescFactory.newInstance(jarCL, pc, jpc, this); 213 214 if (!wsdl.hasPort(pcd.getQName())) { 215 throw new WSDeploymentDescException(getI18n().getMessage( 216 "ServiceDesc.unknownWSDLPort", pcd.getName(), pcd.getQName())); } 218 219 if (namePCDescBindings.put(pcd.getName(), pcd) != null) { 220 throw new WSDeploymentDescException(getI18n().getMessage( 221 "ServiceDesc.portNameAlreadyUsed", pcd.getName())); } 223 } 224 225 List ports = getPortComponents(); 227 228 for (int i = 0; i < ports.size(); i++) { 230 if (ports.get(i) != null) { 231 PortComponentDesc pcd = (PortComponentDesc) ports.get(i); 232 233 if (!wsdl.hasSOAPBinding(pcd.getQName())) { 234 throw new WSDeploymentDescException(getI18n().getMessage( 235 "ServiceDesc.noSOAPBinding", pcd.getName(), pcd.getQName())); } 237 } 238 } 239 } 240 241 245 private boolean isRunningInClientContainer() { 246 return (System.getProperty("jonas.base") == null); 247 } 248 249 254 private Map associatePCAndJPC(WebserviceDescription wsd, JonasWebserviceDescription jwsd) { 255 Map res = new HashMap (); 256 for (Iterator i = wsd.getPortComponentList().iterator(); i.hasNext();) { 258 PortComponent pc = (PortComponent) i.next(); 259 res.put(pc.getPortComponentName(), null); 260 } 261 if (jwsd != null) { 263 264 Set keys = res.keySet(); 266 267 for (Iterator i = jwsd.getJonasPortComponentList().iterator(); i.hasNext();) { 269 JonasPortComponent jpc = (JonasPortComponent) i.next(); 270 String pcName = jpc.getPortComponentName(); 271 272 if (keys.contains(pcName)) { 273 res.put(pcName, jpc); 275 } else { 276 String err = "jonas-port-component '" + pcName + "' is not linked to any port-component. It will be ignored."; logger.log(BasicLevel.WARN, err); 278 } 279 } 280 } 281 return res; 282 } 283 284 288 public String getName() { 289 return name; 290 } 291 292 296 public MappingFile getMapping() { 297 return mapping; 298 } 299 300 304 public WSDLFile getWSDL() { 305 return wsdl; 306 } 307 308 311 public String getEndpointURI() { 312 return endpointURI; 313 } 314 315 319 public List getPortComponents() { 320 return new Vector (namePCDescBindings.values()); 321 } 322 323 330 public PortComponentDesc getPortComponent(String pcName) { 331 return (PortComponentDesc) namePCDescBindings.get(pcName); 332 } 333 334 337 public String toString() { 338 StringBuffer sb = new StringBuffer (); 339 340 sb.append("\n" + getClass().getName()); sb.append("\ngetName()=" + getName()); sb.append("\ngetMapping()=" + getMapping()); sb.append("\ngetWSDL()=" + getWSDL()); 345 for (Iterator i = getPortComponents().iterator(); i.hasNext();) { 346 sb.append("\ngetPortComponents()=" + ((PortComponentDesc) i.next()).toString()); } 348 349 return sb.toString(); 350 } 351 352 355 protected static I18n getI18n() { 356 return i18n; 357 } 358 359 362 public File getPublicationDirectory() { 363 return publicationDirectory; 364 } 365 366 369 public URL getMappingFileURL() { 370 return mappingFileURL; 371 } 372 373 376 public URL getLocalWSDLURL() { 377 return localWSDLURL; 378 } 379 380 383 public String getMappingFilename() { 384 return mappingFilename; 385 } 386 387 390 public String getWsdlFilename() { 391 return wsdlFilename; 392 } 393 } | Popular Tags |