1 23 package com.sun.enterprise.deployment; 24 25 import java.util.*; 26 import com.sun.enterprise.deployment.*; 27 28 import com.sun.enterprise.util.NotificationListener; 29 import com.sun.enterprise.util.NotificationEvent; 30 31 import com.sun.enterprise.deployment.web.MimeMapping; 32 import com.sun.enterprise.deployment.web.ErrorPageDescriptor; 33 import com.sun.enterprise.deployment.web.AppListenerDescriptor; 34 import com.sun.enterprise.deployment.web.ResourceReference; 35 import com.sun.enterprise.deployment.web.ContextParameter; 36 import com.sun.enterprise.deployment.web.SecurityRole; 37 import com.sun.enterprise.deployment.web.SecurityRoleReference; 38 import com.sun.enterprise.deployment.web.SecurityConstraint; 39 import com.sun.enterprise.deployment.web.LocalizedContentDescriptor; 40 import com.sun.enterprise.deployment.web.LoginConfiguration; 41 import com.sun.enterprise.deployment.web.EnvironmentEntry; 42 import com.sun.enterprise.deployment.web.ServletFilter; 43 import com.sun.enterprise.deployment.web.ServletFilterMapping; 44 import com.sun.enterprise.deployment.web.WebResourceCollection; 45 import com.sun.enterprise.deployment.WebServiceEndpoint; 46 import com.sun.enterprise.deployment.node.web.WebBundleNode; 47 48 import com.sun.enterprise.deployment.util.WebBundleVisitor; 49 import com.sun.enterprise.deployment.util.DescriptorVisitor; 50 51 import com.sun.enterprise.deployment.types.EjbReference; 52 import com.sun.enterprise.deployment.types.ResourceReferenceContainer; 53 import com.sun.enterprise.deployment.types.ResourceEnvReferenceContainer; 54 import com.sun.enterprise.deployment.types.MessageDestinationReference; 55 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer; 56 import com.sun.enterprise.deployment.types.EjbReferenceContainer; 57 import com.sun.enterprise.deployment.types.ServiceReferenceContainer; 58 import com.sun.enterprise.deployment.types.MessageDestinationReferencer; 59 60 import com.sun.enterprise.deployment.runtime.web.SunWebApp; 61 62 import javax.enterprise.deploy.shared.ModuleType ; 63 import com.sun.enterprise.util.LocalStringManagerImpl; 64 65 70 71 public class WebBundleDescriptor extends BundleDescriptor 72 implements WritableJndiNameEnvironment, 73 ResourceReferenceContainer, 74 ResourceEnvReferenceContainer, 75 EjbReferenceContainer, 76 MessageDestinationReferenceContainer, 77 ServiceReferenceContainer, 78 NotificationListener 79 80 { 81 82 83 private Set webComponentDescriptors; 84 private int sessionTimeout; 85 private Set mimeMappings; 86 private Set welcomeFiles; 87 private Set errorPageDescriptors; 88 private Vector appListenerDescriptors; 89 private Set contextParameters; 90 private Set ejbReferences; 91 private Set resourceReferences; 92 private Set jmsDestReferences; 93 private Set messageDestReferences; 94 private Set serviceReferences; 95 96 private Set<LifecycleCallbackDescriptor> postConstructDescs = 97 new HashSet<LifecycleCallbackDescriptor>(); 98 private Set<LifecycleCallbackDescriptor> preDestroyDescs = 99 new HashSet<LifecycleCallbackDescriptor>(); 100 101 private Set<EntityManagerFactoryReferenceDescriptor> 102 entityManagerFactoryReferences = 103 new HashSet<EntityManagerFactoryReferenceDescriptor>(); 104 105 private Set<EntityManagerReferenceDescriptor> 106 entityManagerReferences = 107 new HashSet<EntityManagerReferenceDescriptor>(); 108 109 private boolean isDistributable; 110 private Set securityRoles; 111 private Set securityConstraints; 112 private String contextRoot; 113 private LoginConfiguration loginConfiguration; 114 private Set environmentEntries; 115 private LocaleEncodingMappingListDescriptor localeEncodingMappingDesc = null; 116 private JspConfigDescriptor jspConfigDescriptor = null; 117 118 private Vector servletFilters = null; 119 private Vector servletFilterMappings = null; 120 121 public static final int SESSION_TIMEOUT_DEFAULT = 30; 122 private final static String DEPLOYMENT_DESCRIPTOR_DIR="WEB-INF"; 123 124 private static LocalStringManagerImpl localStrings = 125 new LocalStringManagerImpl(WebBundleDescriptor.class); 126 127 private SunWebApp sunWebApp=null; 128 129 131 public WebBundleDescriptor() { 132 sessionTimeout = SESSION_TIMEOUT_DEFAULT; 133 } 134 135 139 public String getDefaultSpecVersion() { 140 return WebBundleNode.SPEC_VERSION; 141 } 142 143 146 public Collection getNamedDescriptors() { 147 return super.getNamedDescriptorsFrom(this); 148 } 149 150 152 public Vector getNamedReferencePairs() { 153 return super.getNamedReferencePairsFrom(this); 154 } 155 156 159 public String getContextRoot() { 160 if (getModuleDescriptor()!=null && getModuleDescriptor().getContextRoot()!=null) { 161 return getModuleDescriptor().getContextRoot(); 162 } 163 if (this.contextRoot == null) { 164 this.contextRoot = ""; 165 } 166 return this.contextRoot; 167 } 168 169 172 public void setContextRoot(String contextRoot) { 173 if (getModuleDescriptor()!=null) { 174 getModuleDescriptor().setContextRoot(contextRoot); 175 } 176 this.contextRoot = contextRoot; 177 this.changed(); 178 } 179 180 public void addWebBundleDescriptor(WebBundleDescriptor webBundleDescriptor) { 181 super.addBundleDescriptor(webBundleDescriptor); 182 183 for (Iterator itr = webBundleDescriptor.getWebComponentDescriptorsSet().iterator(); itr.hasNext();) { 187 WebComponentDescriptor webComponentDescriptor = (WebComponentDescriptor)itr.next(); 188 webComponentDescriptor.setWebBundleDescriptor(this); 189 this.getWebComponentDescriptorsSet().add(webComponentDescriptor); 190 } 191 192 this.getMimeMappingsSet().addAll(webBundleDescriptor.getMimeMappingsSet()); 193 this.getWelcomeFilesSet().addAll(webBundleDescriptor.getWelcomeFilesSet()); 194 this.getErrorPageDescriptorsSet().addAll(webBundleDescriptor.getErrorPageDescriptorsSet()); 195 this.getAppListeners().addAll(webBundleDescriptor.getAppListeners()); 196 this.getContextParametersSet().addAll(webBundleDescriptor.getContextParametersSet()); 197 this.getEjbReferenceDescriptors().addAll(webBundleDescriptor.getEjbReferenceDescriptors()); 198 this.getResourceReferenceDescriptors().addAll(webBundleDescriptor.getResourceReferenceDescriptors()); 199 this.getMessageDestinationReferenceDescriptors().addAll(webBundleDescriptor.getMessageDestinationReferenceDescriptors()); 200 this.getServiceReferenceDescriptors().addAll(webBundleDescriptor.getServiceReferenceDescriptors()); 201 this.getEnvironmentProperties().addAll(webBundleDescriptor.getEnvironmentProperties()); 202 this.getSecurityConstraintsSet().addAll(webBundleDescriptor.getSecurityConstraintsSet()); 203 204 this.getServletFilters().addAll(webBundleDescriptor.getServletFilters()); 207 this.getServletFilterMappings().addAll(webBundleDescriptor.getServletFilterMappings()); 208 this.setLocaleEncodingMappingListDescriptor(webBundleDescriptor.getLocaleEncodingMappingListDescriptor()); 209 this.setJspConfigDescriptor(webBundleDescriptor.getJspConfigDescriptor()); 210 211 WebServicesDescriptor thisWebServices = this.getWebServices(); 213 WebServicesDescriptor otherWebServices = webBundleDescriptor.getWebServices(); 214 for (Iterator i = otherWebServices.getWebServices().iterator(); i.hasNext();) { 215 WebService ws = (WebService)i.next(); 216 thisWebServices.addWebService(new WebService(ws)); 217 } 218 219 this.changed(); 220 } 221 222 224 public Set getWebDescriptors() { 225 if (this.webComponentDescriptors == null) { 226 this.webComponentDescriptors = new OrderedSet(); 227 } 228 return this.webComponentDescriptors; 229 } 230 231 public Set getWebComponentDescriptorsSet() { 232 if (this.webComponentDescriptors == null) { 233 this.webComponentDescriptors = new OrderedSet(); 234 } 235 return this.webComponentDescriptors; 236 } 237 238 240 public Enumeration getWebComponentDescriptors() { 241 return (new Vector(this.getWebComponentDescriptorsSet())).elements(); 242 } 243 244 246 247 public void addWebComponentDescriptor(WebComponentDescriptor webComponentDescriptor) { 248 ((WebComponentDescriptor) webComponentDescriptor).setWebBundleDescriptor(this); 249 for (Iterator wcdIter = getWebComponentDescriptorsSet().iterator(); 250 wcdIter.hasNext();) { 251 WebComponentDescriptor wbd = (WebComponentDescriptor)wcdIter.next(); 252 if (wbd.getCanonicalName().equals( 253 webComponentDescriptor.getCanonicalName())) { 254 webComponentDescriptor.add(wbd); 256 getWebComponentDescriptorsSet().remove(wbd); 259 break; 260 } 261 } 262 this.getWebComponentDescriptorsSet().add(webComponentDescriptor); 263 this.changed(); 264 } 265 266 269 270 public void removeWebComponentDescriptor(WebComponentDescriptor webComponentDescriptor) { 271 ((WebComponentDescriptor) webComponentDescriptor).setWebBundleDescriptor(null); 272 this.getWebComponentDescriptorsSet().remove(webComponentDescriptor); 273 this.changed(); 274 } 275 276 279 public boolean hasServiceReferenceDescriptors() { 280 if (serviceReferences==null) 281 return false; 282 return serviceReferences.size()!=0; 283 } 284 285 public Set getServiceReferenceDescriptors() { 286 if( this.serviceReferences == null ) { 287 this.serviceReferences = new OrderedSet(); 288 } 289 return this.serviceReferences = new OrderedSet(this.serviceReferences); 290 } 291 292 public void addServiceReferenceDescriptor(ServiceReferenceDescriptor 293 serviceRef) { 294 serviceRef.setBundleDescriptor(this); 295 this.getServiceReferenceDescriptors().add(serviceRef); 296 this.changed(); 297 } 298 299 public void removeServiceReferenceDescriptor(ServiceReferenceDescriptor 300 serviceRef) { 301 this.getServiceReferenceDescriptors().remove(serviceRef); 302 this.changed(); 303 } 304 305 309 public ServiceReferenceDescriptor getServiceReferenceByName(String name) { 310 for (Iterator itr = this.getServiceReferenceDescriptors().iterator(); 311 itr.hasNext();) { 312 ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor) 313 itr.next(); 314 if (srd.getName().equals(name)) { 315 return srd; 316 } 317 } 318 throw new IllegalArgumentException ("This web application has no service refernce by the name " + name); 319 } 320 321 324 public Set getJmsDestinationReferenceDescriptors() { 325 if (this.jmsDestReferences == null) { 326 this.jmsDestReferences = new OrderedSet(); 327 } 328 return this.jmsDestReferences = new OrderedSet(this.jmsDestReferences); 329 } 330 331 public void addJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) { 332 this.getJmsDestinationReferenceDescriptors().add(jmsDestReference); 333 this.changed(); 334 } 335 336 public void removeJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) { 337 this.getJmsDestinationReferenceDescriptors().remove(jmsDestReference); 338 this.changed(); 339 } 340 341 344 public JmsDestinationReferenceDescriptor getJmsDestinationReferenceByName(String name) { 345 for (Iterator itr = this.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext();) { 346 JmsDestinationReferenceDescriptor jdr = (JmsDestinationReferenceDescriptor) itr.next(); 347 if (jdr.getName().equals(name)) { 348 return jdr; 349 } 350 } 351 throw new IllegalArgumentException (localStrings.getLocalString( 352 "enterprise.deployment.exceptionwebcomphasnojmsdestrefbyname", 353 "This web component has no JMS destination reference by the name of {0}", new Object [] {name})); 354 } 355 356 359 public int getSessionTimeout() { 360 return this.sessionTimeout; 361 } 362 363 365 public void setSessionTimeout(int sessionTimeout) { 366 this.sessionTimeout = sessionTimeout; 367 this.changed(); 368 } 369 370 private Set getMimeMappingsSet() { 371 if (this.mimeMappings == null) { 372 this.mimeMappings = new HashSet(); 373 } 374 return this.mimeMappings; 375 } 376 377 380 public void setMimeMappings(Set mimeMappings) { 381 this.mimeMappings = mimeMappings; 382 this.changed(); 383 } 384 385 388 public Enumeration getMimeMappings() { 389 return (new Vector(this.getMimeMappingsSet())).elements(); 390 } 391 392 395 public void addMimeMapping(MimeMapping mimeMapping) { 396 for (Iterator itr = getMimeMappingsSet().iterator(); itr.hasNext();) { 400 MimeMapping mm = (MimeMapping) itr.next(); 401 if (mm.getExtension().equals(mimeMapping.getExtension())) { 402 getMimeMappingsSet().remove(mm); 403 break; 404 } 405 } 406 this.getMimeMappingsSet().add(mimeMapping); 407 this.changed(); 408 } 409 410 413 public void addMimeMapping(MimeMappingDescriptor mimeMapping) { 414 addMimeMapping((MimeMapping) mimeMapping); 415 } 416 417 public void addLocaleEncodingMappingListDescriptor(LocaleEncodingMappingListDescriptor lemDesc) { 418 localeEncodingMappingDesc = lemDesc; 419 } 420 421 public LocaleEncodingMappingListDescriptor getLocaleEncodingMappingListDescriptor() { 422 return localeEncodingMappingDesc; 423 } 424 425 public void setLocaleEncodingMappingListDescriptor(LocaleEncodingMappingListDescriptor lemDesc) { 426 localeEncodingMappingDesc = lemDesc; 427 } 428 431 public void removeMimeMapping(MimeMapping mimeMapping) { 432 this.getMimeMappingsSet().remove(mimeMapping); 433 this.changed(); 434 } 435 436 439 public Enumeration getWelcomeFiles() { 440 return (new Vector(this.getWelcomeFilesSet())).elements(); 441 } 442 443 public Set getWelcomeFilesSet() { 444 if (this.welcomeFiles == null) { 445 this.welcomeFiles = new OrderedSet(); 446 } 447 return welcomeFiles; 448 } 449 450 452 public void addWelcomeFile(String fileUri) { 453 this.getWelcomeFilesSet().add(fileUri); 454 this.changed(); 455 } 456 457 459 public void removeWelcomeFile(String fileUri) { 460 this.getWelcomeFilesSet().remove(fileUri); 461 this.changed(); 462 } 463 464 467 public void setWelcomeFiles(Set welcomeFiles) { 468 this.welcomeFiles = welcomeFiles; 469 this.changed(); 470 } 471 472 private Set getErrorPageDescriptorsSet() { 473 if (this.errorPageDescriptors == null) { 474 this.errorPageDescriptors = new HashSet(); 475 } 476 return this.errorPageDescriptors; 477 } 478 479 481 public Enumeration getErrorPageDescriptors() { 482 return (new Vector(this.getErrorPageDescriptorsSet())).elements(); 483 } 484 485 487 public void addErrorPageDescriptor(ErrorPageDescriptor errorPageDescriptor) { 488 this.getErrorPageDescriptorsSet().add(errorPageDescriptor); 489 this.changed(); 490 } 491 492 public void addErrorPageDescriptor(ErrorPageDescriptorImpl errorPageDescriptor) { 493 addErrorPageDescriptor((ErrorPageDescriptor) errorPageDescriptor); 494 } 495 496 499 public void removeErrorPageDescriptor(ErrorPageDescriptor errorPageDescriptor) { 500 this.getErrorPageDescriptorsSet().remove(errorPageDescriptor); 501 this.changed(); 502 } 503 504 507 public ErrorPageDescriptor getErrorPageDescriptorBySignifier(String signifier) { 508 for (Iterator itr = this.getErrorPageDescriptorsSet().iterator(); itr.hasNext();) { 509 ErrorPageDescriptorImpl next = (ErrorPageDescriptorImpl) itr.next(); 510 if (next.getErrorSignifierAsString().equals(signifier)) { 511 return next; 512 } 513 } 514 return null; 515 } 516 517 520 public Set getContextParametersSet() { 521 if (this.contextParameters == null) { 522 this.contextParameters = new OrderedSet(); 523 } 524 return this.contextParameters = new OrderedSet(this.contextParameters); 525 } 526 527 529 public Enumeration getContextParameters() { 530 return (new Vector(this.getContextParametersSet())).elements(); 531 } 532 533 535 public void addContextParameter(ContextParameter contextParameter) { 536 this.getContextParametersSet().add(contextParameter); 537 this.changed(); 538 } 539 540 542 public void addContextParameter(EnvironmentProperty contextParameter) { 543 addContextParameter((ContextParameter) contextParameter); 544 } 545 546 549 public void removeContextParameter(ContextParameter contextParameter) { 550 this.getContextParametersSet().remove(contextParameter); 551 this.changed(); 552 } 553 554 557 558 public boolean isDistributable() { 559 return isDistributable; 560 } 561 562 565 public void setDistributable(boolean isDistributable) { 566 this.isDistributable = isDistributable; 567 this.changed(); 568 } 569 570 573 574 public Enumeration getEjbReferences() { 575 return (new Vector(this.getEjbReferenceDescriptors())).elements(); 576 } 577 580 581 public Set getEjbReferenceDescriptors() { 582 if (this.ejbReferences == null) { 583 this.ejbReferences = new OrderedSet(); 584 } 585 return this.ejbReferences = new OrderedSet(this.ejbReferences); 586 } 587 588 591 592 public EjbReferenceDescriptor getEjbReferenceByName(String name) { 593 return (EjbReferenceDescriptor) getEjbReference(name); 594 } 595 596 public EjbReference getEjbReference(String name) { 597 for (Iterator itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) { 598 EjbReference er = (EjbReference) itr.next(); 599 if (er.getName().equals(name)) { 600 return er; 601 } 602 } 603 throw new IllegalArgumentException (localStrings.getLocalString( 604 "enterprise.deployment.exceptionwebapphasnoejbrefbyname", 605 "This web app has no ejb reference by the name of {0} ", new Object [] {name})); 606 } 607 608 611 612 public ResourceReferenceDescriptor getResourceReferenceByName(String name) { 613 for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) { 614 ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next(); 615 if (next.getName().equals(name)) { 616 return next; 617 } 618 } 619 throw new IllegalArgumentException (localStrings.getLocalString( 620 "enterprise.deployment.exceptionwebapphasnoresourcerefbyname", 621 "This web app has no resource reference by the name of {0}", new Object [] {name})); 622 } 623 624 627 628 public Set getResourceReferenceDescriptors() { 629 if (this.resourceReferences == null) { 630 this.resourceReferences = new OrderedSet(); 631 } 632 return this.resourceReferences = new OrderedSet(this.resourceReferences); 633 } 634 635 public Set<EntityManagerFactoryReferenceDescriptor> 636 getEntityManagerFactoryReferenceDescriptors() { 637 if( this.entityManagerFactoryReferences == null ) { 638 this.entityManagerFactoryReferences = 639 new HashSet<EntityManagerFactoryReferenceDescriptor>(); 640 } 641 return this.entityManagerFactoryReferences = 642 new HashSet<EntityManagerFactoryReferenceDescriptor> 643 (entityManagerFactoryReferences); 644 } 645 646 650 public EntityManagerFactoryReferenceDescriptor 651 getEntityManagerFactoryReferenceByName(String name) { 652 for (EntityManagerFactoryReferenceDescriptor next : 653 getEntityManagerFactoryReferenceDescriptors()) { 654 655 if (next.getName().equals(name)) { 656 return next; 657 } 658 } 659 throw new IllegalArgumentException ("This web component has no entity " 660 + "manager factory reference by the name " + name); 661 } 662 663 public void addEntityManagerFactoryReferenceDescriptor 664 (EntityManagerFactoryReferenceDescriptor reference) { 665 reference.setReferringBundleDescriptor(this); 666 this.getEntityManagerFactoryReferenceDescriptors().add(reference); 667 this.changed(); 668 } 669 670 public Set<EntityManagerReferenceDescriptor> 671 getEntityManagerReferenceDescriptors() { 672 if( this.entityManagerReferences == null ) { 673 this.entityManagerReferences = 674 new HashSet<EntityManagerReferenceDescriptor>(); 675 } 676 return this.entityManagerReferences = 677 new HashSet<EntityManagerReferenceDescriptor> 678 (this.entityManagerReferences); 679 } 680 681 685 public EntityManagerReferenceDescriptor 686 getEntityManagerReferenceByName(String name) { 687 for (EntityManagerReferenceDescriptor next : 688 getEntityManagerReferenceDescriptors()) { 689 690 if (next.getName().equals(name)) { 691 return next; 692 } 693 } 694 throw new IllegalArgumentException ("This web component has no entity " 695 + "manager refernce by the name " + name); 696 } 697 698 public void addEntityManagerReferenceDescriptor 699 (EntityManagerReferenceDescriptor reference) { 700 reference.setReferringBundleDescriptor(this); 701 this.getEntityManagerReferenceDescriptors().add(reference); 702 this.changed(); 703 } 704 705 706 707 709 710 public Set getEnvironmentProperties() { 711 return this.getEnvironmentEntrySet(); 712 } 713 714 715 716 public void addEjbReferenceDescriptor(EjbReference ejbReference) { 717 this.getEjbReferenceDescriptors().add(ejbReference); 718 ejbReference.setReferringBundleDescriptor(this); 719 this.changed(); 720 } 721 722 723 724 public void addEjbReferenceDescriptor(EjbReferenceDescriptor ejbReferenceDescriptor) { 725 this.addEjbReferenceDescriptor((EjbReference) ejbReferenceDescriptor); 726 727 } 728 729 730 public void removeEjbReferenceDescriptor(EjbReferenceDescriptor ejbReferenceDescriptor) { 731 this.removeEjbReferenceDescriptor((EjbReference) ejbReferenceDescriptor); 732 } 733 734 public void removeEjbReferenceDescriptor(EjbReference ejbReferenceDescriptor) { 735 this.getEjbReferenceDescriptors().remove(ejbReferenceDescriptor); 736 ejbReferenceDescriptor.setReferringBundleDescriptor(null); 737 this.changed(); 738 } 739 740 741 public Enumeration getResourceReferences() { 742 return (new Vector(this.getResourceReferenceDescriptors())).elements(); 743 } 744 745 746 public void addResourceReference(ResourceReference resourceReference) { 747 this.getResourceReferenceDescriptors().add(resourceReference); 748 this.changed(); 749 } 750 751 public void addResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) { 752 this.addResourceReference((ResourceReference) resourceReference); 753 } 754 755 public void removeResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) { 756 this.getResourceReferenceDescriptors().remove(resourceReference); 757 this.changed(); 758 } 759 760 public Set getMessageDestinationReferenceDescriptors() { 761 if( this.messageDestReferences == null ) { 762 this.messageDestReferences = new OrderedSet(); 763 } 764 return this.messageDestReferences = 765 new OrderedSet(this.messageDestReferences); 766 } 767 768 public void addMessageDestinationReferenceDescriptor 769 (MessageDestinationReferenceDescriptor messageDestRef) { 770 messageDestRef.setReferringBundleDescriptor(this); 771 this.getMessageDestinationReferenceDescriptors().add(messageDestRef); 772 this.changed(); 773 } 774 775 public void removeMessageDestinationReferenceDescriptor 776 (MessageDestinationReferenceDescriptor msgDestRef) { 777 this.getMessageDestinationReferenceDescriptors().remove(msgDestRef); 778 this.changed(); 779 } 780 781 785 public MessageDestinationReferenceDescriptor 786 getMessageDestinationReferenceByName(String name) { 787 for (Iterator itr = 788 this.getMessageDestinationReferenceDescriptors().iterator(); 789 itr.hasNext();) { 790 MessageDestinationReferenceDescriptor mdr = 791 (MessageDestinationReferenceDescriptor) itr.next(); 792 if (mdr.getName().equals(name)) { 793 return mdr; 794 } 795 } 796 throw new IllegalArgumentException ("This ejb has no message destination refernce by the name " + name); 797 } 798 799 public Set<LifecycleCallbackDescriptor> 800 getPostConstructDescriptors() { 801 if (postConstructDescs == null) { 802 postConstructDescs = 803 new HashSet<LifecycleCallbackDescriptor>(); 804 } 805 return postConstructDescs; 806 } 807 808 public void addPostConstructDescriptor(LifecycleCallbackDescriptor 809 postConstructDesc) { 810 String className = postConstructDesc.getLifecycleCallbackClass(); 811 boolean found = false; 812 for (LifecycleCallbackDescriptor next : 813 getPostConstructDescriptors()) { 814 if (next.getLifecycleCallbackClass().equals(className)) { 815 found = true; 816 break; 817 } 818 } 819 if (!found) { 820 getPostConstructDescriptors().add(postConstructDesc); 821 } 822 } 823 824 public LifecycleCallbackDescriptor 825 getPostConstructDescriptorByClass(String className) { 826 return getPostConstructDescriptorByClass(className, this); 827 } 828 829 public Set<LifecycleCallbackDescriptor> 830 getPreDestroyDescriptors() { 831 if (preDestroyDescs == null) { 832 preDestroyDescs = 833 new HashSet<LifecycleCallbackDescriptor>(); 834 } 835 return preDestroyDescs; 836 } 837 838 public void addPreDestroyDescriptor(LifecycleCallbackDescriptor 839 preDestroyDesc) { 840 String className = preDestroyDesc.getLifecycleCallbackClass(); 841 boolean found = false; 842 for (LifecycleCallbackDescriptor next : 843 getPreDestroyDescriptors()) { 844 if (next.getLifecycleCallbackClass().equals(className)) { 845 found = true; 846 break; 847 } 848 } 849 if (!found) { 850 getPreDestroyDescriptors().add(preDestroyDesc); 851 } 852 } 853 854 public LifecycleCallbackDescriptor 855 getPreDestroyDescriptorByClass(String className) { 856 return getPreDestroyDescriptorByClass(className, this); 857 } 858 859 protected List<InjectionCapable> 860 getInjectableResourcesByClass(String className, 861 JndiNameEnvironment jndiNameEnv) { 862 List<InjectionCapable> injectables = 863 new LinkedList<InjectionCapable>(); 864 865 for(InjectionCapable next : getInjectableResources(jndiNameEnv) ) { 866 if( next.isInjectable()) { 867 for (InjectionTarget target : next.getInjectionTargets()) { 868 if (target.getClassName().equals(className) ) { 869 injectables.add(next); 870 } 871 } 872 } 873 } 874 875 if(((WebBundleDescriptor)jndiNameEnv).hasWebServices()) { 876 for(InjectionCapable next : getInjectableResources(this) ) { 881 if( next.isInjectable()) { 882 for (InjectionTarget target : next.getInjectionTargets()) { 883 Iterator<WebServiceEndpoint> epIter = getWebServices().getEndpoints().iterator(); 884 while(epIter.hasNext()) { 885 String servletImplClass = epIter.next().getServletImplClass(); 886 if (target.getClassName().equals(servletImplClass) ) { 887 injectables.add(next); 888 } 889 } 890 } 891 } 892 } 893 } 894 return injectables; 895 } 896 897 public List<InjectionCapable> 898 getInjectableResourcesByClass(String className) { 899 return(getInjectableResourcesByClass(className, this)); 900 } 901 902 public InjectionInfo getInjectionInfoByClass(String className, 903 JndiNameEnvironment jndiNameEnv) { 904 LifecycleCallbackDescriptor postConstructDesc = 905 getPostConstructDescriptorByClass(className, jndiNameEnv); 906 String postConstructMethodName = (postConstructDesc != null) ? 907 postConstructDesc.getLifecycleCallbackMethod() : null; 908 LifecycleCallbackDescriptor preDestroyDesc = 909 getPreDestroyDescriptorByClass(className, jndiNameEnv); 910 String preDestroyMethodName = (preDestroyDesc != null) ? 911 preDestroyDesc.getLifecycleCallbackMethod() : null; 912 return new InjectionInfo(className, 913 postConstructMethodName, preDestroyMethodName, 914 getInjectableResourcesByClass(className, 915 jndiNameEnv)); 916 } 917 918 public InjectionInfo getInjectionInfoByClass(String className) { 919 return(getInjectionInfoByClass(className, this)); 920 } 921 922 923 public Enumeration getSecurityRoles() { 924 Vector securityRoles = new Vector(); 925 for (Iterator itr = super.getRoles().iterator(); itr.hasNext();) { 926 Role r = (Role) itr.next(); 927 SecurityRoleDescriptor srd = new SecurityRoleDescriptor(r); 928 securityRoles.add(srd); 929 } 930 return securityRoles.elements(); 931 } 932 933 934 public void addSecurityRole(SecurityRole securityRole) { 935 Role r = new Role(securityRole.getName()); 936 r.setDescription(securityRole.getDescription()); 937 super.addRole(r); 938 } 939 940 public void addSecurityRole(SecurityRoleDescriptor securityRole) { 941 addSecurityRole((SecurityRole) securityRole); 942 } 943 944 945 public SecurityRoleReference getSecurityRoleReferenceByName(String compName, String roleName) { 946 for(Enumeration e = this.getWebComponentDescriptors(); e.hasMoreElements();){ 947 WebComponentDescriptor comp = (WebComponentDescriptor) e.nextElement(); 948 if(!comp.getCanonicalName().equals(compName)) 949 continue; 950 951 SecurityRoleReference r = comp.getSecurityRoleReferenceByName(roleName); 952 if(r != null) 953 return r; 954 } 955 956 return null; 957 } 958 959 960 private Set getSecurityConstraintsSet() { 961 if (this.securityConstraints == null) { 962 this.securityConstraints = new HashSet(); 963 } 964 return this.securityConstraints; 965 } 966 967 968 public Enumeration getSecurityConstraints() { 969 return (new Vector(this.getSecurityConstraintsSet())).elements(); 970 } 971 972 public Collection getSecurityConstraintsForUrlPattern(String urlPattern) { 973 Collection constraints = new HashSet(); 974 for(Iterator i = getSecurityConstraintsSet().iterator(); i.hasNext();) { 975 SecurityConstraint next = (SecurityConstraint) i.next(); 976 boolean include = false; 977 for(Enumeration wrc = next.getWebResourceCollections(); 978 wrc.hasMoreElements();) { 979 WebResourceCollection nextCol = (WebResourceCollection) 980 wrc.nextElement(); 981 for(Enumeration up = nextCol.getUrlPatterns(); 982 up.hasMoreElements();) { 983 String nextPattern = (String ) up.nextElement(); 984 if((urlPattern != null) && urlPattern.equals(nextPattern)) { 985 include = true; 986 break; 987 } 988 } 989 if( include ) { break; } 990 } 991 if( include ) { constraints.add(next); } 992 } 993 return constraints; 994 } 995 996 997 public void addSecurityConstraint(SecurityConstraint securityConstraint) { 998 this.getSecurityConstraintsSet().add(securityConstraint); 999 this.changed(); 1000 } 1001 1002 1003 public void addSecurityConstraint(SecurityConstraintImpl securityConstraint) { 1004 addSecurityConstraint((SecurityConstraint )securityConstraint); 1005 } 1006 1007 1008 public void removeSecurityConstraint(SecurityConstraint securityConstraint) { 1009 this.getSecurityConstraintsSet().remove(securityConstraint); 1010 this.changed(); 1011 } 1012 1013 1014 1015 1016 public Enumeration getLocalizedContentDescriptors() { 1017 return (new Vector()).elements(); 1018 } 1019 1020 public JspConfigDescriptor getJspConfigDescriptor() { 1021 return jspConfigDescriptor; 1022 } 1023 1024 public void setJspConfigDescriptor(JspConfigDescriptor jspC) { 1025 if (jspConfigDescriptor != null) { 1026 jspConfigDescriptor.removeNotificationListener(this); 1027 } 1028 jspConfigDescriptor = jspC; 1029 if (jspC != null) { 1030 jspC.addNotificationListener(this); 1031 } 1032 } 1033 1034 1036 1037 public Set getServletDescriptors() { 1038 Set servletDescriptors = new HashSet(); 1039 for (Iterator itr = this.getWebComponentDescriptorsSet().iterator(); itr.hasNext();) { 1040 WebComponentDescriptor next = (WebComponentDescriptor) itr.next(); 1041 if (next.isServlet()) { 1042 servletDescriptors.add(next); 1043 } 1044 } 1045 return servletDescriptors; 1046 } 1047 1048 1049 public Set getJspDescriptors() { 1050 Set jspDescriptors = new HashSet(); 1051 for (Iterator itr = this.getWebComponentDescriptorsSet().iterator(); itr.hasNext();) { 1052 WebComponentDescriptor next = (WebComponentDescriptor) itr.next(); 1053 if (!next.isServlet()) { 1054 jspDescriptors.add(next); 1055 } 1056 } 1057 return jspDescriptors; 1058 } 1059 1060 private Set getEnvironmentEntrySet() { 1061 if (this.environmentEntries == null) { 1062 this.environmentEntries = new OrderedSet(); 1063 } 1064 return this.environmentEntries = new OrderedSet(environmentEntries); 1065 } 1066 1067 1068 public Enumeration getEnvironmentEntries() { 1069 return (new Vector(this.getEnvironmentEntrySet())).elements(); 1070 } 1071 1072 1073 public void addEnvironmentEntry(EnvironmentEntry environmentEntry) { 1074 this.getEnvironmentEntrySet().add(environmentEntry); 1075 this.changed(); 1076 } 1077 1078 1082 public EnvironmentProperty getEnvironmentPropertyByName(String name) { 1083 for (Iterator itr = this.getEnvironmentEntrySet().iterator(); 1084 itr.hasNext();) { 1085 EnvironmentProperty ev = (EnvironmentProperty) itr.next(); 1086 if (ev.getName().equals(name)) { 1087 return ev; 1088 } 1089 } 1090 throw new IllegalArgumentException (localStrings.getLocalString( 1091 "enterprise.deployment.exceptionbeanhasnoenvpropertybyname", 1092 "This bean has no environment property by the name of {0}", 1093 new Object [] {name})); 1094 } 1095 1096 1097 public void removeEnvironmentProperty(EnvironmentProperty environmentProperty) { 1098 this.getEnvironmentEntrySet().remove(environmentProperty); 1099 this.changed(); 1100 } 1101 1102 1103 public void addEnvironmentProperty(EnvironmentProperty environmentProperty) { 1104 this.getEnvironmentEntrySet().add(environmentProperty); 1105 this.changed(); 1106 } 1107 1108 1109 public void removeEnvironmentEntry(EnvironmentEntry environmentEntry) { 1110 this.getEnvironmentEntrySet().remove(environmentEntry); 1111 this.changed(); 1112 } 1113 1114 1115 public LoginConfiguration getLoginConfiguration() { 1116 return this.loginConfiguration; 1117 } 1118 1119 1120 public void setLoginConfiguration(LoginConfiguration loginConfiguration) { 1121 this.loginConfiguration = loginConfiguration; 1122 this.changed(); 1123 } 1124 1125 public void setLoginConfiguration(LoginConfigurationImpl loginConfiguration) { 1126 setLoginConfiguration((LoginConfiguration) loginConfiguration); 1127 } 1128 1129 1130 public WebComponentDescriptor getWebComponentByName(String name) { 1131 for (Iterator itr = this.getWebComponentDescriptorsSet().iterator(); itr.hasNext();) { 1132 Descriptor next = (Descriptor) itr.next(); 1133 if (next.getName().equals(name)) { 1134 return (WebComponentDescriptor) next; 1135 } 1136 } 1137 return null; 1138 } 1139 1140 1141 public WebComponentDescriptor getWebComponentByCanonicalName(String name) { 1142 for (Iterator itr = this.getWebComponentDescriptorsSet().iterator(); itr.hasNext();) { 1143 WebComponentDescriptor next = (WebComponentDescriptor) itr.next(); 1144 if (next.getCanonicalName().equals(name)) { 1145 return (WebComponentDescriptor) next; 1146 } 1147 } 1148 return null; 1149 } 1150 1151 1154 public WebComponentDescriptor[] getWebComponentByImplName(String name) { 1155 ArrayList<WebComponentDescriptor> webCompList = 1156 new ArrayList<WebComponentDescriptor>(); 1157 for (Object webCompObj : this.getWebDescriptors()) { 1158 WebComponentDescriptor webComp = (WebComponentDescriptor)webCompObj; 1159 if (webComp.getWebComponentImplementation().equals(name)) { 1160 webCompList.add(webComp); 1161 } 1162 } 1163 return webCompList.toArray(new WebComponentDescriptor[webCompList.size()]); 1164 } 1165 1166 1168 1169 1172 public Vector getServletFilters() { 1173 if (this.servletFilters == null) { 1174 this.servletFilters = new Vector(); 1175 } 1176 return this.servletFilters; 1177 } 1178 1179 1182 public Vector getServletFilterDescriptors() { 1183 return (Vector)this.getServletFilters().clone(); 1184 } 1185 1186 1189 public void addServletFilter(ServletFilter ref) { 1190 if (!this.getServletFilters().contains(ref)) { 1191 this.getServletFilters().addElement(ref); 1192 this.changed(); 1193 } 1194 } 1195 1196 public void addServletFilter(ServletFilterDescriptor ref) { 1197 addServletFilter((ServletFilter) ref); 1198 } 1199 1200 1203 public void removeServletFilter(ServletFilter ref) { 1204 this.removeVectorItem(this.getServletFilters(), ref); 1205 this.changed(); 1207 } 1208 1209 1211 1212 1215 public Vector getServletFilterMappings() { 1216 if (this.servletFilterMappings == null) { 1217 this.servletFilterMappings = new Vector(); 1218 } 1219 return this.servletFilterMappings; 1220 } 1221 1222 1225 public Vector getServletFilterMappingDescriptors() { 1226 return (Vector)this.getServletFilterMappings().clone(); 1227 } 1228 1229 1232 public void addServletFilterMapping(ServletFilterMapping ref) { 1233 if (!this.getServletFilterMappings().contains(ref)) { 1234 this.getServletFilterMappings().addElement(ref); 1235 this.changed(); 1236 } 1237 } 1238 1239 1242 public void addServletFilterMapping(ServletFilterMappingDescriptor ref) { 1243 addServletFilterMapping((ServletFilterMapping) ref); 1244 } 1245 1246 1249 public void removeServletFilterMapping(ServletFilterMapping ref) { 1250 this.removeVectorItem(this.getServletFilterMappings(), ref); 1251 this.changed(); 1253 } 1254 1258 public void moveServletFilterMapping(ServletFilterMapping ref, int relPos) { 1259 this.moveVectorItem(this.getServletFilterMappings(), ref, relPos); 1260 this.changed(); 1261 } 1262 1263 1265 1266 private Vector getAppListeners() { 1267 if (this.appListenerDescriptors == null) { 1268 this.appListenerDescriptors = new Vector(); 1269 } 1270 return this.appListenerDescriptors; 1271 } 1272 1273 public Vector getAppListenerDescriptors() { 1274 return (Vector)this.getAppListeners().clone(); 1275 } 1276 1277 public void setAppListeners(Collection c) { 1278 this.getAppListeners().clear(); 1279 this.getAppListeners().addAll(c); 1280 this.changed(); 1281 } 1282 1283 public void addAppListenerDescriptor(AppListenerDescriptor ref) { 1284 if (!this.getAppListeners().contains(ref)) { 1285 this.getAppListeners().addElement(ref); 1286 this.changed(); 1287 } 1288 } 1289 1290 public void addAppListenerDescriptor(AppListenerDescriptorImpl ref) { 1291 addAppListenerDescriptor((AppListenerDescriptor) ref); 1292 } 1293 1294 public void removeAppListenerDescriptor(AppListenerDescriptor ref) { 1295 this.removeVectorItem(this.getAppListeners(), ref); 1296 this.changed(); 1298 } 1299 1300 public void moveAppListenerDescriptor(AppListenerDescriptor ref, 1301 int relPos) { 1302 this.moveVectorItem(this.getAppListeners(), ref, relPos); 1303 this.changed(); 1304 } 1305 1306 1309 public boolean hasWebServiceClients() { 1310 return !getServiceReferenceDescriptors().isEmpty(); 1311 } 1312 1313 1316 1317 1319 1320 1323 protected boolean removeVectorItem(Vector list, Object ref) { 1324 for (Iterator i = list.iterator(); i.hasNext();) { 1325 if (ref == i.next()) { 1326 i.remove(); 1327 return true; 1328 } 1329 } 1330 return false; 1331 } 1332 1333 1336 protected void moveVectorItem(Vector list, Object ref, int rpos) { 1337 1338 1339 int size = list.size(), old_pos = size - 1; 1342 for (;old_pos >= 0; old_pos--) { 1343 if (ref == list.elementAt(old_pos)) { 1344 break; 1345 } 1346 } 1347 if (old_pos < 0) { 1348 return; } 1350 1351 1352 int new_pos = old_pos + rpos; 1353 if (new_pos < 0) { 1354 new_pos = 0; } else 1356 if (new_pos >= size) { 1357 new_pos = size - 1; } 1359 1360 1361 if (new_pos == old_pos) { 1362 return; } 1364 1365 1366 list.removeElementAt(old_pos); 1367 list.insertElementAt(ref, new_pos); 1368 this.changed(); 1369 1370 } 1371 1372 1375 public void visit(DescriptorVisitor aVisitor) { 1376 if (aVisitor instanceof WebBundleVisitor) { 1377 visit((WebBundleVisitor) aVisitor); 1378 } else { 1379 super.visit(aVisitor); 1380 } 1381 } 1382 1383 1386 public void visit(WebBundleVisitor aVisitor) { 1387 super.visit(aVisitor); 1388 aVisitor.accept(this); 1389 1390 for(InjectionCapable injectable : getInjectableResources(this)) { 1393 aVisitor.accept(injectable); 1394 } 1395 1396 for (Iterator i=getWebComponentDescriptorsSet().iterator();i.hasNext();) { 1397 WebComponentDescriptor aWebComp = (WebComponentDescriptor) i.next(); 1398 aVisitor.accept(aWebComp); 1399 } 1400 for (Iterator itr=getWebServices().getWebServices().iterator(); 1401 itr.hasNext(); ) { 1402 WebService aWebService = (WebService) itr.next(); 1403 aVisitor.accept(aWebService); 1404 } 1405 1406 for (Iterator itr = getEjbReferenceDescriptors().iterator();itr.hasNext();) { 1407 EjbReference aRef = (EjbReference) itr.next(); 1408 aVisitor.accept(aRef); 1409 } 1410 for (Iterator itr=getResourceReferenceDescriptors().iterator(); 1411 itr.hasNext();) { 1412 ResourceReferenceDescriptor next = 1413 (ResourceReferenceDescriptor) itr.next(); 1414 aVisitor.accept(next); 1415 } 1416 for (Iterator itr=getJmsDestinationReferenceDescriptors().iterator(); 1417 itr.hasNext();) { 1418 JmsDestinationReferenceDescriptor next = 1419 (JmsDestinationReferenceDescriptor) itr.next(); 1420 aVisitor.accept(next); 1421 } 1422 for (Iterator itr=getMessageDestinationReferenceDescriptors().iterator(); 1423 itr.hasNext();) { 1424 MessageDestinationReferencer next = 1425 (MessageDestinationReferencer) itr.next(); 1426 aVisitor.accept(next); 1427 } 1428 for (Iterator itr = getMessageDestinations().iterator(); 1429 itr.hasNext();) { 1430 MessageDestinationDescriptor msgDestDescriptor = 1431 (MessageDestinationDescriptor)itr.next(); 1432 aVisitor.accept(msgDestDescriptor); 1433 } 1434 for (Iterator itr=getServiceReferenceDescriptors().iterator(); 1435 itr.hasNext();) { 1436 aVisitor.accept((ServiceReferenceDescriptor) itr.next()); 1437 } 1438 } 1439 1440 1442 1443 public void notification(NotificationEvent ne) { 1444 this.changed(); 1446 } 1447 1448 1450 1451 1452 public void print(StringBuffer toStringBuffer) { 1453 toStringBuffer.append("\nWeb Bundle descriptor"); 1454 toStringBuffer.append("\n"); 1455 super.print(toStringBuffer); 1456 toStringBuffer.append( "\n context root ").append(getContextRoot()); 1457 toStringBuffer.append( "\n sessionTimeout ").append(sessionTimeout); 1458 toStringBuffer.append( "\n mimeMappings ").append(mimeMappings); 1459 toStringBuffer.append( "\n welcomeFiles ").append(welcomeFiles); 1460 toStringBuffer.append( "\n errorPageDescriptors ").append(errorPageDescriptors); 1461 toStringBuffer.append( "\n appListenerDescriptors ").append(appListenerDescriptors); 1462 toStringBuffer.append( "\n contextParameters ").append(contextParameters); 1463 toStringBuffer.append( "\n ejbReferences "); 1464 if(ejbReferences != null) 1465 printDescriptorSet(ejbReferences,toStringBuffer); 1466 toStringBuffer.append( "\n jmsDestReferences "); 1467 if(jmsDestReferences != null) 1468 printDescriptorSet(jmsDestReferences,toStringBuffer); 1469 toStringBuffer.append( "\n messageDestReferences "); 1470 if(messageDestReferences != null) 1471 printDescriptorSet(messageDestReferences,toStringBuffer); 1472 toStringBuffer.append( "\n resourceReferences "); 1473 if(resourceReferences != null) 1474 printDescriptorSet(resourceReferences,toStringBuffer); 1475 toStringBuffer.append( "\n serviceReferences "); 1476 if(serviceReferences != null) 1477 printDescriptorSet(serviceReferences,toStringBuffer); 1478 toStringBuffer.append( "\n isDistributable ").append(isDistributable); 1479 toStringBuffer.append( "\n securityRoles ").append(securityRoles); 1480 toStringBuffer.append( "\n securityConstraints ").append(securityConstraints); 1481 toStringBuffer.append( "\n contextRoot ").append(contextRoot); 1482 toStringBuffer.append( "\n loginConfiguration ").append(this.loginConfiguration); 1483 toStringBuffer.append( "\n webComponentDescriptors "); 1484 if(webComponentDescriptors != null) 1485 printDescriptorSet(webComponentDescriptors,toStringBuffer); 1486 toStringBuffer.append( "\n environmentEntries "); 1487 if(environmentEntries != null) 1488 printDescriptorSet(environmentEntries,toStringBuffer); 1489 if (sunWebApp!=null) { 1490 toStringBuffer.append( "\n ========== Runtime Descriptors ========="); 1491 toStringBuffer.append( "\n").append(sunWebApp.toString()); 1492 } 1493 } 1494 private void printDescriptorSet(Set descSet, StringBuffer sbuf){ 1495 if (descSet==null) 1496 return; 1497 for(Iterator itr = descSet.iterator(); itr.hasNext();){ 1498 Object obj = itr.next(); 1499 if(obj instanceof Descriptor) 1500 ((Descriptor)obj).print(sbuf); 1501 else 1502 sbuf.append(obj); 1503 } 1504 } 1505 1506 1509 public ModuleType getModuleType() { 1510 return ModuleType.WAR; 1511 } 1512 1513 1517 public String getDeploymentDescriptorDir() { 1518 return DEPLOYMENT_DESCRIPTOR_DIR; 1519 } 1520 1521 1526 1527 1532 public SunWebApp getSunDescriptor(){ 1533 if (sunWebApp==null) { 1534 sunWebApp = new SunWebApp(); 1535 } 1536 return sunWebApp; 1537 } 1538 1539 1544 public void setSunDescriptor(SunWebApp webApp){ 1545 this.sunWebApp = webApp; 1546 } 1547 1548 1552} 1553 1554 | Popular Tags |