1 23 package com.sun.enterprise.deployment; 24 25 import java.util.*; 26 import java.util.jar.*; 27 import com.sun.enterprise.util.LocalStringManagerImpl; 28 29 import com.sun.enterprise.deployment.xml.ApplicationTagNames; 30 import com.sun.enterprise.deployment.types.EjbReference; 31 import com.sun.enterprise.deployment.types.ResourceReferenceContainer; 32 import com.sun.enterprise.deployment.types.ResourceEnvReferenceContainer; 33 import com.sun.enterprise.deployment.types.MessageDestinationReference; 34 import com.sun.enterprise.deployment.types.MessageDestinationReferencer; 35 import com.sun.enterprise.deployment.types.ServiceReferenceContainer; 36 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer; 37 import com.sun.enterprise.deployment.types.EjbReferenceContainer; 38 import com.sun.enterprise.deployment.node.appclient.AppClientNode; 39 import com.sun.enterprise.deployment.util.AppClientVisitor; 40 import com.sun.enterprise.deployment.util.DescriptorVisitor; 41 import com.sun.enterprise.deployment.util.ModuleDescriptor; 42 import com.sun.enterprise.deployment.runtime.JavaWebStartAccessDescriptor; 43 import javax.enterprise.deploy.shared.ModuleType ; 44 48 49 public class ApplicationClientDescriptor extends BundleDescriptor 50 implements WritableJndiNameEnvironment, 51 ResourceReferenceContainer, 52 EjbReferenceContainer, 53 ResourceEnvReferenceContainer, 54 ServiceReferenceContainer, 55 MessageDestinationReferenceContainer 56 { 57 private Set environmentProperties; 58 private Set ejbReferences; 59 private Set jmsDestReferences; 60 private Set messageDestReferences; 61 private Set resourceReferences; 62 private Set serviceReferences; 63 private Set<EntityManagerFactoryReferenceDescriptor> 64 entityManagerFactoryReferences = 65 new HashSet<EntityManagerFactoryReferenceDescriptor>(); 66 private Set<EntityManagerReferenceDescriptor> 67 entityManagerReferences = 68 new HashSet<EntityManagerReferenceDescriptor>(); 69 private Set<LifecycleCallbackDescriptor> postConstructDescs = 70 new HashSet<LifecycleCallbackDescriptor>(); 71 private Set<LifecycleCallbackDescriptor> preDestroyDescs = 72 new HashSet<LifecycleCallbackDescriptor>(); 73 private String mainClassName; 74 private static LocalStringManagerImpl localStrings = 75 new LocalStringManagerImpl(ApplicationClientDescriptor.class); 76 private String callbackHandler = null; 77 private JavaWebStartAccessDescriptor jwsAccessDescriptor = null; 78 79 83 public boolean hasRuntimeInformation() { 84 for (Iterator itr = this.getNamedDescriptors().iterator(); itr.hasNext();) { 85 NamedDescriptor next = (NamedDescriptor) itr.next(); 86 if (!"".equals(next.getJndiName())) { 87 return true; 88 } 89 } 90 return false; 91 } 92 93 97 public String getDefaultSpecVersion() { 98 return AppClientNode.SPEC_VERSION; 99 } 100 101 104 public String getMainClassName() { 105 if (this.mainClassName == null) { 106 this.mainClassName = ""; 107 } 108 return this.mainClassName; 109 } 110 111 114 115 public void setMainClassName(String mainClassName) { 116 this.mainClassName = mainClassName; 117 this.changed(); 118 } 119 120 123 public String getCallbackHandler() { 124 return callbackHandler; 125 } 126 127 130 public void setCallbackHandler(String handler) { 131 callbackHandler = handler; 132 this.changed(); 133 } 134 135 138 139 public Collection getNamedDescriptors() { 140 return super.getNamedDescriptorsFrom(this); 141 } 142 143 146 public Vector getNamedReferencePairs() { 147 return super.getNamedReferencePairsFrom(this); 148 } 149 150 153 public Set getEnvironmentProperties() { 154 if (this.environmentProperties == null) { 155 this.environmentProperties = new OrderedSet(); 156 } 157 return this.environmentProperties = new OrderedSet(this.environmentProperties); 158 } 159 160 164 public EnvironmentProperty getEnvironmentPropertyByName(String name) { 165 for (Iterator itr = this.getEnvironmentProperties().iterator(); 166 itr.hasNext();) { 167 EnvironmentProperty ev = (EnvironmentProperty) itr.next(); 168 if (ev.getName().equals(name)) { 169 return ev; 170 } 171 } 172 throw new IllegalArgumentException (localStrings.getLocalString( 173 "enterprise.deployment.exceptionbeanhasnoenvpropertybyname", 174 "This bean has no environment property by the name of {0}", 175 new Object [] {name})); 176 } 177 178 179 182 183 public void addEnvironmentProperty(EnvironmentProperty environmentProperty) { 184 this.getEnvironmentProperties().add(environmentProperty); 185 this.changed(); 186 } 187 188 191 public void removeEnvironmentProperty(EnvironmentProperty environmentProperty) { 192 this.getEnvironmentProperties().remove(environmentProperty); 193 this.changed(); 194 } 195 196 199 public Set getEjbReferenceDescriptors() { 200 if (this.ejbReferences == null) { 201 this.ejbReferences = new OrderedSet(); 202 } 203 return this.ejbReferences = new OrderedSet(this.ejbReferences); 204 } 205 206 209 public void addEjbReferenceDescriptor(EjbReferenceDescriptor ejbReference) { 210 addEjbReferenceDescriptor((EjbReference) ejbReference); 211 } 212 213 public void addEjbReferenceDescriptor(EjbReference ejbReference) { 214 this.getEjbReferenceDescriptors().add(ejbReference); 215 ejbReference.setReferringBundleDescriptor(this); 216 this.changed(); 217 } 218 219 222 public void removeEjbReferenceDescriptor(EjbReferenceDescriptor ejbReference) { 223 removeEjbReferenceDescriptor((EjbReference) ejbReference); 224 } 225 226 public void removeEjbReferenceDescriptor(EjbReference ejbReference) { 227 this.getEjbReferenceDescriptors().remove(ejbReference); 228 ejbReference.setReferringBundleDescriptor(null); 229 this.changed(); 230 } 231 232 public Set<LifecycleCallbackDescriptor> 233 getPostConstructDescriptors() { 234 if (postConstructDescs == null) { 235 postConstructDescs = 236 new HashSet<LifecycleCallbackDescriptor>(); 237 } 238 return postConstructDescs; 239 } 240 241 public void addPostConstructDescriptor(LifecycleCallbackDescriptor 242 postConstructDesc) { 243 String className = postConstructDesc.getLifecycleCallbackClass(); 244 boolean found = false; 245 for (LifecycleCallbackDescriptor next : 246 getPostConstructDescriptors()) { 247 if ( (next.getLifecycleCallbackClass() != null) && 248 next.getLifecycleCallbackClass().equals(className)) { 249 found = true; 250 break; 251 } 252 } 253 if (!found) { 254 getPostConstructDescriptors().add(postConstructDesc); 255 } 256 } 257 258 public LifecycleCallbackDescriptor 259 getPostConstructDescriptorByClass(String className) { 260 return getPostConstructDescriptorByClass(className, this); 261 } 262 263 public Set<LifecycleCallbackDescriptor> getPreDestroyDescriptors() { 264 if (preDestroyDescs == null) { 265 preDestroyDescs = 266 new HashSet<LifecycleCallbackDescriptor>(); 267 } 268 return preDestroyDescs; 269 } 270 271 public void addPreDestroyDescriptor(LifecycleCallbackDescriptor preDestroyDesc) { 272 String className = preDestroyDesc.getLifecycleCallbackClass(); 273 boolean found = false; 274 for (LifecycleCallbackDescriptor next : 275 getPreDestroyDescriptors()) { 276 if ( (next.getLifecycleCallbackClass() != null) && 277 next.getLifecycleCallbackClass().equals(className)) { 278 found = true; 279 break; 280 } 281 } 282 if (!found) { 283 getPreDestroyDescriptors().add(preDestroyDesc); 284 } 285 } 286 287 public LifecycleCallbackDescriptor 288 getPreDestroyDescriptorByClass(String className) { 289 return getPreDestroyDescriptorByClass(className, this); 290 } 291 292 public InjectionInfo getInjectionInfoByClass(String className) { 293 return getInjectionInfoByClass(className, this); 294 } 295 296 public Set getServiceReferenceDescriptors() { 297 if( this.serviceReferences == null ) { 298 this.serviceReferences = new OrderedSet(); 299 } 300 return this.serviceReferences = new OrderedSet(this.serviceReferences); 301 } 302 303 public void addServiceReferenceDescriptor(ServiceReferenceDescriptor 304 serviceRef) { 305 serviceRef.setBundleDescriptor(this); 306 this.getServiceReferenceDescriptors().add(serviceRef); 307 this.changed(); 308 } 309 310 public void removeServiceReferenceDescriptor(ServiceReferenceDescriptor 311 serviceRef) { 312 this.getServiceReferenceDescriptors().remove(serviceRef); 313 this.changed(); 314 } 315 316 320 public ServiceReferenceDescriptor getServiceReferenceByName(String name) { 321 for (Iterator itr = this.getServiceReferenceDescriptors().iterator(); 322 itr.hasNext();) { 323 ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor) 324 itr.next(); 325 if (srd.getName().equals(name)) { 326 return srd; 327 } 328 } 329 throw new IllegalArgumentException ("This application client has no service refernce by the name " + name); 330 } 331 332 public Set getMessageDestinationReferenceDescriptors() { 333 if( this.messageDestReferences == null ) { 334 this.messageDestReferences = new OrderedSet(); 335 } 336 return this.messageDestReferences = 337 new OrderedSet(this.messageDestReferences); 338 } 339 340 public void addMessageDestinationReferenceDescriptor 341 (MessageDestinationReferenceDescriptor messageDestRef) { 342 messageDestRef.setReferringBundleDescriptor(this); 343 344 this.getMessageDestinationReferenceDescriptors().add(messageDestRef); 345 this.changed(); 346 } 347 348 public void removeMessageDestinationReferenceDescriptor 349 (MessageDestinationReferenceDescriptor msgDestRef) { 350 this.getMessageDestinationReferenceDescriptors().remove(msgDestRef); 351 this.changed(); 352 } 353 354 358 public MessageDestinationReferenceDescriptor 359 getMessageDestinationReferenceByName(String name) { 360 for (Iterator itr = 361 this.getMessageDestinationReferenceDescriptors().iterator(); 362 itr.hasNext();) { 363 MessageDestinationReferenceDescriptor mdr = 364 (MessageDestinationReferenceDescriptor) itr.next(); 365 if (mdr.getName().equals(name)) { 366 return mdr; 367 } 368 } 369 throw new IllegalArgumentException ("This ejb has no message destination refernce by the name " + name); 370 } 371 372 375 public Set getJmsDestinationReferenceDescriptors() { 376 if (this.jmsDestReferences == null) { 377 this.jmsDestReferences = new OrderedSet(); 378 } 379 return this.jmsDestReferences = new OrderedSet(this.jmsDestReferences); 380 } 381 382 public void addJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) { 383 this.getJmsDestinationReferenceDescriptors().add(jmsDestReference); 384 this.changed(); 385 } 386 387 public void removeJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) { 388 this.getJmsDestinationReferenceDescriptors().remove(jmsDestReference); 389 this.changed(); 390 } 391 392 396 public EjbReferenceDescriptor getEjbReferenceByName(String name) { 397 for (Iterator itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) { 398 EjbReferenceDescriptor ejr = (EjbReferenceDescriptor) itr.next(); 399 if (ejr.getName().equals(name)) { 400 return ejr; 401 } 402 } 403 throw new IllegalArgumentException ("This appclient has no ejb refernce by the name " + name); 404 } 405 406 public Set<EntityManagerFactoryReferenceDescriptor> 407 getEntityManagerFactoryReferenceDescriptors() { 408 if( this.entityManagerFactoryReferences == null ) { 409 this.entityManagerFactoryReferences = 410 new HashSet<EntityManagerFactoryReferenceDescriptor>(); 411 } 412 return this.entityManagerFactoryReferences = 413 new HashSet<EntityManagerFactoryReferenceDescriptor> 414 (entityManagerFactoryReferences); 415 } 416 417 421 public EntityManagerFactoryReferenceDescriptor 422 getEntityManagerFactoryReferenceByName(String name) { 423 for (EntityManagerFactoryReferenceDescriptor next : 424 getEntityManagerFactoryReferenceDescriptors()) { 425 426 if (next.getName().equals(name)) { 427 return next; 428 } 429 } 430 throw new IllegalArgumentException ("This appclient has no entity " 431 + "manager factory reference by the name " + name); 432 } 433 434 public void addEntityManagerFactoryReferenceDescriptor 435 (EntityManagerFactoryReferenceDescriptor reference) { 436 reference.setReferringBundleDescriptor(this); 437 this.getEntityManagerFactoryReferenceDescriptors().add(reference); 438 this.changed(); 439 } 440 441 public Set<EntityManagerReferenceDescriptor> 442 getEntityManagerReferenceDescriptors() { 443 return new HashSet<EntityManagerReferenceDescriptor>(); 444 } 445 446 450 public EntityManagerReferenceDescriptor 451 getEntityManagerReferenceByName(String name) { 452 throw new IllegalArgumentException ("This appclient has no entity " 453 + "manager refernce by the name " + name); 454 } 455 456 public void addEntityManagerReferenceDescriptor 457 (EntityManagerReferenceDescriptor reference) { 458 reference.setReferringBundleDescriptor(this); 459 this.getEntityManagerReferenceDescriptors().add(reference); 460 this.changed(); 461 } 462 463 public List<InjectionCapable> 464 getInjectableResourcesByClass(String className) { 465 return getInjectableResourcesByClass(className, this); 466 } 467 468 472 public EjbReference getEjbReference(String name) { 473 for (Iterator itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) { 474 EjbReference ejr = (EjbReference) itr.next(); 475 if (ejr.getName().equals(name)) { 476 return ejr; 477 } 478 } 479 throw new IllegalArgumentException ("This application client has no ejb refernce by the name " + name); 480 } 481 482 485 public JmsDestinationReferenceDescriptor getJmsDestinationReferenceByName(String name) { 486 for (Iterator itr = this.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext();) { 487 JmsDestinationReferenceDescriptor jdr = (JmsDestinationReferenceDescriptor) itr.next(); 488 if (jdr.getName().equals(name)) { 489 return jdr; 490 } 491 } 492 throw new IllegalArgumentException (localStrings.getLocalString( 493 "enterprise.deployment.exceptionappclienthasnojmsdestrefbyname", 494 "This application client has no JMS destination reference by the name of {0}", new Object [] {name})); 495 } 496 497 500 public Set getResourceReferenceDescriptors() { 501 if (this.resourceReferences == null) { 502 this.resourceReferences = new OrderedSet(); 503 } 504 return this.resourceReferences = new OrderedSet(this.resourceReferences); 505 } 506 507 511 public ResourceReferenceDescriptor getResourceReferenceByName(String name) { 512 for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) { 513 ResourceReferenceDescriptor rr = (ResourceReferenceDescriptor) itr.next(); 514 if (rr.getName().equals(name)) { 515 return rr; 516 } 517 } 518 throw new IllegalArgumentException (localStrings.getLocalString( 519 "enterprise.deployment.exceptionappclienthasnoejbrefname", 520 "This application client has no ejb refernce by the name {0}", new Object [] {name})); 521 } 522 523 526 527 public void addResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) { 528 this.getResourceReferenceDescriptors().add(resourceReference); 529 this.changed(); 530 } 531 532 535 public void removeResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) { 536 this.getResourceReferenceDescriptors().remove(resourceReference); 537 this.changed(); 538 } 539 540 543 public Set<String > getComponentClassNames() { 544 Set set = new HashSet<String >(); 545 set.add(getMainClassName()); 546 return set; 547 } 548 549 550 553 public boolean hasWebServiceClients() { 554 return !(getServiceReferenceDescriptors().isEmpty()); 555 } 556 557 560 public boolean hasWebServices() { 561 return false; 562 } 563 564 public void print(StringBuffer toStringBuffer) { 565 toStringBuffer.append("Application Client Descriptor"); 566 toStringBuffer.append("\n "); 567 super.print(toStringBuffer); 568 toStringBuffer.append("\n environmentProperties ").append(environmentProperties); 569 toStringBuffer.append("\n ejbReferences "); 570 if(ejbReferences != null) 571 printDescriptorSet(ejbReferences,toStringBuffer); 572 toStringBuffer.append("\n jmsDestReferences "); 573 if(jmsDestReferences != null) 574 printDescriptorSet(jmsDestReferences,toStringBuffer); 575 toStringBuffer.append("\n messageDestReferences "); 576 if(messageDestReferences != null) 577 printDescriptorSet(messageDestReferences,toStringBuffer); 578 toStringBuffer.append("\n resourceReferences "); 579 if(resourceReferences != null) 580 printDescriptorSet(resourceReferences,toStringBuffer); 581 toStringBuffer.append("\n serviceReferences "); 582 if(serviceReferences != null) 583 printDescriptorSet(serviceReferences,toStringBuffer); 584 toStringBuffer.append("\n mainClassName ").append(mainClassName); 585 } 586 private void printDescriptorSet(Set descSet, StringBuffer sbuf){ 587 for(Iterator itr = descSet.iterator(); itr.hasNext();){ 588 Object obj = itr.next(); 589 if(obj instanceof Descriptor) 590 ((Descriptor)obj).print(sbuf); 591 else 592 sbuf.append(obj); 593 } 594 } 595 596 601 public void visit(DescriptorVisitor aVisitor) { 602 if (aVisitor instanceof AppClientVisitor) { 603 visit((AppClientVisitor) aVisitor); 604 } else { 605 super.visit(aVisitor); 606 } 607 } 608 609 614 public void visit(AppClientVisitor aVisitor) { 615 aVisitor.accept(this); 616 617 for(InjectionCapable injectable : getInjectableResources(this)) { 620 aVisitor.accept(injectable); 621 } 622 623 Set ejbRefs = getEjbReferenceDescriptors(); 624 for (Iterator itr = ejbRefs.iterator();itr.hasNext();) { 625 aVisitor.accept((EjbReference) itr.next()); 626 } 627 628 for (Iterator itr=getResourceReferenceDescriptors().iterator(); 629 itr.hasNext();) { 630 ResourceReferenceDescriptor next = 631 (ResourceReferenceDescriptor) itr.next(); 632 aVisitor.accept(next); 633 } 634 635 for (Iterator itr=getJmsDestinationReferenceDescriptors().iterator(); 636 itr.hasNext();) { 637 JmsDestinationReferenceDescriptor next = 638 (JmsDestinationReferenceDescriptor) itr.next(); 639 aVisitor.accept(next); 640 } 641 642 Set msgDestRefs = getMessageDestinationReferenceDescriptors(); 643 for (Iterator itr = msgDestRefs.iterator();itr.hasNext();) { 644 aVisitor.accept((MessageDestinationReferencer) itr.next()); 645 } 646 647 for (Iterator itr = getMessageDestinations().iterator(); 648 itr.hasNext();) { 649 MessageDestinationDescriptor msgDestDescriptor = 650 (MessageDestinationDescriptor)itr.next(); 651 aVisitor.accept(msgDestDescriptor); 652 } 653 654 Set serviceRefs = getServiceReferenceDescriptors(); 655 for (Iterator itr = serviceRefs.iterator();itr.hasNext();) { 656 aVisitor.accept((ServiceReferenceDescriptor) itr.next()); 657 } 658 } 659 660 663 public ModuleType getModuleType() { 664 return ModuleType.CAR; 665 } 666 667 public JavaWebStartAccessDescriptor getJavaWebStartAccessDescriptor() { 668 if (jwsAccessDescriptor == null) { 669 jwsAccessDescriptor = new JavaWebStartAccessDescriptor(); 670 jwsAccessDescriptor.setBundleDescriptor(this); 671 } 672 return jwsAccessDescriptor; 673 } 674 675 public void setJavaWebStartAccessDescriptor(JavaWebStartAccessDescriptor descr) { 676 descr.setBundleDescriptor(this); 677 jwsAccessDescriptor = descr; 678 this.changed(); 679 } 680 681 } 682 683 | Popular Tags |