1 23 package com.sun.enterprise.deployment; 24 25 import java.util.List ; 26 import java.util.LinkedList ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.Collection ; 30 import java.util.HashSet ; 31 import java.util.Set ; 32 import java.util.Iterator ; 33 34 import java.io.*; 35 36 import java.net.URL ; 37 import javax.xml.namespace.QName ; 38 39 import com.sun.enterprise.deployment.util.ModuleDescriptor; 40 import com.sun.enterprise.util.FileUtil; 41 import com.sun.enterprise.util.LocalStringManagerImpl; 42 import com.sun.enterprise.deployment.util.DOLUtils; 43 import com.sun.enterprise.deployment.types.HandlerChainContainer; 44 45 50 51 public class ServiceReferenceDescriptor extends EnvironmentProperty 52 implements HandlerChainContainer { 53 54 private String serviceInterface; 55 56 private String mappedName; 57 58 private String wsdlFileUri; 59 60 64 private URL wsdlFileUrl; 65 66 private String mappingFileUri; 67 68 72 private File mappingFile; 73 74 private String serviceNamespaceUri; 77 private String serviceLocalPart; 78 private String serviceNameNamespacePrefix; 79 80 private Set portsInfo; 82 83 private BundleDescriptor bundleDescriptor; 85 86 private LinkedList handlers; 89 90 private LinkedList handlerChain; 92 93 97 private Set callProperties; 98 99 private String serviceImplClassName; 101 102 private URL wsdlOverride; 105 106 private String injectionTargetType=null; 111 112 public ServiceReferenceDescriptor(ServiceReferenceDescriptor other) { 113 super(other); 114 serviceInterface = other.serviceInterface; 115 mappedName = other.mappedName; 116 wsdlFileUri = other.wsdlFileUri; 117 wsdlFileUrl = other.wsdlFileUrl; 118 mappingFileUri = other.mappingFileUri; 119 mappingFile = other.mappingFile; 120 serviceNamespaceUri = other.serviceNamespaceUri; 121 serviceLocalPart = other.serviceLocalPart; 122 serviceNameNamespacePrefix = other.serviceNameNamespacePrefix; 123 portsInfo = new HashSet (); for (Iterator i = other.portsInfo.iterator(); i.hasNext();) { 125 ServiceRefPortInfo port = new ServiceRefPortInfo( 126 (ServiceRefPortInfo)i.next()); 127 port.setServiceReference(this); portsInfo.add(port); 129 } 130 handlers = new LinkedList (); for (Iterator i = other.handlers.iterator(); i.hasNext();) { 132 handlers.add(new WebServiceHandler 133 ((WebServiceHandler)i.next())); 134 } 135 handlerChain = new LinkedList (); for (Iterator i = other.handlerChain.iterator(); i.hasNext();) { 137 handlerChain.add(new WebServiceHandlerChain((WebServiceHandlerChain)i.next())); 138 } 139 callProperties = new HashSet (); for (Iterator i = other.callProperties.iterator(); i.hasNext();) { 141 callProperties.add(new NameValuePairDescriptor( 142 (NameValuePairDescriptor)i.next())); 143 } 144 serviceImplClassName = other.serviceImplClassName; 145 } 146 147 public ServiceReferenceDescriptor(String name, String description, 148 String service) { 149 super(name, "", description); 150 handlers = new LinkedList (); 151 handlerChain = new LinkedList (); 152 portsInfo = new HashSet (); 153 callProperties = new HashSet (); 154 serviceInterface = service; 155 } 156 157 public ServiceReferenceDescriptor() { 158 handlers = new LinkedList (); 159 handlerChain = new LinkedList (); 160 portsInfo = new HashSet (); 161 callProperties = new HashSet (); 162 } 163 164 public String getMappedName() { 165 return mappedName; 166 } 167 168 public void setMappedName(String value) { 169 mappedName = value; 170 } 171 172 public void setBundleDescriptor(BundleDescriptor bundle) { 173 bundleDescriptor = bundle; 174 } 175 176 public BundleDescriptor getBundleDescriptor() { 177 return bundleDescriptor; 178 } 179 180 public boolean hasGenericServiceInterface() { 181 return serviceInterface.equals("javax.xml.rpc.Service"); 182 } 183 184 public boolean hasGeneratedServiceInterface() { 185 return !(hasGenericServiceInterface()); 186 } 187 188 public void setServiceInterface(String service) { 189 serviceInterface = service; 190 super.changed(); 191 } 192 193 public String getServiceInterface() { 194 return serviceInterface; 195 } 196 197 public boolean hasWsdlFile() { 198 return (wsdlFileUri != null); 199 } 200 201 205 public void setWsdlFileUrl(URL url) { 206 wsdlFileUrl = url; 207 super.changed(); 208 } 209 210 public URL getWsdlFileUrl() { 211 return wsdlFileUrl; 212 } 213 214 public void setWsdlFileUri(String uri) { 215 wsdlFileUri = uri; 216 super.changed(); 217 } 218 219 public String getWsdlFileUri() { 220 return wsdlFileUri; 221 } 222 223 public boolean hasMappingFile() { 224 return (mappingFileUri != null); 225 } 226 227 231 public void setMappingFile(File file) { 232 mappingFile = file; 233 super.changed(); 234 } 235 236 public File getMappingFile() { 237 return mappingFile; 238 } 239 240 public void setMappingFileUri(String uri) { 241 mappingFileUri = uri; 242 super.changed(); 243 } 244 245 public String getMappingFileUri() { 246 return mappingFileUri; 247 } 248 249 public void setServiceName(QName serviceName) { 250 setServiceName(serviceName, null); 251 } 252 253 public void setServiceName(QName serviceName, String prefix) { 254 serviceNamespaceUri = serviceName.getNamespaceURI(); 255 serviceLocalPart = serviceName.getLocalPart(); 256 serviceNameNamespacePrefix = prefix; 257 super.changed(); 258 } 259 260 public void setServiceNamespaceUri(String uri) { 261 serviceNamespaceUri = uri; 262 serviceNameNamespacePrefix = null; 263 super.changed(); 264 } 265 266 public String getServiceNamespaceUri() { 267 return serviceNamespaceUri; 268 } 269 270 public void setServiceLocalPart(String localpart) { 271 serviceLocalPart = localpart; 272 serviceNameNamespacePrefix = null; 273 super.changed(); 274 } 275 276 public String getServiceLocalPart() { 277 return serviceLocalPart; 278 } 279 280 public void setServiceNameNamespacePrefix(String prefix) { 281 serviceNameNamespacePrefix = prefix; 282 super.changed(); 283 } 284 285 public String getServiceNameNamespacePrefix() { 286 return serviceNameNamespacePrefix; 287 } 288 289 public boolean hasServiceName() { 290 return ( (serviceNamespaceUri != null) && (serviceLocalPart != null) ); 291 } 292 293 296 public QName getServiceName() { 297 return ( hasServiceName() ? 298 new QName (serviceNamespaceUri, serviceLocalPart) : null ); 299 } 300 301 public Set getPortsInfo() { 302 return portsInfo; 303 } 304 305 public void addPortInfo(ServiceRefPortInfo portInfo) { 306 portInfo.setServiceReference(this); 307 portsInfo.add(portInfo); 308 super.changed(); 309 } 310 311 public void removePortInfo(ServiceRefPortInfo portInfo) { 312 portsInfo.remove(portInfo); 313 super.changed(); 314 } 315 316 321 public void addRuntimePortInfo(ServiceRefPortInfo runtimePortInfo) { 322 ServiceRefPortInfo existing = null; 323 324 if( runtimePortInfo.hasServiceEndpointInterface() ) { 325 existing = 326 getPortInfoBySEI(runtimePortInfo.getServiceEndpointInterface()); 327 } 328 if( (existing == null) && runtimePortInfo.hasWsdlPort() ) { 329 existing = getPortInfoByPort(runtimePortInfo.getWsdlPort()); 330 } 331 332 if( existing == null ) { 333 if (portsInfo!=null && portsInfo.size()>0) { 334 LocalStringManagerImpl localStrings = 335 new LocalStringManagerImpl(ServiceReferenceDescriptor.class); 336 DOLUtils.getDefaultLogger().warning( 337 localStrings.getLocalString("enterprise.deployment.unknownportforruntimeinfo", 338 "Runtime port info SEI {0} is not declared in standard service-ref " + 339 "deployment descriptors (under port-component-ref), is this intended ?", 340 new Object [] {runtimePortInfo.getServiceEndpointInterface()})); 341 } 342 addPortInfo(runtimePortInfo); 343 } else { 344 if( !existing.hasServiceEndpointInterface() ) { 345 existing.setServiceEndpointInterface 346 (runtimePortInfo.getServiceEndpointInterface()); 347 } 348 if( !existing.hasWsdlPort() ) { 349 existing.setWsdlPort(runtimePortInfo.getWsdlPort()); 350 } 351 for(Iterator iter = runtimePortInfo. 352 getStubProperties().iterator(); iter.hasNext();) { 353 NameValuePairDescriptor next = 354 (NameValuePairDescriptor) iter.next(); 355 existing.addStubProperty(next); 357 } 358 for(Iterator iter = runtimePortInfo.getCallProperties() 359 .iterator(); iter.hasNext();) { 360 NameValuePairDescriptor next = 361 (NameValuePairDescriptor) iter.next(); 362 existing.addCallProperty(next); 364 } 365 if (runtimePortInfo.getMessageSecurityBinding() != null) { 366 existing.setMessageSecurityBinding( 367 runtimePortInfo.getMessageSecurityBinding()); 368 } 369 } 370 } 371 372 public ServiceRefPortInfo addContainerManagedPort 373 (String serviceEndpointInterface) { 374 ServiceRefPortInfo info = new ServiceRefPortInfo(); 375 info.setServiceEndpointInterface(serviceEndpointInterface); 376 info.setIsContainerManaged(true); 377 info.setServiceReference(this); 378 portsInfo.add(info); 379 super.changed(); 380 return info; 381 } 382 383 public boolean hasContainerManagedPorts() { 384 boolean containerManaged = false; 385 for(Iterator iter = portsInfo.iterator(); iter.hasNext();) { 386 ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next(); 387 if( next.isContainerManaged() ) { 388 containerManaged = true; 389 break; 390 } 391 } 392 return containerManaged; 393 } 394 395 public boolean hasClientManagedPorts() { 396 boolean clientManaged = false; 397 for(Iterator iter = portsInfo.iterator(); iter.hasNext();) { 398 ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next(); 399 if( next.isClientManaged() ) { 400 clientManaged = true; 401 break; 402 } 403 } 404 return clientManaged; 405 } 406 407 410 public ServiceRefPortInfo getPortInfo(String serviceEndpointInterface) { 411 return getPortInfoBySEI(serviceEndpointInterface); 412 } 413 414 417 public ServiceRefPortInfo getPortInfoBySEI(String serviceEndpointInterface) 418 { 419 for(Iterator iter = portsInfo.iterator(); iter.hasNext();) { 420 ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next(); 421 if( serviceEndpointInterface.equals 422 (next.getServiceEndpointInterface()) ) { 423 return next; 424 } 425 } 426 return null; 427 } 428 429 432 public ServiceRefPortInfo getPortInfoByPort(QName wsdlPort) { 433 for(Iterator iter = portsInfo.iterator(); iter.hasNext();) { 434 ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next(); 435 if( next.hasWsdlPort() && wsdlPort.equals(next.getWsdlPort()) ) { 436 return next; 437 } 438 } 439 return null; 440 } 441 442 445 public void addHandler(WebServiceHandler handler) { 446 handlers.addLast(handler); 447 super.changed(); 448 } 449 450 public void removeHandler(WebServiceHandler handler) { 451 handlers.remove(handler); 452 super.changed(); 453 } 454 455 public void removeHandlerByName(String handlerName) { 456 for(Iterator iter = handlers.iterator(); iter.hasNext();) { 457 WebServiceHandler next = (WebServiceHandler) iter.next(); 458 if( next.getHandlerName().equals(handlerName) ) { 459 iter.remove(); 460 super.changed(); 461 break; 462 } 463 } 464 } 465 466 public boolean hasHandlers() { 467 return (handlers.size() > 0); 468 } 469 470 473 public LinkedList getHandlers() { 474 return handlers; 475 } 476 477 480 public void addHandlerChain(WebServiceHandlerChain handler) { 481 handlerChain.addLast(handler); 482 super.changed(); 483 } 484 485 public void removeHandlerChain(WebServiceHandlerChain handler) { 486 handlerChain.remove(handler); 487 super.changed(); 488 } 489 490 public boolean hasHandlerChain() { 491 return (handlerChain.size() > 0); 492 } 493 494 public LinkedList getHandlerChain() { 495 return handlerChain; 496 } 497 498 501 502 public Set getCallProperties() { 503 return callProperties; 504 } 505 506 public NameValuePairDescriptor getCallPropertyByName(String name) { 507 NameValuePairDescriptor prop = null; 508 for(Iterator iter = callProperties.iterator(); iter.hasNext();) { 509 NameValuePairDescriptor next = (NameValuePairDescriptor) 510 iter.next(); 511 if( next.getName().equals(name) ) { 512 prop = next; 513 break; 514 } 515 } 516 return prop; 517 } 518 519 524 public void addCallProperty(NameValuePairDescriptor property) { 525 NameValuePairDescriptor prop = 526 getCallPropertyByName(property.getName()); 527 if( prop != null ) { 528 prop.setValue(property.getValue()); 529 } else { 530 callProperties.add(property); 531 } 532 } 533 534 535 540 public void removeCallProperty(NameValuePairDescriptor property) { 541 NameValuePairDescriptor prop = 542 getCallPropertyByName(property.getName()); 543 if( prop != null ) { 544 callProperties.remove(property); 545 } 546 } 547 548 public boolean hasServiceImplClassName() { 549 return (serviceImplClassName != null); 550 } 551 552 public void setServiceImplClassName(String className) { 553 serviceImplClassName = className; 554 } 555 556 public String getServiceImplClassName() { 557 return serviceImplClassName; 558 } 559 560 public boolean hasWsdlOverride() { 561 return (wsdlOverride != null); 562 } 563 564 public void setWsdlOverride(URL override) { 565 wsdlOverride = override; 566 } 567 568 public URL getWsdlOverride() { 569 return wsdlOverride; 570 } 571 572 public void setInjectionTargetType(String type) { 573 injectionTargetType = type; 574 } 575 576 public String getInjectionTargetType() { 577 return injectionTargetType; 578 } 579 580 581 public boolean equals(Object object) { 582 if (object instanceof ServiceReferenceDescriptor) { 583 ServiceReferenceDescriptor thatReference = 584 (ServiceReferenceDescriptor) object; 585 return thatReference.getName().equals(this.getName()); 586 } 587 return false; 588 } 589 590 } 591 | Popular Tags |