1 57 58 package org.apache.wsif.base; 59 60 import java.util.Hashtable ; 61 import java.util.Map ; 62 63 import javax.wsdl.Definition; 64 import javax.wsdl.PortType; 65 import javax.wsdl.Service; 66 import javax.xml.namespace.QName ; 67 68 import org.apache.wsif.WSIFException; 69 import org.apache.wsif.WSIFService; 70 import org.apache.wsif.WSIFServiceFactory; 71 import org.apache.wsif.logging.Trc; 72 73 79 public class WSIFServiceFactoryImpl extends WSIFServiceFactory { 80 81 private boolean useCache = false; 82 private Map cache = new Hashtable (); 83 84 100 public WSIFService getService( 101 String wsdlLoc, 102 String serviceNS, 103 String serviceName, 104 String portTypeNS, 105 String portTypeName) 106 throws WSIFException { 107 Trc.entry( 108 this, 109 wsdlLoc, 110 serviceNS, 111 serviceName, 112 portTypeNS, 113 portTypeName); 114 115 String key = ""; 116 if (useCache) { 117 key = 118 genCacheKey( 119 wsdlLoc, 120 serviceNS, 121 serviceName, 122 portTypeNS, 123 portTypeName); 124 WSIFServiceImpl cachedWSI = (WSIFServiceImpl) cache.get(key); 125 if (cachedWSI != null) { 126 WSIFServiceImpl wsi = new WSIFServiceImpl(cachedWSI); 127 Trc.exit(wsi); 128 return wsi; 129 } 130 } 131 132 WSIFServiceImpl wsi = 133 new WSIFServiceImpl( 134 wsdlLoc, 135 serviceNS, 136 serviceName, 137 portTypeNS, 138 portTypeName); 139 140 if (useCache && !key.equals("")) { 141 cache.put(key, wsi); 142 } 143 144 Trc.exit(wsi); 145 return wsi; 146 } 147 148 166 public WSIFService getService( 167 String wsdlLoc, 168 ClassLoader cl, 169 String serviceNS, 170 String serviceName, 171 String portTypeNS, 172 String portTypeName) 173 throws WSIFException { 174 Trc.entry( 175 this, 176 wsdlLoc, 177 cl, 178 serviceNS, 179 serviceName, 180 portTypeNS, 181 portTypeName); 182 183 String key = ""; 184 if (useCache) { 185 key = 186 genCacheKey( 187 wsdlLoc, 188 serviceNS, 189 serviceName, 190 portTypeNS, 191 portTypeName); 192 WSIFServiceImpl cachedWSI = (WSIFServiceImpl) cache.get(key); 193 if (cachedWSI != null) { 194 WSIFServiceImpl wsi = new WSIFServiceImpl(cachedWSI); 195 Trc.exit(wsi); 196 return wsi; 197 } 198 } 199 200 WSIFServiceImpl wsi = 201 new WSIFServiceImpl( 202 wsdlLoc, 203 cl, 204 serviceNS, 205 serviceName, 206 portTypeNS, 207 portTypeName); 208 209 if (useCache && !key.equals("")) { 210 cache.put(key, wsi); 211 } 212 213 Trc.exit(wsi); 214 return wsi; 215 } 216 217 223 public WSIFService getService(Definition def) throws WSIFException { 224 Trc.entryExpandWsdl(this, new Object [] { def }); 225 String key = ""; 226 if (useCache) { 227 key = genCacheKey(def, null, null); 228 WSIFServiceImpl cachedWSI = (WSIFServiceImpl) cache.get(key); 229 if (cachedWSI != null) { 230 WSIFServiceImpl wsi = new WSIFServiceImpl(cachedWSI); 231 Trc.exit(wsi); 232 return wsi; 233 } 234 } 235 236 WSIFServiceImpl wsi = new WSIFServiceImpl(def); 237 if (useCache && !key.equals("")) { 238 cache.put(key, wsi); 239 } 240 241 Trc.exit(wsi); 242 return wsi; 243 } 244 245 252 public WSIFService getService(Definition def, Service service) 253 throws WSIFException { 254 Trc.entryExpandWsdl(this, new Object [] { def, service }); 255 String key = ""; 256 if (useCache) { 257 key = genCacheKey(def, service, null); 258 WSIFServiceImpl cachedWSI = (WSIFServiceImpl) cache.get(key); 259 if (cachedWSI != null) { 260 WSIFServiceImpl wsi = new WSIFServiceImpl(cachedWSI); 261 Trc.exit(wsi); 262 return wsi; 263 } 264 } 265 266 WSIFServiceImpl wsi = new WSIFServiceImpl(def, service); 267 if (useCache && !key.equals("")) { 268 cache.put(key, wsi); 269 } 270 Trc.exit(wsi); 271 return wsi; 272 } 273 274 282 public WSIFService getService( 283 Definition def, 284 Service service, 285 PortType portType) 286 throws WSIFException { 287 Trc.entryExpandWsdl(this, new Object []{def, service, portType}); 288 String key = ""; 289 if (useCache) { 290 key = genCacheKey(def, service, portType); 291 WSIFServiceImpl cachedWSI = (WSIFServiceImpl) cache.get(key); 292 if (cachedWSI != null) { 293 WSIFServiceImpl wsi = new WSIFServiceImpl(cachedWSI); 294 Trc.exit(wsi); 295 return wsi; 296 } 297 } 298 299 WSIFServiceImpl wsi = new WSIFServiceImpl(def, service, portType); 300 if (useCache && !key.equals("")) { 301 cache.put(key, wsi); 302 } 303 304 Trc.exit(wsi); 305 return wsi; 306 } 307 308 318 public WSIFService getService( 319 Definition def, 320 String serviceNS, 321 String serviceName, 322 String portTypeNS, 323 String portTypeName) 324 throws WSIFException { 325 Trc.entryExpandWsdl( 326 this, 327 new Object [] { 328 def, 329 serviceNS, 330 serviceName, 331 portTypeNS, 332 portTypeName }); 333 334 String key = ""; 335 if (useCache) { 336 key = 337 genCacheKey( 338 def, 339 serviceNS, 340 serviceName, 341 portTypeNS, 342 portTypeName); 343 WSIFServiceImpl cachedWSI = (WSIFServiceImpl) cache.get(key); 344 if (cachedWSI != null) { 345 WSIFServiceImpl wsi = new WSIFServiceImpl(cachedWSI); 346 Trc.exit(wsi); 347 return wsi; 348 } 349 } 350 351 WSIFServiceImpl wsi = 352 new WSIFServiceImpl( 353 def, 354 serviceNS, 355 serviceName, 356 portTypeNS, 357 portTypeName); 358 if (useCache && !key.equals("")) { 359 cache.put(key, wsi); 360 } 361 362 Trc.exit(wsi); 363 return wsi; 364 } 365 366 373 public void cachingOn(boolean on) { 374 Trc.entry(this,on); 375 useCache = on; 376 Trc.exit(); 377 } 378 379 private String genCacheKey( 380 Definition def, 381 Service service, 382 PortType portType) { 383 Trc.entry(this, def, service, portType); 384 385 String db = 386 (def != null && def.getDocumentBaseURI() != null) 387 ? def.getDocumentBaseURI() 388 : "null"; 389 QName serviceName = (service != null) ? service.getQName() : null; 390 String sn = (serviceName != null) ? serviceName.toString() : "null"; 391 QName portTypeName = (portType != null) ? portType.getQName() : null; 392 String ptn = (portTypeName != null) ? portTypeName.toString() : "null"; 393 StringBuffer key = new StringBuffer (); 394 key.append("D="); 395 key.append(db); 396 key.append("S="); 397 key.append(sn); 398 key.append("P="); 399 key.append(ptn); 400 401 String ret = key.toString(); 402 if (ret.equals("D=nullS=nullP=null")) 404 ret = ""; 405 Trc.exit(ret); 406 return ret; 407 } 408 409 private String genCacheKey( 410 String wsdlLoc, 411 String serviceNS, 412 String serviceName, 413 String portTypeNS, 414 String portTypeName) { 415 Trc.entry( 416 this, 417 wsdlLoc, 418 serviceNS, 419 serviceName, 420 portTypeNS, 421 portTypeName); 422 423 StringBuffer key = new StringBuffer (); 424 if (wsdlLoc == null) 425 wsdlLoc = ""; 426 if (serviceNS == null) 427 serviceNS = ""; 428 if (serviceName == null) 429 serviceName = ""; 430 if (portTypeNS == null) 431 portTypeNS = ""; 432 if (portTypeName == null) 433 portTypeName = ""; 434 key.append("W="); 435 key.append(wsdlLoc); 436 key.append("SN="); 437 key.append(serviceNS); 438 key.append("SS="); 439 key.append(serviceName); 440 key.append("PN="); 441 key.append(portTypeNS); 442 key.append("PS="); 443 key.append(portTypeName); 444 445 String ret = key.toString(); 446 if (ret.equals("W=SN=SS=PN=PS=")) 448 ret = ""; 449 Trc.exit(ret); 450 return ret; 451 } 452 453 private String genCacheKey( 454 Definition def, 455 String serviceNS, 456 String serviceName, 457 String portTypeNS, 458 String portTypeName) { 459 Trc.entry(this, def, serviceNS, serviceName, portTypeNS, portTypeName); 460 461 StringBuffer key = new StringBuffer (); 462 String db = 463 (def != null && def.getDocumentBaseURI() != null) 464 ? def.getDocumentBaseURI() 465 : "null"; 466 if (serviceNS == null) 467 serviceNS = ""; 468 if (serviceName == null) 469 serviceName = ""; 470 if (portTypeNS == null) 471 portTypeNS = ""; 472 if (portTypeName == null) 473 portTypeName = ""; 474 key.append("D="); 475 key.append(db); 476 key.append("SN="); 477 key.append(serviceNS); 478 key.append("SS="); 479 key.append(serviceName); 480 key.append("PN="); 481 key.append(portTypeNS); 482 key.append("PS="); 483 key.append(portTypeName); 484 485 String ret = key.toString(); 486 if (ret.equals("D=nullSN=SS=PN=PS=")) 488 ret = ""; 489 Trc.exit(ret); 490 return ret; 491 } 492 } 493 | Popular Tags |